[go: nahoru, domu]

Skip to content

An unofficial Go port of the official Tavily API Python Wrapper.

License

Notifications You must be signed in to change notification settings

diverged/tavily-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tavily-go

An unofficial Go client for the Tavily search API, modeled closely on the official Tavily Python Wrapper.

Installation

To install the tavily-go package, use the following command:

go get github.com/diverged/tavily-go

Usage

Below is a simple example of how to use the tavily-go package:

package main

import (
    "fmt"
    "log"

    tavilygo "github.com/diverged/tavily-go"
    "github.com/diverged/tavily-go/models"
)

func main() {
    // Create a new Tavily client
    client := tavilygo.NewClient("your-api-key-here")

    // Perform a search
    searchReq := models.SearchRequest{
        Query:       "What is the capital of France?",
        SearchDepth: "basic",
    }
    
    response, err := tavilygo.Search(client, searchReq)
    if err != nil {
        log.Fatalf("Error performing search: %v", err)
    }

    // Print the search results
    for _, result := range response.Results {
        fmt.Printf("Title: %s\nURL: %s\n\n", result.Title, result.URL)
    }

    // Perform a Q&A search
    answer, err := tavilygo.QnASearch(client, "What is the capital of France?", "basic")
    if err != nil {
        log.Fatalf("Error performing Q&A search: %v", err)
    }

    fmt.Printf("Answer: %s\n", answer)
}

License

MIT