From adbb5cc93f6c6eb22d053fd63c141b1514fba19c Mon Sep 17 00:00:00 2001 From: Ghostz <137054651+ye4293@users.noreply.github.com> Date: Wed, 10 Jul 2024 23:03:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D4v=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E4=B8=8Btext=E5=8F=82=E6=95=B0=E7=BC=BA=E5=B0=91=E5=BC=95?= =?UTF-8?q?=E5=8F=91=E7=9A=84nil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 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 ddbfad86..8378b264 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 {