### Answer Go Example Source: https://context7.com/lollipopkit/exa/llms.txt Demonstrates how to get AI-generated answers with citations using the Exa Go client. Requires an API key. ```go package main import ( "context" "fmt" "log" "github.com/lollipopkit/exa" ) func main() { client, _ := exa.NewClient("YOUR_EXA_API_KEY") ctx := context.Background() // Get an answer with citations resp, err := client.Answer(ctx, exa.AnswerRequest{ Query: "What are the key differences between GPT-4 and Claude 3?", NumResults: 5, Type: exa.SearchTypeNeural, Contents: &exa.ContentsRequest{ Text: exa.BoolValue[exa.TextOptions](true), }, }) if err != nil { log.Fatalf("Answer failed: %v", err) } fmt.Printf("Request ID: %s\n\n", resp.RequestID) fmt.Printf("Answer:\n%s\n\n", resp.Answer) if len(resp.Citations) > 0 { fmt.Println("Citations:") for i, citation := range resp.Citations { fmt.Printf("%d. %s\n %s\n", i+1, citation.Title, citation.URL) } } if len(resp.Results) > 0 { fmt.Println("\nSource content:") for i, result := range resp.Results { fmt.Printf("\n%d. %s\n", i+1, result.Title) if len(result.Text) > 200 { fmt.Printf(" %s...\n", result.Text[:200]) } } } if resp.CostDollars != nil { fmt.Printf("\nTotal cost: $%.6f\n", resp.CostDollars.Total) } } // Expected output: // Request ID: req-xyz789 // // Answer: // GPT-4 and Claude 3 are both large language models but differ in several key aspects... // // Citations: // 1. Comparing GPT-4 and Claude 3 // https://example.com/ai-comparison // 2. Claude 3 Technical Report // https://anthropic.com/claude-3 ``` -------------------------------- ### Install Exa CLI Source: https://github.com/lollipopkit/exa/blob/main/README.md Installs the Exa command-line interface tool using the Go package manager. This command fetches the latest version of the CLI. ```bash go install github.com/lollipopkit/exa/cmd/cli@latest ``` -------------------------------- ### FindSimilar Go Example Source: https://context7.com/lollipopkit/exa/llms.txt Demonstrates finding content similar to a given URL or text description using the Exa Go client. Ensure your API key is set. ```go package main import ( "context" "fmt" "log" "github.com/lollipopkit/exa" ) func main() { client, _ := exa.NewClient("YOUR_EXA_API_KEY") ctx := context.Background() // Find content similar to a URL urlResp, err := client.FindSimilar(ctx, exa.SimilarRequest{ URL: "https://arxiv.org/abs/2301.07041", NumResults: 5, IncludeDomains: []string{"arxiv.org", "openai.com", "anthropic.com"}, }) if err != nil { log.Fatalf("FindSimilar by URL failed: %v", err) } fmt.Println("Similar papers:") for i, result := range urlResp.Results { fmt.Printf("%d. %s - %s\n", i+1, result.Title, result.URL) } // Find content similar to a text description textResp, err := client.FindSimilar(ctx, exa.SimilarRequest{ Text: "Research papers about transformer architectures and attention mechanisms in deep learning", NumResults: 10, Contents: &exa.ContentsRequest{ Text: exa.BoolValue[exa.TextOptions](true), Summary: &exa.SummaryRequest{}, }, }) if err != nil { log.Fatalf("FindSimilar by text failed: %v", err) } fmt.Println("\nRelated content:") for i, result := range textResp.Results { fmt.Printf("\n%d. %s\n", i+1, result.Title) fmt.Printf(" URL: %s\n", result.URL) if result.Summary != "" { fmt.Printf(" Summary: %s\n", result.Summary) } } if textResp.CostDollars != nil { fmt.Printf("\nTotal cost: $%.6f\n", textResp.CostDollars.Total) } } // Expected output: // Similar papers: // 1. Attention Is All You Need - https://arxiv.org/abs/1706.03762 // 2. BERT: Pre-training of Deep Bidirectional Transformers - https://arxiv.org/abs/1810.04805 // ... ``` -------------------------------- ### Search with JSON Output and Full Content Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Example of a search query configured to output results in JSON format and include the full content of the found items. ```bash exa search "renewable energy" --output json --include-contents ``` -------------------------------- ### Ask for an Answer with Citations Source: https://github.com/lollipopkit/exa/blob/main/README.md Queries the Exa API to get an answer to a question, including citations for the information provided. This is helpful for research and fact-checking. ```go // Ask for an answer with citations answer, _ := c.Answer(ctx, exa.AnswerRequest{Query: "What is Exa?"}) ``` -------------------------------- ### Get AI Answer with Citations Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Shows how to get an AI-generated answer to a question, limiting the number of sources used for the response. ```bash exa answer "What are the benefits of meditation?" --num-results 5 ``` -------------------------------- ### Exa CLI - Get AI Answer Source: https://context7.com/lollipopkit/exa/llms.txt Obtains an AI-generated answer to a question, including citations, with options for search type, number of results, and JSON output. ```bash # Get AI answer with citations exa answer "What are the benefits of using Go for backend development?" \ --search-type deep \ --num-results 5 \ --output json ``` -------------------------------- ### Get AI Answer to a Question Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Obtain an AI-generated answer to a question using the 'exa answer' command. This feature provides summarized information with citations. ```bash # Get answer to a question exa answer "What are the latest developments in quantum computing?" ``` -------------------------------- ### Exa Contents Output as JSON Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Get the content retrieval results in JSON format by specifying the --output json flag. This is useful for scripting and data processing. ```bash # JSON output exa contents https://example.com --output json ``` -------------------------------- ### Initialize Exa Client and Perform Search Source: https://github.com/lollipopkit/exa/blob/main/README.md Initializes the Exa client with an API key and demonstrates how to perform a search query, including retrieving content. Ensure you replace 'YOUR_EXA_API_KEY' with your actual API key. ```go import ( "context" "github.com/lollipopkit/exa" ) ctx := context.Background() c, err := exa.NewClient("YOUR_EXA_API_KEY") if err != nil { /* handle */ } // Search with contents resp, err := c.Search(ctx, exa.SearchRequest{ Query: "Latest research in LLMs", Contents: &exa.ContentsRequest{Text: exa.BoolValue[exa.TextOptions](true)}, }) ``` -------------------------------- ### Initialize Exa Go Client Source: https://context7.com/lollipopkit/exa/llms.txt Initialize the Exa client with your API key. Supports optional configuration for custom base URLs and HTTP clients. ```go package main import ( "context" "fmt" "log" "net/http" "time" "github.com/lollipopkit/exa" ) func main() { // Basic client initialization client, err := exa.NewClient("YOUR_EXA_API_KEY") if err != nil { log.Fatalf("Failed to create client: %v", err) } // Client with custom options customHTTPClient := &http.Client{Timeout: 30 * time.Second} clientWithOptions, err := exa.NewClient( "YOUR_EXA_API_KEY", exa.WithBaseURL("https://custom-api.exa.ai"), exa.WithHTTPClient(customHTTPClient), ) if err != nil { log.Fatalf("Failed to create client: %v", err) } fmt.Printf("Client created: %+v\n", client) fmt.Printf("Custom client created: %+v\n", clientWithOptions) } ``` -------------------------------- ### Exa CLI - Retrieve Page Contents Source: https://context7.com/lollipopkit/exa/llms.txt Fetches and displays the content of a given URL, with options to include highlights and a summary. ```bash # Retrieve page contents exa contents https://go.dev/doc/effective_go \ --highlights \ --summary ``` -------------------------------- ### Using BoolOrObject and StringOrList Type Helpers in Go Source: https://context7.com/lollipopkit/exa/llms.txt Illustrates how to use BoolValue, ObjectValue, StringValue, and StringList helpers for API parameters. Shows serialization to JSON for different types of values. ```go package main import ( "encoding/json" "fmt" "github.com/lollipopkit/exa" ) func main() { // BoolOrObject: Use BoolValue for simple boolean simpleText := exa.BoolValue[exa.TextOptions](true) // BoolOrObject: Use ObjectValue for detailed configuration detailedText := exa.ObjectValue(exa.TextOptions{ MaxCharacters: intPtr(10000), IncludeHTMLTags: boolPtr(false), }) // StringOrList: Use StringValue for single string singleTarget := exa.StringValue("pricing") // StringOrList: Use StringList for multiple values multipleTargets := exa.StringList([]string{"pricing", "features", "documentation"}) // Example request using these helpers req := exa.ContentsRequest{ Text: detailedText, SubpageTarget: multipleTargets, Highlights: &exa.HighlightsRequest{ NumSentences: intPtr(3), HighlightsPerURL: intPtr(2), }, } // Serialize to JSON data, _ := json.MarshalIndent(req, "", " ") fmt.Printf("Request JSON:\n%s\n", string(data)) // Show boolean serialization boolData, _ := json.Marshal(simpleText) fmt.Printf("\nSimple text (bool): %s\n", boolData) objData, _ := json.Marshal(detailedText) fmt.Printf("Detailed text (object): %s\n", objData) singleData, _ := json.Marshal(singleTarget) fmt.Printf("Single target: %s\n", singleData) listData, _ := json.Marshal(multipleTargets) fmt.Printf("Multiple targets: %s\n", listData) } func intPtr(i int) *int { return &i } func boolPtr(b bool) *bool { return &b } // Expected output: // Request JSON: // { // "text": { // "maxCharacters": 10000, // "includeHtmlTags": false // }, // "subpageTarget": ["pricing", "features", "documentation"], // "highlights": { // "numSentences": 3, // "highlightsPerUrl": 2 // } // } // // Simple text (bool): true // Detailed text (object): {"maxCharacters":10000,"includeHtmlTags":false} // Single target: "pricing" // Multiple targets: ["pricing","features","documentation"] ``` -------------------------------- ### Exa CLI - Custom Base URL Source: https://context7.com/lollipopkit/exa/llms.txt Demonstrates how to use a custom base URL for the Exa API, useful for testing or connecting to alternative endpoints. ```bash # Using custom base URL (for testing) exa search "test query" --base-url https://staging-api.exa.ai ``` -------------------------------- ### Exa Contents with Highlights and Summary Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Retrieve content along with its highlights and a summary by using the --highlights and --summary flags. This provides a more detailed view of the content. ```bash # Include highlights and summary exa contents https://example.com --highlights --summary ``` -------------------------------- ### Perform Search with Full Text Content Source: https://context7.com/lollipopkit/exa/llms.txt Use SearchAndContents for quick searches where you need the full text content of the results included. Ensure you have your Exa API key configured. ```go package main import ( "context" "fmt" "log" "github.com/lollipopkit/exa" ) func main() { client, _ := exa.NewClient("YOUR_EXA_API_KEY") ctx := context.Background() // Quick search with contents included resp, err := client.SearchAndContents(ctx, "golang best practices 2024") if err != nil { log.Fatalf("SearchAndContents failed: %v", err) } fmt.Printf("Request ID: %s\n", resp.RequestID) fmt.Printf("Search type: %s\n", resp.ResolvedSearchType) for i, result := range resp.Results { fmt.Printf("\n%d. %s\n", i+1, result.Title) fmt.Printf(" URL: %s\n", result.URL) if len(result.Text) > 300 { fmt.Printf(" Content: %s...\n", result.Text[:300]) } else { fmt.Printf(" Content: %s\n", result.Text) } } } ``` -------------------------------- ### Exa CLI - Find Similar Content Source: https://context7.com/lollipopkit/exa/llms.txt Finds content similar to a specified URL, with options to include specific domains, content, and limit the number of results. ```bash # Find similar content exa similar https://arxiv.org/abs/2301.07041 \ --include-domains arxiv.org \ --include-contents \ --num-results 10 ``` -------------------------------- ### Find Similar Content with Domain Filtering Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Illustrates how to find similar content while restricting the search to specific domains using the --include-domains flag. ```bash exa similar https://techcrunch.com/example-post --include-domains venturebeat.com,wired.com ``` -------------------------------- ### Perform Web Search with Exa Go SDK Source: https://context7.com/lollipopkit/exa/llms.txt Execute searches across the web using neural, fast, auto, or deep search modes. Supports filtering by domains, dates, and text content, with optional inline content retrieval. ```go package main import ( "context" "fmt" "log" "github.com/lollipopkit/exa" ) func main() { client, _ := exa.NewClient("YOUR_EXA_API_KEY") ctx := context.Background() // Basic search basicResp, err := client.Search(ctx, exa.SearchRequest{ Query: "Latest research in large language models", NumResults: 5, Type: exa.SearchTypeNeural, }) if err != nil { log.Fatalf("Search failed: %v", err) } fmt.Printf("Found %d results\n", len(basicResp.Results)) // Advanced search with domain filtering and content retrieval advancedResp, err := client.Search(ctx, exa.SearchRequest{ Query: "machine learning tutorials", NumResults: 10, Type: exa.SearchTypeDeep, IncludeDomains: []string{"arxiv.org", "github.com"}, ExcludeDomains: []string{"medium.com"}, StartPublishedDate: "2024-01-01", IncludeText: []string{"transformer", "attention"}, Contents: &exa.ContentsRequest{ Text: exa.BoolValue[exa.TextOptions](true), Highlights: &exa.HighlightsRequest{ NumSentences: exa.IntPtr(3), HighlightsPerURL: exa.IntPtr(2), }, Summary: &exa.SummaryRequest{}, }, }) if err != nil { log.Fatalf("Advanced search failed: %v", err) } for _, result := range advancedResp.Results { fmt.Printf("Title: %s\n", result.Title) fmt.Printf("URL: %s\n", result.URL) fmt.Printf("Published: %s\n", result.PublishedDate) if result.Text != "" { fmt.Printf("Content: %.200s...\n", result.Text) } if len(result.Highlights) > 0 { fmt.Printf("Highlights: %v\n", result.Highlights) } fmt.Println() } if advancedResp.CostDollars != nil { fmt.Printf("Total cost: $%.6f\n", advancedResp.CostDollars.Total) } } // Expected output: // Found 5 results // Title: Attention Is All You Need // URL: https://arxiv.org/abs/1706.03762 // Published: 2017-06-12 // Content: The dominant sequence transduction models are based on complex... // Highlights: [The Transformer relies entirely on self-attention...] ``` -------------------------------- ### Basic Search with Table Output Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Demonstrates a basic search query that defaults to a human-readable table output format. ```bash exa search "artificial intelligence ethics" ``` -------------------------------- ### Exa Similar Including Full Content Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Retrieve full content for similar items found by the 'exa similar' command by using the --include-contents flag. ```bash # Include full content exa similar https://example.com --include-contents ``` -------------------------------- ### Basic Exa Search Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Perform a basic search for content using a query string. This is the most straightforward way to find relevant information. ```bash # Basic search exa search "machine learning trends 2024" ``` -------------------------------- ### Retrieve Content for URLs Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Fetch the full content for one or more specified URLs using the 'exa contents' command. This retrieves the text from the given web addresses. ```bash # Get content for URLs exa contents https://example.com https://another-site.com ``` -------------------------------- ### Exa CLI - Search with Filters Source: https://context7.com/lollipopkit/exa/llms.txt Executes a search with advanced filters including search type, number of results, domain inclusion, content inclusion, and JSON output. ```bash # Search with filters and content exa search "golang tutorials" \ --search-type neural \ --num-results 5 \ --include-domains github.com,go.dev \ --include-contents \ --output json ``` -------------------------------- ### Find Similar Content to URL Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Discover content similar to a given URL using the 'exa similar' command. This helps in finding related articles or web pages. ```bash # Find similar content to a URL exa similar https://arxiv.org/abs/2301.07041 ``` -------------------------------- ### Fetch Content for Specific URLs Source: https://github.com/lollipopkit/exa/blob/main/README.md Retrieves content, specifically text, for a given list of URLs using the Exa client. This is useful for extracting information from web pages. ```go // Contents for specific URLs contents, _ := c.Contents(ctx, exa.ContentsRequestBody{ URLs: []string{"https://example.com"}, ContentsRequest: exa.ContentsRequest{Text: exa.BoolValue[exa.TextOptions](true)}, }) ``` -------------------------------- ### Exa Similar with Domain Filtering Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Refine similarity searches by including specific domains using the --include-domains flag. This focuses the search on particular websites. ```bash # Include domains in search exa similar https://example.com --include-domains techcrunch.com,venturebeat.com ``` -------------------------------- ### Find Similar Content by ID Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Locate content similar to a specific content ID using the 'exa similar' command. This requires a valid content ID as input. ```bash # Find similar content by ID exa similar content-id-here ``` -------------------------------- ### Retrieve Content by IDs Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Fetch content using specific item IDs with the 'exa contents --ids' command. Provide a comma-separated list of IDs to retrieve their associated content. ```bash # Get content by IDs exa contents --ids id1,id2,id3 ``` -------------------------------- ### Find Similar Links Source: https://github.com/lollipopkit/exa/blob/main/README.md Identifies and returns links that are similar to a provided URL. This can be used for content discovery and recommendation. ```go // Find similar links similar, _ := c.FindSimilar(ctx, exa.SimilarRequest{URL: "https://example.com"}) ``` -------------------------------- ### Find Similar Content to Text Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Identify content similar to a provided text query using the 'exa similar' command. This allows for similarity searches based on textual input. ```bash # Find similar content to text exa similar "quantum computing breakthroughs in 2024" ``` -------------------------------- ### Retrieve Web Page Contents by URL Source: https://context7.com/lollipopkit/exa/llms.txt Use the Contents method to fetch full content from specified URLs or Exa content IDs. This method supports text extraction, highlights, summaries, and live crawling. Configure options like MaxCharacters, IncludeHTMLTags, and Livecrawl behavior as needed. ```go package main import ( "context" "fmt" "log" "github.com/lollipopkit/exa" ) func main() { client, _ := exa.NewClient("YOUR_EXA_API_KEY") ctx := context.Background() // Retrieve contents for multiple URLs resp, err := client.Contents(ctx, exa.ContentsRequestBody{ URLs: []string{ "https://go.dev/doc/effective_go", "https://go.dev/blog/go1.21", }, ContentsRequest: exa.ContentsRequest{ Text: exa.ObjectValue(exa.TextOptions{ MaxCharacters: exa.IntPtr(5000), IncludeHTMLTags: exa.BoolPtr(false), }), Highlights: &exa.HighlightsRequest{ NumSentences: exa.IntPtr(5), HighlightsPerURL: exa.IntPtr(3), Query: "error handling", }, Summary: &exa.SummaryRequest{ Query: "Summarize the main points", }, Livecrawl: "fallback", }, }) if err != nil { log.Fatalf("Contents failed: %v", err) } fmt.Printf("Retrieved %d pages\n\n", len(resp.Results)) for _, result := range resp.Results { fmt.Printf("Title: %s\n", result.Title) fmt.Printf("URL: %s\n", result.URL) fmt.Printf("Summary: %s\n", result.Summary) fmt.Printf("Highlights: %v\n", result.Highlights) fmt.Printf("Text length: %d chars\n\n", len(result.Text)) } // Check for any failed content retrievals for _, status := range resp.Statuses { if status.Status != "success" { fmt.Printf("Failed to retrieve %s: %v\n", status.ID, status.Error) } } } ``` -------------------------------- ### Set Exa API Key Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Set your Exa API key as an environment variable. This is required for authentication before using Exa CLI commands. ```bash export EXA_API_KEY="your-api-key-here" ``` -------------------------------- ### Exa CLI - Set API Key Source: https://context7.com/lollipopkit/exa/llms.txt Command to set the Exa API key as an environment variable. This is required for all CLI operations. ```bash # Set API key export EXA_API_KEY="your-api-key-here" ``` -------------------------------- ### Exa Search with Specific Type Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Execute a search query using a specific search type, such as 'neural', for more targeted results. ```bash # With specific search type exa search "climate change" --search-type neural ``` -------------------------------- ### Exa Search with Domain Filtering Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Include or exclude specific domains from search results using the --include-domains and --exclude-domains flags. This helps refine searches to particular sources. ```bash # Include/exclude domains exa search "ai research" --include-domains arxiv.org,openai.com --exclude-domains spam.com ``` -------------------------------- ### Exa Search Output as JSON Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Output search results in JSON format using the --output json flag. This is ideal for programmatic use and data integration. ```bash # Output as JSON exa search "space exploration" --output json ``` -------------------------------- ### Exa Search Including Full Content Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Retrieve the full content of search results by using the --include-contents flag. This flag provides the complete text of the found documents. ```bash # Include full content exa search "blockchain technology" --include-contents ``` -------------------------------- ### Exa Answer Including Full Content Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Include full content in the results of an AI-generated answer by using the --include-contents flag. This provides more context for the answer. ```bash # Include full content in results exa answer "What is machine learning?" --include-contents ``` -------------------------------- ### Exa Search with Limited Results Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Limit the number of search results returned by specifying the --num-results flag. Useful for controlling output size. ```bash # Limit results exa search "golang tutorials" --num-results 5 ``` -------------------------------- ### Exa Answer with Limited Sources Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Limit the number of sources used for an AI-generated answer by specifying the --num-results flag. This controls the breadth of information considered. ```bash # Limit number of sources exa answer "Climate change impacts" --num-results 10 ``` -------------------------------- ### Exa Answer with Specific Search Type Source: https://github.com/lollipopkit/exa/blob/main/CLI.md Specify the search type for AI-generated answers using the --search-type flag. This allows for customization of the underlying search mechanism. ```bash # Specify search type exa answer "How does blockchain work?" --search-type neural ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.