Commit e54bb12a by CalciumIon

feat: 兼容OpenAI格式下设置gemini模型联网搜索 #615

parent ee03e71e
...@@ -34,6 +34,7 @@ type GeminiChatSafetySettings struct { ...@@ -34,6 +34,7 @@ type GeminiChatSafetySettings struct {
} }
type GeminiChatTools struct { type GeminiChatTools struct {
GoogleSearch any `json:"googleSearch,omitempty"`
FunctionDeclarations any `json:"functionDeclarations,omitempty"` FunctionDeclarations any `json:"functionDeclarations,omitempty"`
} }
......
...@@ -45,14 +45,26 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques ...@@ -45,14 +45,26 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
} }
if textRequest.Tools != nil { if textRequest.Tools != nil {
functions := make([]dto.FunctionCall, 0, len(textRequest.Tools)) functions := make([]dto.FunctionCall, 0, len(textRequest.Tools))
googleSearch := false
for _, tool := range textRequest.Tools { for _, tool := range textRequest.Tools {
if tool.Function.Name == "googleSearch" {
googleSearch = true
continue
}
functions = append(functions, tool.Function) functions = append(functions, tool.Function)
} }
if len(functions) > 0 {
geminiRequest.Tools = []GeminiChatTools{ geminiRequest.Tools = []GeminiChatTools{
{ {
FunctionDeclarations: functions, FunctionDeclarations: functions,
}, },
} }
}
if googleSearch {
geminiRequest.Tools = append(geminiRequest.Tools, GeminiChatTools{
GoogleSearch: make(map[string]string),
})
}
} else if textRequest.Functions != nil { } else if textRequest.Functions != nil {
geminiRequest.Tools = []GeminiChatTools{ geminiRequest.Tools = []GeminiChatTools{
{ {
...@@ -134,7 +146,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques ...@@ -134,7 +146,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
shouldAddDummyModelMessage = false shouldAddDummyModelMessage = false
} }
} }
return &geminiRequest return &geminiRequest
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment