{"id":23964509,"url":"https://github.com/rdhillbb/gotavilysearch","last_synced_at":"2025-07-09T14:34:16.587Z","repository":{"id":270326277,"uuid":"908520386","full_name":"rdhillbb/gotavilysearch","owner":"rdhillbb","description":"Tavily Search for using Antrhopics","archived":false,"fork":false,"pushed_at":"2025-01-04T14:40:02.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-24T13:28:38.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rdhillbb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-26T09:18:38.000Z","updated_at":"2025-01-04T14:40:06.000Z","dependencies_parsed_at":"2025-01-06T21:36:13.961Z","dependency_job_id":null,"html_url":"https://github.com/rdhillbb/gotavilysearch","commit_stats":null,"previous_names":["rdhillbb/gotavilysearch"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rdhillbb/gotavilysearch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Fgotavilysearch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Fgotavilysearch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Fgotavilysearch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Fgotavilysearch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdhillbb","download_url":"https://codeload.github.com/rdhillbb/gotavilysearch/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Fgotavilysearch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264476481,"owners_count":23614504,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-06T21:36:12.778Z","updated_at":"2025-07-09T14:34:16.553Z","avatar_url":"https://github.com/rdhillbb.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Function Documentation for Tavily Search Package\n\n## Overview\n\nThis package provides a concurrent search implementation using the Tavily API. It supports multiple search modes and uses Go's errgroup package for efficient concurrent execution.\n\n## Core Components\n\n### searchTavily.go Functions\n\n#### DeepSearch\n```go\nfunc DeepSearch(searchQuery string) (string, error)\n```\nPerforms an expanded search operation by breaking down the query into multiple sub-queries and aggregating results.\n\n**Parameters:**\n- `searchQuery` (string): The original search query to be expanded and searched\n\n**Returns:**\n- `string`: Combined search results from all sub-queries\n- `error`: Error if the search fails\n\n**Error cases:**\n- Empty query provided\n- Query expansion failure\n- All searches failed\n- No results found\n\n#### SearchInternet\n```go\nfunc SearchInternet(searchQuery string) (string, error)\n```\nPerforms a single search query against the Tavily API.\n\n**Parameters:**\n- `searchQuery` (string): The search query to execute\n\n**Returns:**\n- `string`: Search results in JSON format\n- `error`: Error if the search fails\n\n**Error cases:**\n- Empty query provided\n- Search execution failed\n- No results returned\n- Empty results returned\n\n#### SearchAtentInternet\n```go\nfunc SearchAtentInternet(searchQueries []string, searchFunc func(string, int) (string, error), envVar string)\n```\nManages concurrent execution of multiple search queries using errgroup.Group.\n\n**Parameters:**\n- `searchQueries` ([]string): Array of search queries to execute\n- `searchFunc` (func(string, int) (string, error)): Function to perform individual searches\n- `envVar` (string): Environment variable name for max results configuration\n\n**Returns:**\n- `[]SearchResult`: Array of search results with timing and error information\n\n**Concurrency Features:**\n- Uses errgroup.Group for goroutine management\n- Mutex-based synchronization for result collection\n- Context-based timeout (30 seconds)\n- Automatic cleanup and cancellation\n\n### tavilyclient.go Functions\n\n#### TavilySearch\n```go\nfunc TavilySearch(searchQuery string, maxResults int) (string, error)\n```\nPerforms a general internet search using the Tavily API.\n\n**Parameters:**\n- `searchQuery` (string): The search query to execute\n- `maxResults` (int): Maximum number of results to return\n\n**Returns:**\n- `string`: JSON-formatted search results\n- `error`: Error if the search fails\n\n**Configuration:**\n- Topic: General\n- IncludeAnswer: true\n- IncludeImages: false\n- IncludeRawContent: false\n\n#### TavilyMaxSearch\n```go\nfunc TavilyMaxSearch(searchQuery string) (string, error)\n```\nPerforms a deep search with advanced depth configuration.\n\n**Configuration:**\n- Topic: General\n- SearchDepth: advance\n- IncludeAnswer: true\n- IncludeRawContent: true\n- MaxResults: From MAXDeepRESULTS environment variable\n\n#### TavilyNewsSearch\n```go\nfunc TavilyNewsSearch(searchQuery string) (string, error)\n```\nPerforms a basic news search.\n\n**Configuration:**\n- Topic: News\n- SearchDepth: basic\n- IncludeAnswer: true\n- MaxResults: From MAXRESULTS environment variable\n\n#### TavilyRawNewsSearch\n```go\nfunc TavilyRawNewsSearch(searchQuery string) (string, error)\n```\nPerforms an advanced news search with expanded results.\n\n**Configuration:**\n- Topic: News\n- SearchDepth: advance\n- IncludeAnswer: true\n- MaxResults: From MAXDeepRESULTS environment variable\n- Days: 5\n\n#### API Key and Configuration Management\n```go\nfunc getAPIKey() string\nfunc getMaxResults(envVar string) int\n```\n\n**API Key Management:**\n1. Checks environment variable TAVILY_API_KEY\n2. Falls back to default API key if environment variable is not set\n\n**Max Results Configuration:**\n1. Reads from specified environment variable (MAXRESULTS or MAXDeepRESULTS)\n2. Falls back to default value of 3 if not set\n\n## Data Structures\n\n### SearchResult\n```go\ntype SearchResult struct {\n    Query      string        `json:\"query\"`\n    Results    string        `json:\"results\"`\n    WorkerID   int          `json:\"worker_id\"`\n    TimeSpent  time.Duration `json:\"time_spent\"`\n    Error      error        `json:\"error\"`\n}\n```\nStructure for holding search results and metadata.\n\n## Error Handling Patterns\n\n1. Input Validation\n```go\nif searchQuery == \"\" {\n    return \"\", fmt.Errorf(\"empty search query provided\")\n}\n```\n\n2. Error Wrapping\n```go\nif err != nil {\n    return \"\", fmt.Errorf(\"search failed: %v\", err)\n}\n```\n\n3. Concurrent Error Handling\n```go\nif err := g.Wait(); err != nil {\n    logging.WriteLogs(fmt.Sprintf(\"Search group error: %v\", err))\n}\n```\n\n## Logging\n\nThe package implements comprehensive logging throughout:\n- Search initialization and completion\n- Worker status updates and timing\n- Error conditions\n- API interactions\n\n## Dependencies\n\n- golang.org/x/sync/errgroup\n- github.com/hekmon/tavily\n- Internal packages:\n  - anthropicfunc/logging\n  - anthropicfunc/util\n\n## Configuration\n\n### Environment Variables\n- TAVILY_API_KEY: API key for Tavily service\n- MAXRESULTS: Maximum results for regular searches\n- MAXDeepRESULTS: Maximum results for deep searches\n\n### Default Settings\n- Default API key provided as fallback\n- Default max results: 3\n- Search timeout: 30 seconds\n- News search default days: 5\n\n### Concurrency Settings\n- Worker count matches query count\n- Mutex-protected result collection\n- Context-based timeout management\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdhillbb%2Fgotavilysearch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdhillbb%2Fgotavilysearch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdhillbb%2Fgotavilysearch/lists"}