feat: add Thought field to GeminiPart and update response handling in streamResponseGeminiChat2OpenAI
This commit is contained in:
@@ -54,6 +54,7 @@ type GeminiFileData struct {
|
|||||||
|
|
||||||
type GeminiPart struct {
|
type GeminiPart struct {
|
||||||
Text string `json:"text,omitempty"`
|
Text string `json:"text,omitempty"`
|
||||||
|
Thought bool `json:"thought,omitempty"`
|
||||||
InlineData *GeminiInlineData `json:"inlineData,omitempty"`
|
InlineData *GeminiInlineData `json:"inlineData,omitempty"`
|
||||||
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
|
FunctionCall *FunctionCall `json:"functionCall,omitempty"`
|
||||||
FunctionResponse *FunctionResponse `json:"functionResponse,omitempty"`
|
FunctionResponse *FunctionResponse `json:"functionResponse,omitempty"`
|
||||||
|
|||||||
@@ -596,6 +596,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 +621,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 +636,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
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user