repobeginner
Show HN: Open-source code search with OpenAI's function calling
By narenkmanohackernews
View original on hackernewsgpt-code-search is an open-source tool that enables natural language code search across any codebase using OpenAI's GPT-4 and function calling. It runs locally without requiring code indexing or repository uploads, offering functions like search_codebase, get_file_tree, and get_file_contents to help the LLM retrieve and analyze code context.
Key Points
- •Install gpt-code-search via pip and set OPENAI_API_KEY environment variable to enable natural language code search on local codebases
- •Leverage OpenAI's function calling with GPT-4 to enable the LLM to call predefined functions (search_codebase, get_file_tree, get_file_contents) without requiring pre-indexing or third-party repo uploads
- •Use TF-IDF vectorizer for codebase searching and file tree navigation to gather context needed to answer code-related queries
- •LLM iteratively calls get_file_contents across multiple files to build sufficient context, which increases latency and API costs due to single-file-per-call limitations
- •Run the tool from the package/directory closest to target code since search is limited to five filesystem levels deep by context window constraints
- •Current approach trades off multi-file context loading for privacy and local execution—only OpenAI receives code data, not external indexing services
- •Planned improvements include local vector embeddings integration to reduce latency/cost and support for additional models, CLI chat interactions, and code generation
- •Tool is early-stage (built in one week) and actively seeking community feedback to refine search quality and functionality
Found this useful? Add it to a playbook for a step-by-step implementation guide.
Workflow Diagram
Start Process
Step A
Step B
Step C
Complete
Concepts
Artifacts (1)
gpt-code-search installation and usagebashcommand
pip install gpt-code-search
export OPENAI_API_KEY=<your-api-key>
gpt-code-search query "How do I use the analytics module?"
gpt-code-search query "Document all the API routes related to authentication."