Add toolbox features for function removal and callback execution
Introduced `WithFunctionRemoved` and `ExecuteCallbacks` methods to enhance `ToolBox` functionality. This allows dynamic function removal and execution of custom callbacks during tool call processing. Also cleaned up logging and improved handling for required tools in `openai.go`.
This commit is contained in:
11
openai.go
11
openai.go
@@ -3,7 +3,6 @@ package go_llm
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
oai "github.com/sashabaranov/go-openai"
|
||||
@@ -40,8 +39,10 @@ func (o openaiImpl) newRequestToOpenAIRequest(request Request) oai.ChatCompletio
|
||||
Parameters: tool.Parameters.Definition(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fmt.Println("tool:", tool.Name, tool.Description, tool.Strict, tool.Parameters.Definition())
|
||||
if !request.Toolbox.dontRequireTool {
|
||||
res.ToolChoice = "required"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +73,6 @@ func (o openaiImpl) responseToLLMResponse(response oai.ChatCompletionResponse) R
|
||||
for _, choice := range response.Choices {
|
||||
var toolCalls []ToolCall
|
||||
for _, call := range choice.Message.ToolCalls {
|
||||
fmt.Println("responseToLLMResponse: call:", call.Function.Arguments)
|
||||
toolCall := ToolCall{
|
||||
ID: call.ID,
|
||||
FunctionCall: FunctionCall{
|
||||
@@ -81,8 +81,6 @@ func (o openaiImpl) responseToLLMResponse(response oai.ChatCompletionResponse) R
|
||||
},
|
||||
}
|
||||
|
||||
fmt.Println("toolCall.FunctionCall.Arguments:", toolCall.FunctionCall.Arguments)
|
||||
|
||||
toolCalls = append(toolCalls, toolCall)
|
||||
|
||||
}
|
||||
@@ -103,11 +101,8 @@ func (o openaiImpl) ChatComplete(ctx context.Context, request Request) (Response
|
||||
|
||||
req := o.newRequestToOpenAIRequest(request)
|
||||
|
||||
slog.Info("openaiImpl.ChatComplete", "req", fmt.Sprintf("%#v", req))
|
||||
resp, err := cl.CreateChatCompletion(ctx, req)
|
||||
|
||||
fmt.Println("resp:", fmt.Sprintf("%#v", resp))
|
||||
|
||||
if err != nil {
|
||||
return Response{}, fmt.Errorf("unhandled openaiImpl error: %w", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user