修复"reasoning"字段类型错误

This commit is contained in:
2025-11-12 11:20:14 +08:00
parent 2e3a4a3a9c
commit 56353904a3

View File

@@ -73,6 +73,25 @@ func (h *APIHandler) ChatCompletions(c *gin.Context) {
modelName, _ := jsonBody["model"].(string)
isStream, _ := jsonBody["stream"].(bool)
// 处理 reasoning 字段,将对象转换为字符串
if messagesRaw, ok := jsonBody["messages"].([]interface{}); ok {
for _, msgRaw := range messagesRaw {
if msgMap, ok := msgRaw.(map[string]interface{}); ok {
if reasoning, exists := msgMap["reasoning"]; exists {
// 如果 reasoning 是对象,提取 content 字段作为字符串
if reasoningMap, ok := reasoning.(map[string]interface{}); ok {
if reasoningContent, ok := reasoningMap["content"].(string); ok {
msgMap["reasoning"] = reasoningContent
} else {
// 如果无法提取 content移除 reasoning 字段
delete(msgMap, "reasoning")
}
}
}
}
}
}
// 提取 messages 并转换为计算 token 所需的格式
var messages []billing.ChatCompletionMessage
if messagesRaw, ok := jsonBody["messages"].([]interface{}); ok {
@@ -206,6 +225,25 @@ func (h *APIHandler) ResponsesCompletions(c *gin.Context) {
// 从 map 中提取需要的字段
modelName, _ := jsonBody["model"].(string)
// 处理 input 中的 reasoning 字段,将对象转换为字符串
if inputRaw, ok := jsonBody["input"].([]interface{}); ok {
for _, msgRaw := range inputRaw {
if msgMap, ok := msgRaw.(map[string]interface{}); ok {
if reasoning, exists := msgMap["reasoning"]; exists {
// 如果 reasoning 是对象,提取 content 字段作为字符串
if reasoningMap, ok := reasoning.(map[string]interface{}); ok {
if reasoningContent, ok := reasoningMap["content"].(string); ok {
msgMap["reasoning"] = reasoningContent
} else {
// 如果无法提取 content移除 reasoning 字段
delete(msgMap, "reasoning")
}
}
}
}
}
}
// 提取 input 并转换为计算 token 所需的格式
var messages []billing.ChatCompletionMessage
if inputRaw, ok := jsonBody["input"].([]interface{}); ok {