From 65acb94f454e8d2f3acd16d218afb164a3997ef2 Mon Sep 17 00:00:00 2001 From: Ghostz <137054651+ye4293@users.noreply.github.com> Date: Sat, 13 Jul 2024 14:57:08 +0800 Subject: [PATCH] fix: text filed check for 4v request (#1634) --- relay/adaptor/openai/token.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/relay/adaptor/openai/token.go b/relay/adaptor/openai/token.go index ddbfad8..8378b26 100644 --- a/relay/adaptor/openai/token.go +++ b/relay/adaptor/openai/token.go @@ -97,7 +97,11 @@ func CountTokenMessages(messages []model.Message, model string) int { m := it.(map[string]any) switch m["type"] { case "text": - tokenNum += getTokenNum(tokenEncoder, m["text"].(string)) + if textValue, ok := m["text"]; ok { + if textString, ok := textValue.(string); ok { + tokenNum += getTokenNum(tokenEncoder, textString) + } + } case "image_url": imageUrl, ok := m["image_url"].(map[string]any) if ok {