Fix unmarshalling issues and adjust logging for debugging
Modify `FunctionCall` struct to handle arguments as strings. Add debugging logs to facilitate error tracing and improve JSON unmarshalling in various functions.
This commit is contained in:
20
anthropic.go
20
anthropic.go
@@ -2,6 +2,7 @@ package go_llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
anth "github.com/liushuangls/go-anthropic/v2"
|
||||
"log"
|
||||
@@ -120,13 +121,18 @@ func (a anthropic) responseToLLMResponse(in anth.MessagesResponse) Response {
|
||||
|
||||
case anth.MessagesContentTypeToolUse:
|
||||
if msg.MessageContentToolUse != nil {
|
||||
choice.Calls = append(choice.Calls, ToolCall{
|
||||
ID: msg.MessageContentToolUse.ID,
|
||||
FunctionCall: FunctionCall{
|
||||
Name: msg.MessageContentToolUse.Name,
|
||||
Arguments: msg.MessageContentToolUse.Input,
|
||||
},
|
||||
})
|
||||
b, e := json.Marshal(msg.MessageContentToolUse.Input)
|
||||
if e != nil {
|
||||
log.Println("failed to marshal input", e)
|
||||
} else {
|
||||
choice.Calls = append(choice.Calls, ToolCall{
|
||||
ID: msg.MessageContentToolUse.ID,
|
||||
FunctionCall: FunctionCall{
|
||||
Name: msg.MessageContentToolUse.Name,
|
||||
Arguments: string(b),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user