fix: enhance count argument handling in WebSearchTool to support string input
This commit is contained in:
parent
ec6da7a530
commit
52a137f771
1 changed files with 18 additions and 3 deletions
|
|
@ -6,9 +6,11 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -473,9 +475,22 @@ func (t *WebSearchTool) Execute(ctx context.Context, args map[string]any) *ToolR
|
|||
}
|
||||
|
||||
count := t.maxResults
|
||||
if c, ok := args["count"].(float64); ok {
|
||||
if int(c) > 0 && int(c) <= 10 {
|
||||
count = int(c)
|
||||
switch v := args["count"].(type) {
|
||||
case float64:
|
||||
rounded := int(math.Round(v))
|
||||
if math.Abs(v-float64(rounded)) > 1e-9 {
|
||||
return ErrorResult(fmt.Sprintf("count must be an integer, got %v", v))
|
||||
}
|
||||
if rounded > 0 && rounded <= 10 {
|
||||
count = rounded
|
||||
}
|
||||
case int:
|
||||
if v > 0 && v <= 10 {
|
||||
count = v
|
||||
}
|
||||
case string:
|
||||
if n, err := strconv.Atoi(v); err == nil && n > 0 && n <= 10 {
|
||||
count = n
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue