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:
@@ -15,6 +15,14 @@ type MCPServer struct {
|
||||
AllowedTools []string `json:"allowed_tools,omitempty"`
|
||||
}
|
||||
|
||||
type WebSearchConfig struct {
|
||||
AllowedDomains []string `json:"allowed_domains,omitempty"`
|
||||
BlockedDomains []string `json:"blocked_domains,omitempty"`
|
||||
MaxUses int `json:"max_uses,omitempty"`
|
||||
Fetch bool `json:"fetch,omitempty"`
|
||||
MaxContentTokens int `json:"max_content_tokens,omitempty"`
|
||||
}
|
||||
|
||||
const (
|
||||
ThinkingModeAdaptive = "adaptive"
|
||||
ThinkingModeDisabled = "disabled"
|
||||
@@ -43,6 +51,7 @@ type BotConfig struct {
|
||||
ElevenLabsModel string `json:"elevenlabs_model"`
|
||||
DebugScreening bool `json:"debug_screening"`
|
||||
MCPServers []MCPServer `json:"mcp_servers,omitempty"`
|
||||
WebSearch *WebSearchConfig `json:"web_search,omitempty"`
|
||||
ConfigFilePath string `json:"-"`
|
||||
}
|
||||
|
||||
@@ -112,6 +121,11 @@ func loadAllConfigs(dir string) ([]BotConfig, error) {
|
||||
config.ID, config.MaxTokens)
|
||||
}
|
||||
|
||||
if ws := config.WebSearch; ws != nil && len(ws.AllowedDomains) == 0 && len(ws.BlockedDomains) == 0 {
|
||||
InfoLogger.Printf("[%s] web_search enabled with no allowed_domains/blocked_domains: the model may search the open web",
|
||||
config.ID)
|
||||
}
|
||||
|
||||
config.ConfigFilePath = validPath
|
||||
configs = append(configs, config)
|
||||
}
|
||||
@@ -168,6 +182,18 @@ func validateConfig(config *BotConfig, ids, tokens map[string]bool) error {
|
||||
return fmt.Errorf("'max_tokens' must be greater than 0 when set")
|
||||
}
|
||||
|
||||
if ws := config.WebSearch; ws != nil {
|
||||
if len(ws.AllowedDomains) > 0 && len(ws.BlockedDomains) > 0 {
|
||||
return fmt.Errorf("'web_search' cannot set both allowed_domains and blocked_domains (the API rejects that)")
|
||||
}
|
||||
if ws.MaxUses < 0 {
|
||||
return fmt.Errorf("'web_search.max_uses' must be greater than 0 when set")
|
||||
}
|
||||
if ws.MaxContentTokens < 0 {
|
||||
return fmt.Errorf("'web_search.max_content_tokens' must be greater than 0 when set")
|
||||
}
|
||||
}
|
||||
|
||||
if config.MessagePerHour <= 0 {
|
||||
return fmt.Errorf("'messages_per_hour' must be greater than 0")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user