Skip to content

Commit

Permalink
feat: 兼容OpenAI格式下设置gemini模型联网搜索 #615
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Dec 12, 2024
1 parent b1fb595 commit 5d33833
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions relay/channel/gemini/dto.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type GeminiChatSafetySettings struct {
}

type GeminiChatTools struct {
GoogleSearch any `json:"googleSearch,omitempty"`
FunctionDeclarations any `json:"functionDeclarations,omitempty"`
}

Expand Down
21 changes: 16 additions & 5 deletions relay/channel/gemini/relay-gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,25 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
}
if textRequest.Tools != nil {
functions := make([]dto.FunctionCall, 0, len(textRequest.Tools))
googleSearch := false
for _, tool := range textRequest.Tools {
if tool.Function.Name == "googleSearch" {
googleSearch = true
continue
}
functions = append(functions, tool.Function)
}
geminiRequest.Tools = []GeminiChatTools{
{
FunctionDeclarations: functions,
},
if len(functions) > 0 {
geminiRequest.Tools = []GeminiChatTools{
{
FunctionDeclarations: functions,
},
}
}
if googleSearch {
geminiRequest.Tools = append(geminiRequest.Tools, GeminiChatTools{
GoogleSearch: make(map[string]string),
})
}
} else if textRequest.Functions != nil {
geminiRequest.Tools = []GeminiChatTools{
Expand Down Expand Up @@ -134,7 +146,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
shouldAddDummyModelMessage = false
}
}

return &geminiRequest
}

Expand Down

0 comments on commit 5d33833

Please sign in to comment.