Skip to content

Commit 696fa03

Browse files
committed
0.1.13
1 parent e6a5e90 commit 696fa03

1 file changed

Lines changed: 21 additions & 26 deletions

File tree

qwen2api.go

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,8 +1616,14 @@ func handleStreamingRequest(w http.ResponseWriter, r *http.Request, apiReq APIRe
16161616
newContent = content
16171617
}
16181618

1619+
// 以下是修复后的代码,用if语句代替三元运算符
1620+
truncateLen := 20
1621+
if appConfig.DebugEnabled {
1622+
truncateLen = 100
1623+
}
1624+
16191625
logInfo("[reqID:%s] 发送内容(%d字节): %s", reqID, len(newContent),
1620-
truncateString(newContent, appConfig.DebugEnabled ? 100 : 20))
1626+
truncateString(newContent, truncateLen))
16211627

16221628
// 发送内容块
16231629
contentChunk := createContentChunk(respID, createdTime, modelName, newContent)
@@ -2241,33 +2247,22 @@ func handleDrawRequest(w http.ResponseWriter, r *http.Request, apiReq APIRequest
22412247
Content string `json:"content"`
22422248
} `json:"message"`
22432249
FinishReason string `json:"finish_reason"`
2244-
}{
2245-
{
2246-
Index: 0,
2247-
Message: struct {
2248-
Role string `json:"role"`
2249-
Content string `json:"content"`
2250-
}{
2251-
Role: "assistant",
2252-
Content: fmt.Sprintf("![%s](%s)", imageURL, imageURL),
2253-
},
2254-
FinishReason: "stop",
2255-
},
2256-
},
2257-
Usage: struct {
2258-
PromptTokens int `json:"prompt_tokens"`
2259-
CompletionTokens int `json:"completion_tokens"`
2260-
TotalTokens int `json:"total_tokens"`
2261-
}{
2262-
PromptTokens: 1024,
2263-
CompletionTokens: 1024,
2264-
TotalTokens: 2048,
22652250
},
2266-
}
2251+
},
2252+
Usage: struct {
2253+
PromptTokens int `json:"prompt_tokens"`
2254+
CompletionTokens int `json:"completion_tokens"`
2255+
TotalTokens int `json:"total_tokens"`
2256+
}{
2257+
PromptTokens: 1024,
2258+
CompletionTokens: 1024,
2259+
TotalTokens: 2048,
2260+
},
2261+
}
22672262

2268-
// 返回响应
2269-
w.Header().Set("Content-Type", "application/json")
2270-
json.NewEncoder(w).Encode(completionResponse)
2263+
// 返回响应
2264+
w.Header().Set("Content-Type", "application/json")
2265+
json.NewEncoder(w).Encode(completionResponse)
22712266
}
22722267
}
22732268

0 commit comments

Comments
 (0)