{"id":23697982,"url":"https://github.com/rdhillbb/util","last_synced_at":"2026-05-01T00:31:47.166Z","repository":{"id":269292865,"uuid":"906973210","full_name":"rdhillbb/util","owner":"rdhillbb","description":"Anthropic/Openai Utilities","archived":false,"fork":false,"pushed_at":"2024-12-26T11:05:07.000Z","size":7,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-29T17:20:16.344Z","etag":null,"topics":["anthropic","anthropic-claude","openai","promp","query","queryrewrite","rewrite"],"latest_commit_sha":null,"homepage":"","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,"zenodo":null}},"created_at":"2024-12-22T13:13:59.000Z","updated_at":"2024-12-26T11:05:45.000Z","dependencies_parsed_at":"2025-05-22T16:41:28.190Z","dependency_job_id":null,"html_url":"https://github.com/rdhillbb/util","commit_stats":null,"previous_names":["rdhillbb/util"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rdhillbb/util","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Futil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Futil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Futil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Futil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rdhillbb","download_url":"https://codeload.github.com/rdhillbb/util/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rdhillbb%2Futil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32481553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"ssl_error","status_checked_at":"2026-04-30T13:12:06.837Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["anthropic","anthropic-claude","openai","promp","query","queryrewrite","rewrite"],"created_at":"2024-12-30T07:12:26.833Z","updated_at":"2026-05-01T00:31:47.139Z","avatar_url":"https://github.com/rdhillbb.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Query Rewrite System\n\nThis system provides functionality to enhance and rewrite search queries using the Anthropic Claude API. It generates multiple variations of an input query while maintaining the original intent and adding contextual depth.\n\n## Overview\n\nThe Query Rewrite System consists of two main components:\n- A message template file (`messagefile.xml.txt`) containing the prompt structure\n- A Go implementation (`util.go`) that handles the query rewriting logic\n\n## Message File Structure\n\nThe system uses an XML-based message file that contains templates for different operations. The primary template used is the `query_rewrite` template under `utilmessages`. This template provides instructions to Claude for generating query variations.\n\n### Template Variables\nThe query rewrite template accepts two parameters:\n- `%d`: Number of query rewrites to generate\n- `%s`: Original query to be enhanced\n\n## Environment Variables\n\nThe following environment variables must be configured:\n\n| Variable | Description | Default |\n|----------|-------------|---------|\n| `ANTHROPIC_API_KEY` | API key for Anthropic Claude service | Required |\n| `REWRITENUM` | Number of query rewrites to generate | 3 |\n\n## Core Functions\n\n### `ReWriteQR(query string) ([]string, error)`\nMain function that processes a query and returns an array of rewritten queries.\n\n### `buildPrompt(query string) string`\nConstructs the prompt using the message template and query parameters.\n\n### `makeAnthropicRequest(prompt, apiKey string) (*http.Response, error)`\nHandles the API communication with Anthropic's Claude service.\n\n### `processResponse(resp *http.Response) ([]string, error)`\nProcesses the API response and extracts the rewritten queries.\n\n## Query Rewrite Guidelines\n\nThe system generates variations that include:\n- Broader context queries\n- More specific/detailed queries\n- Alternative phrasings\n- Related subtopics\n- Different perspectives\n\nEach rewritten query:\n- Maintains the original intent\n- Uses natural language\n- Avoids redundancy\n- Includes relevant context\n- Varies in complexity\n- Must not exceed 200 characters\n\n## Example Usage\n\n```go\nfunc main() {\n    results, err := ReWriteQR(\"what are the health benefits of garlic\")\n    if err != nil {\n        fmt.Printf(\"Error: %v\\n\", err)\n        return\n    }\n\n    for i, result := range results {\n        fmt.Printf(\"%d: %s\\n\", i+1, result)\n    }\n}\n```\n\n## API Configuration\n\nThe system uses the Claude 3 Sonnet model (`claude-3-sonnet-20240229`) with the following settings:\n- Max tokens: 1000\n- API Version: 2023-06-01\n\n## Dependencies\n\n- github.com/rdhillbb/messagefile\n- github.com/joho/godotenv\n\n## Error Handling\n\nThe system includes comprehensive error handling for:\n- Missing environment variables\n- API communication issues\n- Response parsing errors\n- Invalid JSON formatting\n- Empty results\n\n## Installation\n\n1. Clone the repository\n2. Create a `.env` file with required environment variables\n3. Install dependencies: `go get`\n4. Build: `go build`\n\n## Contributing\n\nWhen contributing to this project, please ensure that:\n- All new message templates are added to the XML file\n- Environment variables are documented\n- Error handling follows the established pattern\n- Tests are included for new functionality\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdhillbb%2Futil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frdhillbb%2Futil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frdhillbb%2Futil/lists"}