mirror of
https://github.com/HugeFrog24/go-telegram-bot.git
synced 2026-08-28 22:11:38 +00:00
Add web search capabilities
This commit is contained in:
@@ -127,6 +127,90 @@ func TestBackwardCompatibleParams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWebSearchTools(t *testing.T) {
|
||||
t.Run("nil config yields no tools", func(t *testing.T) {
|
||||
if tools := webSearchTools(nil); tools != nil {
|
||||
t.Errorf("webSearchTools(nil) = %v, want nil", tools)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("search only when fetch off", func(t *testing.T) {
|
||||
tools := webSearchTools(&WebSearchConfig{
|
||||
AllowedDomains: []string{"example.com/hc"},
|
||||
MaxUses: 3,
|
||||
})
|
||||
if len(tools) != 1 {
|
||||
t.Fatalf("got %d tools, want 1 (search only)", len(tools))
|
||||
}
|
||||
if tools[0].OfWebSearchTool20250305 == nil {
|
||||
t.Fatalf("tools[0] is not a web_search tool")
|
||||
}
|
||||
if tools[0].OfWebFetchTool20250910 != nil {
|
||||
t.Error("web_fetch tool present but fetch is off")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("search + fetch with allowlist and citations", func(t *testing.T) {
|
||||
tools := webSearchTools(&WebSearchConfig{
|
||||
AllowedDomains: []string{"example.com/hc", "docs.example.com"},
|
||||
MaxUses: 3,
|
||||
Fetch: true,
|
||||
MaxContentTokens: 50000,
|
||||
})
|
||||
if len(tools) != 2 {
|
||||
t.Fatalf("got %d tools, want 2 (search + fetch)", len(tools))
|
||||
}
|
||||
|
||||
search := tools[0].OfWebSearchTool20250305
|
||||
if search == nil {
|
||||
t.Fatalf("tools[0] is not a web_search tool")
|
||||
}
|
||||
if len(search.AllowedDomains) != 2 {
|
||||
t.Errorf("search AllowedDomains = %v, want 2 entries", search.AllowedDomains)
|
||||
}
|
||||
if search.MaxUses.Value != 3 {
|
||||
t.Errorf("search MaxUses = %d, want 3", search.MaxUses.Value)
|
||||
}
|
||||
|
||||
fetch := tools[1].OfWebFetchTool20250910
|
||||
if fetch == nil {
|
||||
t.Fatalf("tools[1] is not a web_fetch tool")
|
||||
}
|
||||
if len(fetch.AllowedDomains) != 2 {
|
||||
t.Errorf("fetch AllowedDomains = %v, want 2 entries", fetch.AllowedDomains)
|
||||
}
|
||||
if fetch.MaxContentTokens.Value != 50000 {
|
||||
t.Errorf("fetch MaxContentTokens = %d, want 50000", fetch.MaxContentTokens.Value)
|
||||
}
|
||||
if fetch.Citations.Enabled.Value != true {
|
||||
t.Error("fetch citations not enabled")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("wire shape carries allowed_domains", func(t *testing.T) {
|
||||
tools := webSearchTools(&WebSearchConfig{
|
||||
AllowedDomains: []string{"thatgamecompany.helpshift.com/hc"},
|
||||
MaxUses: 2,
|
||||
Fetch: true,
|
||||
})
|
||||
raw, err := json.Marshal(tools)
|
||||
if err != nil {
|
||||
t.Fatalf("marshal: %v", err)
|
||||
}
|
||||
body := string(raw)
|
||||
for _, want := range []string{
|
||||
"web_search_20250305",
|
||||
"web_fetch_20250910",
|
||||
"thatgamecompany.helpshift.com/hc",
|
||||
"allowed_domains",
|
||||
} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("wire body missing %q:\n%s", want, body)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestEmptyStreamError(t *testing.T) {
|
||||
err := emptyStreamError("max_tokens", 3900, 4000)
|
||||
for _, want := range []string{"output budget exhausted", "3900", "4000"} {
|
||||
|
||||
Reference in New Issue
Block a user