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"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
@ -473,9 +475,22 @@ func (t *WebSearchTool) Execute(ctx context.Context, args map[string]any) *ToolR
|
||||||
}
|
}
|
||||||
|
|
||||||
count := t.maxResults
|
count := t.maxResults
|
||||||
if c, ok := args["count"].(float64); ok {
|
switch v := args["count"].(type) {
|
||||||
if int(c) > 0 && int(c) <= 10 {
|
case float64:
|
||||||
count = int(c)
|
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