Thanks to visit codestin.com
Credit goes to github.com

Skip to content

hekmon/tavily

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tavily Go bindings

Go Reference Go report card

These Go bindings implements the Tavily REST API for the Tavily SaaS service. Tavily offers APIs to search the web and retreive results in a simpe and clean way. It is first intended for LLM Agents but can be used for other purposes as well.

Features

Endpoints

All current endpoints are supported:

  • Search
  • Extract

Rate Limiting

The client will automatically handle Tavily rate limiting for you.

Golang types

Every fields of tavily API responses that can be convert to high level Golang types will be converted for ease of use within your code base.

For example: time.Duration, *url.URL

But they will be reverted to their original type and value if they are marshal again to JSON.

Error Handling

The client will return a typed error with body content if the API returns a known API error status code.

API Credits

The client will track current session API credits usage thru its stats method/object.

Usage

Installation

go get -v github.com/hekmon/tavily/v2

Example

package main

import (
    "context"

    "github.com/hekmon/tavily"
)

func main() {
    client := tavily.NewClient("<your-tavily-API-key>", tavily.APIKeyTypeDev, nil)
    answer, err := client.Search(context.TODO(), tavily.SearchQuery{
        Query:                    "What is Tavily ?",
        SearchDepth:              tavily.SearchDepthAdvanced,     // optional
        Topic:                    tavily.SearchQueryTopicGeneral, // optional
        MaxResults:               3,                              // optional
        IncludeImages:            true,                           // optional
        IncludeImageDescriptions: true,                           // optional
        IncludeAnswer:            true,                           // optional but recommended for LLMs agents
        // ... others optional params exist
    })
    if err != nil {
        panic(err)
    }
    // Do something with the answer
    // ...
}

OpenAI Tool helper

An optional package can help you to integrate this Tavily client as a tool with the OpenAI official API bindings.

Contributors 2

  •  
  •  

Languages