Feat: llm tool use

This commit is contained in:
Grail Finder
2025-09-05 14:03:17 +03:00
parent 8b88d2d824
commit 8699b1a84e
3 changed files with 119 additions and 44 deletions

23
main.go
View File

@@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
"flag"
"fmt"
"flag"
"io"
"log/slog"
"net/http"
@@ -194,7 +194,26 @@ func runBench(questions []models.Question) ([]models.Answer, error) {
logger.Error("failed to parse llm response", "error", err)
continue
}
a := models.Answer{Q: q, Answer: respText, Model: "default"} // model name from resp?
// Check if the response indicates tool usage
var toolCall models.ToolCallInfo
if strings.HasPrefix(respText, "[TOOL_CALL:") && strings.HasSuffix(respText, "]") {
// Extract tool name from the marker
toolName := strings.TrimPrefix(strings.TrimSuffix(respText, "]"), "[TOOL_CALL:")
toolCall = models.ToolCallInfo{
Name: toolName,
// Arguments would need to be parsed from the actual response
}
// Remove the marker from the response text
respText = fmt.Sprintf("Used tool: %s", toolName)
}
a := models.Answer{
Q: q,
Answer: respText,
Model: "default", // model name from resp?
ToolCall: toolCall,
}
answers = append(answers, a)
}
return answers, nil