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:
2024-11-11 00:23:01 -05:00
parent cd4ad59a38
commit 0993a8e865
5 changed files with 37 additions and 28 deletions

View File

@@ -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)
}