ultisuite-backend/internal/websearch/client.go
R3D347HR4Y 621b0099d6
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(deploy): enhance Nginx configuration and API integration for UltiAI
- Updated .env.example to include new configuration options for the UltiAI branding and API endpoints.
- Enhanced Nginx configuration to support new API routes for the MCP and WebSocket connections.
- Introduced sub-filters for branding adjustments in Nginx responses.
- Added new JavaScript patch for API endpoint adjustments.
- Implemented tests for new API functionalities and improved error handling in the AI gateway.
2026-06-15 00:22:23 +02:00

56 lines
1.3 KiB
Go

package websearch
import (
"context"
"fmt"
"net/http"
"strings"
"time"
)
var braveSearchURL = "https://api.search.brave.com/res/v1/web/search"
var bingSearchURL = "https://api.bing.microsoft.com/v7.0/search"
var duckDuckGoHTMLURL = "https://html.duckduckgo.com/html/"
type Result struct {
Title string `json:"title"`
URL string `json:"url"`
Description string `json:"description"`
}
type Client struct {
http *http.Client
}
func NewClient() *Client {
return &Client{http: &http.Client{Timeout: 15 * time.Second}}
}
func (c *Client) Search(ctx context.Context, provider Provider, query string, count int) ([]Result, error) {
query = strings.TrimSpace(query)
if query == "" {
return nil, fmt.Errorf("search query is required")
}
if count <= 0 {
count = 5
}
if count > 20 {
count = 20
}
switch provider.Type {
case ProviderBrave:
return c.searchBrave(ctx, provider.APIKey, query, count)
case ProviderBing:
return c.searchBing(ctx, provider, query, count)
case ProviderDuckDuckGo:
return c.searchDuckDuckGo(ctx, provider, query, count)
case ProviderSearXNG:
return c.searchSearXNG(ctx, provider, query, count)
case ProviderCustom:
return c.searchCustom(ctx, provider, query, count)
default:
return nil, fmt.Errorf("unsupported search provider type: %s", provider.Type)
}
}