add proxy support for TavilySearchProvider

This commit is contained in:
George Wang 2026-02-23 16:23:10 +08:00
parent ba17ed712a
commit fb7a5b9ee7
2 changed files with 7 additions and 1 deletions

View file

@ -277,6 +277,7 @@ func DefaultConfig() *Config {
}, },
Tools: ToolsConfig{ Tools: ToolsConfig{
Web: WebToolsConfig{ Web: WebToolsConfig{
Proxy: "",
Brave: BraveConfig{ Brave: BraveConfig{
Enabled: false, Enabled: false,
APIKey: "", APIKey: "",

View file

@ -129,6 +129,7 @@ func (p *BraveSearchProvider) Search(ctx context.Context, query string, count in
type TavilySearchProvider struct { type TavilySearchProvider struct {
apiKey string apiKey string
baseURL string baseURL string
proxy string
} }
func (p *TavilySearchProvider) Search(ctx context.Context, query string, count int) (string, error) { func (p *TavilySearchProvider) Search(ctx context.Context, query string, count int) (string, error) {
@ -160,7 +161,10 @@ func (p *TavilySearchProvider) Search(ctx context.Context, query string, count i
req.Header.Set("Content-Type", "application/json") req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", userAgent) req.Header.Set("User-Agent", userAgent)
client := &http.Client{Timeout: 10 * time.Second} client, err := createHTTPClient(p.proxy, 10*time.Second)
if err != nil {
return "", fmt.Errorf("failed to create http client: %w", err)
}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return "", fmt.Errorf("request failed: %w", err) return "", fmt.Errorf("request failed: %w", err)
@ -420,6 +424,7 @@ func NewWebSearchTool(opts WebSearchToolOptions) *WebSearchTool {
provider = &TavilySearchProvider{ provider = &TavilySearchProvider{
apiKey: opts.TavilyAPIKey, apiKey: opts.TavilyAPIKey,
baseURL: opts.TavilyBaseURL, baseURL: opts.TavilyBaseURL,
proxy: opts.Proxy,
} }
if opts.TavilyMaxResults > 0 { if opts.TavilyMaxResults > 0 {
maxResults = opts.TavilyMaxResults maxResults = opts.TavilyMaxResults