Package: gpt-code-search
gpt-code-searchgpt-code-searchis a tool enabling you to search your codebase with natural language. It utilizes OpenAI's function calling to retrieve, search and answer queries about your code, boosting productivity and code understanding.Features🧠GPT-4: Code search, retrieval, and answering all done with OpenAI'sfunction calling.🔐Privacy-first: Code snippets only leave your machine when you ask a question and the LLM requests the relevant code.🔥Works instantly: No pre-processing, chunking, or indexing, get started right away.📦File-system backed: Works with any code on your machine.Getting StartedInstallationpipinstallgpt-code-searchUsageAsk a question about your codebaseTo query about the purpose of your codebase, you can use thequerycommand:gpt-code-searchquery"What does this codebase do?"# or use the shorthand aliasgcsquery"What does this codebase do?"If you want to generate a test for a specific file, for example analytics.py, you can mention the file name to improve accuracy:gcsquery"Can you generate a test for analytics.py?"For a general usage question about a certain module, like analytics, you can use keywords to search across the codebase:gcsquery"How do I use the analytics module?"Remember, mentioning the file name or specific keywords improves the accuracy of the search.Select a model to usegcsselect-modelDefaults togpt-3.5-turbo-16k. The selected model is stored in$HOME/.gpt-code-search/config.toml.ConfigurationThe tool will prompt you to configure theOPENAI_API_KEY, if you haven't already.ProblemYou want to leverage the power of GPT-4 to search your codebase, but you don't want to manually copy and paste code snippets into a prompt nor send your code to another third-party service (other than OpenAI).This tool solves these problems by letting GPT-4 determine the most relevant code snippets within your codebase. Also, it meets you where you already live, in your terminal, not a new UI or window.Examples of the types of questions you might want to ask:🐛 Help debugging errors and finding the relevant code and files📝 Document large files or functionalities formatted as markdown🛠️ Generate new code based on existing files and conventions📨 Ask general questions about any part of the codebaseHow it worksWe utilize OpenAI's function calling to let GPT-4 call certain predefined functions in our library. You do not need to implement any of these functions yourself. These functions are designed to interact with your codebase and return enough context for the LLM to perform code searches without pre-indexing it or uploading your repo to a third party other than OpenAI. So, you only need to run the tool from the directory you want to search.The functions currently available for the LLM to call are:search_codebase- searches the codebase using a TF-IDF vectorizerget_file_tree- provides the file tree of the codebaseget_file_contents- provides the contents of a fileThese functions are implemented ingpt-code-searchand are triggered by chat completions. The LLM is prompted to utilize the search_codebase and get_file_tree function as needed to find the necessary context to answer your query and then loops as needed to collect more context with the get_file_contents until the LLM responds.PrivacyThis tool prioritizes privacy. Outside of the LLM, no code is sent to us and is only used as context for the LLM. We do collect anonymous usage data to improve the tool, but you can opt out of this.LimitationsThis does have some limitations, namely:The LLM is unable to load context across multiple files at once. This means that if you ask a question that requires context from multiple files, you will need to ask multiple questions.Specify the file name and keywords in your question to improve accuracy. For example, if you want to ask a question aboutanalytics.py, mention the file name in your question.The level of search and retrieval is limited by the context window, which refers to the scope of the search conducted by the tool, meaning that we can only search 5 levels deep in the file system. So you need to run the tool from the folder/package closest to the code you want to search.These limitations lead to suboptimal results in a few cases, but we're working on improving this.We wanted to get this tool out there as soon as possible to get feedback and iterate on it!RoadmapUse vector embeddings to improve search and retrievalAdd support for generating code and saving it to a fileSupport for searching across multiple codebasesAllow the model to create new functions that it can then executeUseguidanceto improve promptsAdd support for additional models (Claude, Bedrock, etc)AnalyticsWe collect anonymous crash and usage data to help us improve the tool. This data aids in understanding usage patterns and improving the tool. You can opt out of analytics by running:gcsopt-out-of-analyticsYou can check the data that by looking at theanalyticsandconfigfiles.Here's an exhaustive list of the data we collect:- exception - stacktraces of crashes
- uuid - a unique identifier for the user
- model - the model used for the query
- usage - the type of usage (query_count, query_at, query_execution_time)Note: We do not collect any PII (ip-address), queries or code snippets.ContributingWe love contributions from the community! ❤️ If you'd like to contribute, feel free to fork the repository and submit a pull request.Please read ourCode of ConductandContributing Guidefor more detailed steps and information.Code of ConductWe are committed to fostering a welcoming community. To ensure that everyone feels safe and welcome, we have aCode of Conductthat all contributors, maintainers, and users of this project are expected to adhere to.SupportIf you're having trouble usinggpt-code-search, feel free toopen an issueon our GitHub. You can also reach out to us directly atnarenkmanoharan@gmail.com. We're always happy to help!FeedbackYour feedback is very important to us! If you have ideas for how we can improvegpt-code-search, we'd love to hear from you. Pleaseopen an issueor reach out to us directly atnarenkmanoharan@gmailwith your feedback or thoughts.LicenseThis project is licensed under the terms of theApache 2.0.