|
@@ -539,6 +539,8 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
|
|
|
if call := getResponseToolCall(&part); call != nil {
|
|
if call := getResponseToolCall(&part); call != nil {
|
|
|
toolCalls = append(toolCalls, *call)
|
|
toolCalls = append(toolCalls, *call)
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if part.Thought {
|
|
|
|
|
+ choice.Message.ReasoningContent = part.Text
|
|
|
} else {
|
|
} else {
|
|
|
if part.ExecutableCode != nil {
|
|
if part.ExecutableCode != nil {
|
|
|
texts = append(texts, "```"+part.ExecutableCode.Language+"\n"+part.ExecutableCode.Code+"\n```")
|
|
texts = append(texts, "```"+part.ExecutableCode.Language+"\n"+part.ExecutableCode.Code+"\n```")
|
|
@@ -556,7 +558,6 @@ func responseGeminiChat2OpenAI(response *GeminiChatResponse) *dto.OpenAITextResp
|
|
|
choice.Message.SetToolCalls(toolCalls)
|
|
choice.Message.SetToolCalls(toolCalls)
|
|
|
isToolCall = true
|
|
isToolCall = true
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
choice.Message.SetStringContent(strings.Join(texts, "\n"))
|
|
choice.Message.SetStringContent(strings.Join(texts, "\n"))
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -596,6 +597,7 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) (*dto.C
|
|
|
}
|
|
}
|
|
|
var texts []string
|
|
var texts []string
|
|
|
isTools := false
|
|
isTools := false
|
|
|
|
|
+ isThought := false
|
|
|
if candidate.FinishReason != nil {
|
|
if candidate.FinishReason != nil {
|
|
|
// p := GeminiConvertFinishReason(*candidate.FinishReason)
|
|
// p := GeminiConvertFinishReason(*candidate.FinishReason)
|
|
|
switch *candidate.FinishReason {
|
|
switch *candidate.FinishReason {
|
|
@@ -620,6 +622,9 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) (*dto.C
|
|
|
call.SetIndex(len(choice.Delta.ToolCalls))
|
|
call.SetIndex(len(choice.Delta.ToolCalls))
|
|
|
choice.Delta.ToolCalls = append(choice.Delta.ToolCalls, *call)
|
|
choice.Delta.ToolCalls = append(choice.Delta.ToolCalls, *call)
|
|
|
}
|
|
}
|
|
|
|
|
+ } else if part.Thought {
|
|
|
|
|
+ isThought = true
|
|
|
|
|
+ texts = append(texts, part.Text)
|
|
|
} else {
|
|
} else {
|
|
|
if part.ExecutableCode != nil {
|
|
if part.ExecutableCode != nil {
|
|
|
texts = append(texts, "```"+part.ExecutableCode.Language+"\n"+part.ExecutableCode.Code+"\n```\n")
|
|
texts = append(texts, "```"+part.ExecutableCode.Language+"\n"+part.ExecutableCode.Code+"\n```\n")
|
|
@@ -632,7 +637,11 @@ func streamResponseGeminiChat2OpenAI(geminiResponse *GeminiChatResponse) (*dto.C
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- choice.Delta.SetContentString(strings.Join(texts, "\n"))
|
|
|
|
|
|
|
+ if isThought {
|
|
|
|
|
+ choice.Delta.SetReasoningContent(strings.Join(texts, "\n"))
|
|
|
|
|
+ } else {
|
|
|
|
|
+ choice.Delta.SetContentString(strings.Join(texts, "\n"))
|
|
|
|
|
+ }
|
|
|
if isTools {
|
|
if isTools {
|
|
|
choice.FinishReason = &constant.FinishReasonToolCalls
|
|
choice.FinishReason = &constant.FinishReasonToolCalls
|
|
|
}
|
|
}
|
|
@@ -716,8 +725,11 @@ func GeminiChatHandler(c *gin.Context, resp *http.Response, info *relaycommon.Re
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return service.OpenAIErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
|
return service.OpenAIErrorWrapper(err, "close_response_body_failed", http.StatusInternalServerError), nil
|
|
|
}
|
|
}
|
|
|
|
|
+ if common.DebugEnabled {
|
|
|
|
|
+ println(string(responseBody))
|
|
|
|
|
+ }
|
|
|
var geminiResponse GeminiChatResponse
|
|
var geminiResponse GeminiChatResponse
|
|
|
- err = json.Unmarshal(responseBody, &geminiResponse)
|
|
|
|
|
|
|
+ err = common.DecodeJson(responseBody, &geminiResponse)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return service.OpenAIErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil
|
|
return service.OpenAIErrorWrapper(err, "unmarshal_response_body_failed", http.StatusInternalServerError), nil
|
|
|
}
|
|
}
|