Feat: llm tool use
This commit is contained in:
23
main.go
23
main.go
@@ -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
|
||||
|
Reference in New Issue
Block a user