fix(ollama): adapt to ToolCallFunctionArguments struct API

The ollama Go SDK changed ToolCallFunctionArguments from
map[string]any to a struct backed by an ordered map. Use ToMap() for
read access and NewToolCallFunctionArguments()+UnmarshalJSON for
construction so the build matches the upgraded SDK.
This commit is contained in:
wizardchen
2026-05-09 13:58:55 +08:00
parent 4bac6e30d2
commit ff950ef249
+5 -4
View File
@@ -240,9 +240,10 @@ func (c *OllamaChat) ChatStream(
}
for _, tc := range resp.Message.ToolCalls {
argsMap := tc.Function.Arguments.ToMap()
switch tc.Function.Name {
case "final_answer":
if answer, ok := tc.Function.Arguments["answer"].(string); ok && answer != "" {
if answer, ok := argsMap["answer"].(string); ok && answer != "" {
streamChan <- types.StreamResponse{
ResponseType: types.ResponseTypeAnswer,
Content: answer,
@@ -253,7 +254,7 @@ func (c *OllamaChat) ChatStream(
}
}
case "thinking":
if thought, ok := tc.Function.Arguments["thought"].(string); ok && thought != "" {
if thought, ok := argsMap["thought"].(string); ok && thought != "" {
streamChan <- types.StreamResponse{
ResponseType: types.ResponseTypeThinking,
Content: thought,
@@ -368,9 +369,9 @@ func (c *OllamaChat) toolCallFrom(toolCalls []ToolCall) []ollamaapi.ToolCall {
}
ollamaToolCalls := make([]ollamaapi.ToolCall, 0, len(toolCalls))
for _, tc := range toolCalls {
var args map[string]interface{}
args := ollamaapi.NewToolCallFunctionArguments()
if tc.Function.Arguments != "" {
_ = json.Unmarshal([]byte(tc.Function.Arguments), &args)
_ = args.UnmarshalJSON([]byte(tc.Function.Arguments))
}
ollamaToolCalls = append(ollamaToolCalls, ollamaapi.ToolCall{
Function: ollamaapi.ToolCallFunction{