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:
13
toolbox.go
13
toolbox.go
@@ -2,11 +2,9 @@ package go_llm
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/sashabaranov/go-openai"
|
||||
"log/slog"
|
||||
)
|
||||
|
||||
// ToolBox is a collection of tools that OpenAI can use to execute functions.
|
||||
@@ -69,8 +67,6 @@ var (
|
||||
func (t *ToolBox) ExecuteFunction(ctx context.Context, functionName string, params string) (string, error) {
|
||||
f, ok := t.names[functionName]
|
||||
|
||||
slog.Info("functionName", functionName)
|
||||
|
||||
if !ok {
|
||||
return "", newError(ErrFunctionNotFound, fmt.Errorf("function \"%s\" not found", functionName))
|
||||
}
|
||||
@@ -79,12 +75,5 @@ func (t *ToolBox) ExecuteFunction(ctx context.Context, functionName string, para
|
||||
}
|
||||
|
||||
func (t *ToolBox) Execute(ctx context.Context, toolCall ToolCall) (string, error) {
|
||||
slog.Info("toolCall", toolCall)
|
||||
|
||||
b, err := json.Marshal(toolCall.FunctionCall.Arguments)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to marshal arguments: %w", err)
|
||||
}
|
||||
return t.ExecuteFunction(ctx, toolCall.ID, string(b))
|
||||
return t.ExecuteFunction(ctx, toolCall.FunctionCall.Name, toolCall.FunctionCall.Arguments)
|
||||
}
|
||||
|
Reference in New Issue
Block a user