mirror of
https://github.com/linux-do/new-api.git
synced 2025-09-21 01:36:37 +08:00
修复vision格式问题
This commit is contained in:
parent
f048cefed1
commit
b3f1da44dd
@ -160,10 +160,27 @@ func countTokenMessages(messages []Message, model string) (int, error) {
|
|||||||
} else {
|
} else {
|
||||||
for _, m := range arrayContent {
|
for _, m := range arrayContent {
|
||||||
if m.Type == "image_url" {
|
if m.Type == "image_url" {
|
||||||
imageTokenNum, err := getImageToken(&m.ImageUrl)
|
var imageTokenNum int
|
||||||
|
if str, ok := m.ImageUrl.(string); ok {
|
||||||
|
imageTokenNum, err = getImageToken(&MessageImageUrl{Url: str, Detail: "auto"})
|
||||||
|
} else {
|
||||||
|
imageUrlMap := m.ImageUrl.(map[string]interface{})
|
||||||
|
detail, ok := imageUrlMap["detail"]
|
||||||
|
if ok {
|
||||||
|
imageUrlMap["detail"] = detail.(string)
|
||||||
|
} else {
|
||||||
|
imageUrlMap["detail"] = "auto"
|
||||||
|
}
|
||||||
|
imageUrl := MessageImageUrl{
|
||||||
|
Url: imageUrlMap["url"].(string),
|
||||||
|
Detail: imageUrlMap["detail"].(string),
|
||||||
|
}
|
||||||
|
imageTokenNum, err = getImageToken(&imageUrl)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
tokenNum += imageTokenNum
|
tokenNum += imageTokenNum
|
||||||
log.Printf("image token num: %d", imageTokenNum)
|
log.Printf("image token num: %d", imageTokenNum)
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,7 +21,7 @@ type Message struct {
|
|||||||
type MediaMessage struct {
|
type MediaMessage struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
ImageUrl MessageImageUrl `json:"image_url,omitempty"`
|
ImageUrl any `json:"image_url,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageImageUrl struct {
|
type MessageImageUrl struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user