From 5d338337a0d3372bbe5c56b871b44642237948aa Mon Sep 17 00:00:00 2001 From: CalciumIon <1808837298@qq.com> Date: Thu, 12 Dec 2024 17:58:25 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9OpenAI=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E4=B8=8B=E8=AE=BE=E7=BD=AEgemini=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E8=81=94=E7=BD=91=E6=90=9C=E7=B4=A2=20#615?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- relay/channel/gemini/dto.go | 1 + relay/channel/gemini/relay-gemini.go | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/relay/channel/gemini/dto.go b/relay/channel/gemini/dto.go index 771a616a..8c93073f 100644 --- a/relay/channel/gemini/dto.go +++ b/relay/channel/gemini/dto.go @@ -34,6 +34,7 @@ type GeminiChatSafetySettings struct { } type GeminiChatTools struct { + GoogleSearch any `json:"googleSearch,omitempty"` FunctionDeclarations any `json:"functionDeclarations,omitempty"` } diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index df262976..2e45e44c 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -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{ @@ -134,7 +146,6 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques shouldAddDummyModelMessage = false } } - return &geminiRequest }