fix: 修复4v请求下text参数缺少引发的nil

This commit is contained in:
Ghostz 2024-07-10 23:03:09 +08:00 committed by GitHub
parent 6ad169975f
commit adbb5cc93f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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 {