fix: use Responses-compatible function tool_choice format
This commit is contained in:
@@ -991,9 +991,40 @@ func TestAnthropicToResponses_ToolChoiceSpecific(t *testing.T) {
|
||||
var tc map[string]any
|
||||
require.NoError(t, json.Unmarshal(resp.ToolChoice, &tc))
|
||||
assert.Equal(t, "function", tc["type"])
|
||||
fn, ok := tc["function"].(map[string]any)
|
||||
require.True(t, ok)
|
||||
assert.Equal(t, "get_weather", fn["name"])
|
||||
assert.Equal(t, "get_weather", tc["name"])
|
||||
assert.NotContains(t, tc, "function")
|
||||
}
|
||||
|
||||
func TestResponsesToAnthropicRequest_ToolChoiceFunctionName(t *testing.T) {
|
||||
req := &ResponsesRequest{
|
||||
Model: "gpt-5.2",
|
||||
Input: json.RawMessage(`[{"role":"user","content":"Hello"}]`),
|
||||
ToolChoice: json.RawMessage(`{"type":"function","name":"get_weather"}`),
|
||||
}
|
||||
|
||||
resp, err := ResponsesToAnthropicRequest(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var tc map[string]string
|
||||
require.NoError(t, json.Unmarshal(resp.ToolChoice, &tc))
|
||||
assert.Equal(t, "tool", tc["type"])
|
||||
assert.Equal(t, "get_weather", tc["name"])
|
||||
}
|
||||
|
||||
func TestResponsesToAnthropicRequest_ToolChoiceLegacyFunctionName(t *testing.T) {
|
||||
req := &ResponsesRequest{
|
||||
Model: "gpt-5.2",
|
||||
Input: json.RawMessage(`[{"role":"user","content":"Hello"}]`),
|
||||
ToolChoice: json.RawMessage(`{"type":"function","function":{"name":"get_weather"}}`),
|
||||
}
|
||||
|
||||
resp, err := ResponsesToAnthropicRequest(req)
|
||||
require.NoError(t, err)
|
||||
|
||||
var tc map[string]string
|
||||
require.NoError(t, json.Unmarshal(resp.ToolChoice, &tc))
|
||||
assert.Equal(t, "tool", tc["type"])
|
||||
assert.Equal(t, "get_weather", tc["name"])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user