Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) QASearch(q string, params ...TavilyRequest) (string, error)
- func (c *Client) QASearchWithCtx(ctx context.Context, q string, params ...TavilyRequest) (string, error)
- func (c *Client) Search(q string, params ...TavilyRequest) (*TavilyResponse, error)
- func (c *Client) SearchWithCtx(ctx context.Context, q string, params ...TavilyRequest) (*TavilyResponse, error)
- func (c *Client) SearchWithDepth(q string, depth string) (*TavilyResponse, error)
- func (c *Client) SearchWithDomains(q string, inc []string, exc []string) (*TavilyResponse, error)
- func (c *Client) SearchWithNResults(q string, n uint32) (*TavilyResponse, error)
- func (c *Client) SetMaxResults(d uint32)
- func (c *Client) SetSearchDepth(d string) error
- func (c *Client) SetTimeout(d uint32)
- type SearchHandler
- type TavilyRequest
- type TavilyResponse
- type TavilyResult
Constants ¶
const ( TavilyBaseURL = "https://api.tavily.com/search" DefaultModelEncoding = "gpt-3.5-turbo" DefaultMaxTokens = 4000 )
Variables ¶
var (
ErrUnknownDepth = errors.New("Unknown search depth, use 'basic' or 'advanced'")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { APIKey string // contains filtered or unexported fields }
Client A struct to work with Tavily
func NewClient ¶
NewClient Produce a new Tavily Client with the given API Key. If the API key is empty, an error is returned
func (*Client) QASearch ¶
func (c *Client) QASearch(q string, params ...TavilyRequest) (string, error)
QASearch - Question and Answer Search start. Defaults are changed to search depth advanced regardless how the client is set unless explicitly added in the params to get the best answer. Returns only the answer to the question instead of the entire response Params sent accept search depth, max results, and domains to include or exclude. All else is ignored Only the first TavilyRequest Struct will be concidered if multiple are sent
func (*Client) QASearchWithCtx ¶
func (c *Client) QASearchWithCtx(ctx context.Context, q string, params ...TavilyRequest) (string, error)
QASearchWithCtx - With a custom context value, Question and Answer Search start. Defaults are changed to search depth advanced regardless how the client is set unless explicitly added in the params to get the best answer. Returns only the answer to the question instead of the entire response Params sent accept search depth, max results, and domains to include or exclude. All else is ignored Only the first TavilyRequest Struct will be concidered if multiple are sent
func (*Client) Search ¶
func (c *Client) Search(q string, params ...TavilyRequest) (*TavilyResponse, error)
Search Use Tavily AI to search the internet. Must provide a query string. Optionally, provide a request object to customize the search query. If an array of request objects are input, only the first will be used
func (*Client) SearchWithCtx ¶
func (c *Client) SearchWithCtx(ctx context.Context, q string, params ...TavilyRequest) (*TavilyResponse, error)
SearchWithCtx Use Tavily to perform a search but pass in a custom context.Context value ctx - a custom context.Context to use q - a query or search string to use (optionally) TavilyRequest - provide a request object to overwrite all the params of the request
func (*Client) SearchWithDepth ¶
func (c *Client) SearchWithDepth(q string, depth string) (*TavilyResponse, error)
SearchWithDepth Search Tavily with a custom Search Depth just for this query. Otherwise, all defaults are used
func (*Client) SearchWithDomains ¶
SearchWithDepth Search Tavily with explicity domains to include or exclude from the search Use empty string slices to avoid including or excluding anything specific. Otherwise, all defaults are used
func (*Client) SearchWithNResults ¶
func (c *Client) SearchWithNResults(q string, n uint32) (*TavilyResponse, error)
SearchWithDepth Search Tavily with a custom number of results returned just for this query. Otherwise, all defaults are used
func (*Client) SetMaxResults ¶
SetMaxResults to any positive number to increase the number of results returned
func (*Client) SetSearchDepth ¶
SetSearchDepth This allows the user to change the default search depth for all future queries. The Default is 'basic', options: ['basic', 'advanced']
func (*Client) SetTimeout ¶
SetTimeout Set the request timeout in Millisecond (ms) Default is 30,000ms or 30 seconds
type SearchHandler ¶ added in v0.1.1
type SearchHandler struct{}
func (*SearchHandler) ServeHTTP ¶ added in v0.1.1
func (h *SearchHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type TavilyRequest ¶
type TavilyRequest struct { ApiKey string `json:"api_key"` Query string `json:"query"` SearchDepth string `json:"search_depth,omitempty"` IncludeImages bool `json:"include_images,omitempty"` IncludeAnswer bool `json:"include_answer,omitempty"` IncludeRawContent bool `json:"include_raw_content,omitempty"` MaxResults uint32 `json:"max_results,omitempty"` IncludeDomains []string `json:"include_domains,omitempty"` ExcludeDomains []string `json:"exclude_domains,omitempty"` }
TavilyRequest Payload structure to hit the Tavily API
type TavilyResponse ¶
type TavilyResponse struct { Answer string `json:"answer"` Query string `json:"query"` ResponseTime float64 `json:"response_time"` Images []string `json:"images,omitempty"` FollowUpQuestions []string `json:"follow_up_questions"` Results []TavilyResult `json:"results"` }
TavilyResponse is the expected response back from Tavily
type TavilyResult ¶
type TavilyResult struct { Title string `json:"title"` //The URL for the website used URL string `json:"url"` //content which used from the site used Content string `json:"content"` //The raw content from the Website RawContent *string `json:"raw_content"` //Tavily's relevance score Score float64 `json:"score"` }
TavilyResult is a single record relating to the search