feat: gemini urlContext

This commit is contained in:
Seefs
2025-09-27 16:14:09 +08:00
parent 5197d874d7
commit 9e8b9995a6
2 changed files with 11 additions and 0 deletions

View File

@@ -251,6 +251,7 @@ type GeminiChatTool struct {
GoogleSearchRetrieval any `json:"googleSearchRetrieval,omitempty"` GoogleSearchRetrieval any `json:"googleSearchRetrieval,omitempty"`
CodeExecution any `json:"codeExecution,omitempty"` CodeExecution any `json:"codeExecution,omitempty"`
FunctionDeclarations any `json:"functionDeclarations,omitempty"` FunctionDeclarations any `json:"functionDeclarations,omitempty"`
URLContext any `json:"urlContext,omitempty"`
} }
type GeminiChatGenerationConfig struct { type GeminiChatGenerationConfig struct {

View File

@@ -245,6 +245,7 @@ func CovertGemini2OpenAI(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
functions := make([]dto.FunctionRequest, 0, len(textRequest.Tools)) functions := make([]dto.FunctionRequest, 0, len(textRequest.Tools))
googleSearch := false googleSearch := false
codeExecution := false codeExecution := false
urlContext := false
for _, tool := range textRequest.Tools { for _, tool := range textRequest.Tools {
if tool.Function.Name == "googleSearch" { if tool.Function.Name == "googleSearch" {
googleSearch = true googleSearch = true
@@ -254,6 +255,10 @@ func CovertGemini2OpenAI(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
codeExecution = true codeExecution = true
continue continue
} }
if tool.Function.Name == "urlContext" {
urlContext = true
continue
}
if tool.Function.Parameters != nil { if tool.Function.Parameters != nil {
params, ok := tool.Function.Parameters.(map[string]interface{}) params, ok := tool.Function.Parameters.(map[string]interface{})
@@ -281,6 +286,11 @@ func CovertGemini2OpenAI(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i
GoogleSearch: make(map[string]string), GoogleSearch: make(map[string]string),
}) })
} }
if urlContext {
geminiTools = append(geminiTools, dto.GeminiChatTool{
URLContext: make(map[string]string),
})
}
if len(functions) > 0 { if len(functions) > 0 {
geminiTools = append(geminiTools, dto.GeminiChatTool{ geminiTools = append(geminiTools, dto.GeminiChatTool{
FunctionDeclarations: functions, FunctionDeclarations: functions,