fix(gemini): 使用 JSON Schema 传递工具参数
This commit is contained in:
@@ -1406,7 +1406,24 @@ func TestGeminiClientChatRestoresToolContext(t *testing.T) {
|
|||||||
"function": map[string]any{
|
"function": map[string]any{
|
||||||
"name": "get_weather",
|
"name": "get_weather",
|
||||||
"description": "lookup weather",
|
"description": "lookup weather",
|
||||||
"parameters": map[string]any{"type": "object"},
|
"parameters": map[string]any{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]any{
|
||||||
|
"location": map[string]any{
|
||||||
|
"anyOf": []any{
|
||||||
|
map[string]any{"type": "string"},
|
||||||
|
map[string]any{
|
||||||
|
"type": "object",
|
||||||
|
"properties": map[string]any{
|
||||||
|
"city": map[string]any{"type": "string"},
|
||||||
|
},
|
||||||
|
"required": []any{"city"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": []any{"location"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}},
|
}},
|
||||||
},
|
},
|
||||||
@@ -1450,6 +1467,18 @@ func TestGeminiClientChatRestoresToolContext(t *testing.T) {
|
|||||||
if declaration["name"] != "get_weather" || declaration["description"] != "lookup weather" {
|
if declaration["name"] != "get_weather" || declaration["description"] != "lookup weather" {
|
||||||
t.Fatalf("tool declaration was not converted for Gemini: %+v", captured["tools"])
|
t.Fatalf("tool declaration was not converted for Gemini: %+v", captured["tools"])
|
||||||
}
|
}
|
||||||
|
if _, exists := declaration["parameters"]; exists {
|
||||||
|
t.Fatalf("Gemini tool declaration must not use OpenAPI parameters: %+v", declaration)
|
||||||
|
}
|
||||||
|
parameters, _ := declaration["parametersJsonSchema"].(map[string]any)
|
||||||
|
properties, _ := parameters["properties"].(map[string]any)
|
||||||
|
location, _ := properties["location"].(map[string]any)
|
||||||
|
anyOf, _ := location["anyOf"].([]any)
|
||||||
|
nestedObject, _ := anyOf[1].(map[string]any)
|
||||||
|
required, _ := nestedObject["required"].([]any)
|
||||||
|
if len(anyOf) != 2 || len(required) != 1 || required[0] != "city" {
|
||||||
|
t.Fatalf("Gemini JSON Schema was not preserved: %+v", declaration)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGeminiClientChatConvertsFunctionCallResponse(t *testing.T) {
|
func TestGeminiClientChatConvertsFunctionCallResponse(t *testing.T) {
|
||||||
|
|||||||
@@ -523,7 +523,7 @@ func geminiToolsFromOpenAITools(value any) []any {
|
|||||||
declaration["description"] = description
|
declaration["description"] = description
|
||||||
}
|
}
|
||||||
if parameters, ok := function["parameters"]; ok {
|
if parameters, ok := function["parameters"]; ok {
|
||||||
declaration["parameters"] = parameters
|
declaration["parametersJsonSchema"] = parameters
|
||||||
}
|
}
|
||||||
declarations = append(declarations, declaration)
|
declarations = append(declarations, declaration)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user