executeToolCall executes a single tool call
(ctx context.Context, toolCall openai.ChatCompletionMessageToolCall, sessionID string)
| 37 | |
| 38 | // executeToolCall executes a single tool call |
| 39 | func (te *ToolExecutor) executeToolCall(ctx context.Context, toolCall openai.ChatCompletionMessageToolCall, sessionID string) models.ToolCallResult { |
| 40 | functionName := toolCall.Function.Name |
| 41 | arguments := toolCall.Function.Arguments |
| 42 | toolCallID := toolCall.ID |
| 43 | |
| 44 | switch functionName { |
| 45 | case "search_products": |
| 46 | return te.handleSearchProducts(arguments, toolCallID) |
| 47 | case "add_to_cart": |
| 48 | return te.handleAddToCart(arguments, sessionID, toolCallID) |
| 49 | case "remove_from_cart": |
| 50 | return te.handleRemoveFromCart(arguments, sessionID, toolCallID) |
| 51 | case "view_cart": |
| 52 | return te.handleViewCart(sessionID, toolCallID) |
| 53 | case "checkout": |
| 54 | return te.handleCheckout(sessionID, toolCallID) |
| 55 | default: |
| 56 | return models.ToolCallResult{ |
| 57 | CallID: toolCallID, |
| 58 | ToolName: functionName, |
| 59 | Success: false, |
| 60 | Error: fmt.Sprintf("Unknown tool: %s", functionName), |
| 61 | Arguments: arguments, |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | // handleSearchProducts handles product search tool calls |
| 67 | func (te *ToolExecutor) handleSearchProducts(arguments string, toolCallID string) models.ToolCallResult { |
no test coverage detected