Skip to content

Commit 017bcfc

Browse files
committed
fix: bug
1 parent 7519846 commit 017bcfc

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

pkg/openai/chat.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ type ChatCompletionMessage struct {
5353
Role string `json:"role"`
5454
Content json.RawMessage `json:"content"`
5555
Name string `json:"name,omitempty"`
56+
// MultiContent []VisionContent
5657
}
5758

5859
type FunctionDefinition struct {
@@ -115,17 +116,27 @@ type ChatCompletionResponse struct {
115116
Message struct {
116117
Role string `json:"role"`
117118
Content string `json:"content"`
118-
ToolCalls []ToolCall `json:"tool_calls"`
119+
ToolCalls []ToolCall `json:"tool_calls,omitempty"`
119120
} `json:"message"`
120121
Logprobs string `json:"logprobs"`
121122
FinishReason string `json:"finish_reason"`
122123
} `json:"choices"`
123124
Usage struct {
124-
PromptTokens int `json:"prompt_tokens"`
125-
CompletionTokens int `json:"completion_tokens"`
126-
TotalTokens int `json:"total_tokens"`
127-
} `json:"usage"`
128-
SystemFingerprint string `json:"system_fingerprint"`
125+
PromptTokens int `json:"prompt_tokens,omitempty"`
126+
CompletionTokens int `json:"completion_tokens,omitempty"`
127+
TotalTokens int `json:"total_tokens,omitempty"`
128+
PromptTokensDetails struct {
129+
CachedTokens int `json:"cached_tokens,omitempty"`
130+
AudioTokens int `json:"audio_tokens,omitempty"`
131+
} `json:"prompt_tokens_details,omitempty"`
132+
CompletionTokensDetails struct {
133+
ReasoningTokens int `json:"reasoning_tokens,omitempty"`
134+
AudioTokens int `json:"audio_tokens,omitempty"`
135+
AcceptedPredictionTokens int `json:"accepted_prediction_tokens,omitempty"`
136+
RejectedPredictionTokens int `json:"rejected_prediction_tokens,omitempty"`
137+
} `json:"completion_tokens_details,omitempty"`
138+
} `json:"usage,omitempty"`
139+
SystemFingerprint string `json:"system_fingerprint,omitempty"`
129140
}
130141

131142
type Choice struct {
@@ -304,13 +315,12 @@ func ChatProxy(c *gin.Context, chatReq *ChatCompletionRequest) {
304315
// 处理非流式响应
305316
body, err := io.ReadAll(teeReader)
306317
if err != nil {
307-
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
318+
fmt.Println("Error reading response body:", err)
308319
return
309320
}
310321
var opiResp ChatCompletionResponse
311322
if err := json.Unmarshal(body, &opiResp); err != nil {
312323
log.Println("Error parsing JSON:", err)
313-
c.JSON(http.StatusInternalServerError, gin.H{"error": "Error parsing JSON," + err.Error()})
314324
return
315325
}
316326
if opiResp.Choices != nil && len(opiResp.Choices) > 0 {

0 commit comments

Comments
 (0)