Cody is an AI programming assistant designed to let developers interactively query codebases in natural language. It uses vector embeddings, chunking, and OpenAI's language models to help users browse code efficiently and intuitively.
Main capabilities
- File monitoring: Monitors all files in the project directory and subdirectories in real time, automatically updating the knowledge base every time a file is saved.
- Embedding-based knowledge base: Uses OpenAI Embeddings to create a knowledge base, collecting the contents of all text and JSON files and adding them to the knowledge base.
- Interactive Q&A: Listens for user input; after the user asks a question, Cody uses the knowledge base to generate an answer.
- Customizable: You can use ignore_list to specify files or directories to ignore during monitoring.
Usage
- (Optional) In the terminal, from the project root directory run
pip install -m venv .venvto set up a virtual environment, then runpip install -r requirements.txt. - Rename the
.local.envfile to.env, and replaceYOUR_API_KEY_HEREwith your OpenAI API key. - Modify the
IGNORE_THESEglobal variable at the top of the script to specify directories and files to exclude from monitoring (large files should be commented out, such as virtual environments, caches, downloaded JS libraries, etc.). - Run the script with Python:
python cody.py, and follow the terminal prompts to set it up. It will ask whether you want to use text chat (terminal) or conversation (voice input/output). If you remove.envfrom the ignore list, it will also issue a warning. - To stop the script, type 'exit' or say 'exit' and press Enter, and Cody will gracefully terminate the program.
Configuring the ignore list
Cody allows you to specify files and directories that should be ignored during file monitoring, which is especially useful for excluding files that change frequently, are irrelevant to queries, or may contain sensitive information.
- Ignore specific files: add
*.envto the ignore list, for exampleIGNORE_THESE = ['*.env']. - Ignore directories: add the directory name, for example
IGNORE_THESE = ['node_modules', '.venv']. - Ignore file extensions: use wildcards, for example
IGNORE_THESE = ['*.log', '*.tmp']. - Complex patterns: combine directory names and wildcards, for example to ignore all .md files under the docs directory:
IGNORE_THESE = ['docs/*.md']. It is recommended to periodically review and update the ignore list, use wildcards cautiously, and test changes after updating.
Dependencies
- dotenv: Loads variables from a .env file into the environment.
- langchain-community: A language processing library for embeddings and vector storage.
- langchain_openai: Provides OpenAIEmbeddings functionality, integrating OpenAI models with the langchain architecture.
- litellm: Calls all LLM APIs using the OpenAI format.
- watchdog: Monitors file system events in real time.
- openai: Uses OpenAI language models to generate intelligent responses.
- speech_recognition: Converts speech to text for voice interaction.
- gtts: Google Text-to-Speech library, used to generate audio from text.
- pygame: A library for playing audio files.
Notes and Tips
- Cody uses the FAISS library to store vectors for efficient similarity search. Please ensure there is enough memory, especially when monitoring a large number of files.
- Please monitor OpenAI API usage. It is recommended to set a monthly spending limit in your OpenAI account to prevent unexpected situations. In addition, it will print the number of tokens used on each call.
- To fully realize the potential of "real-time" coding Q&A, it is recommended to open a separate terminal or command prompt, cd to the project directory, and then start
python cody.py. Then display it split-screen with the code, so you can use another terminal to actually run the code without worrying about Cody or having to run it every time. It will still continuously update every time a file is saved, always using the latest data.
Use Cases
Suitable for scenarios where developers need to quickly understand, navigate, or query a codebase, especially for getting answers to code-related questions in real time during coding.
Limitations
- Requires an OpenAI API key and may incur API usage costs.
- Requires sufficient memory, especially for large projects.
- Only supports content collection from text and JSON files.
- Voice interaction depends on libraries such as speech_recognition and gtts, and may be limited by the environment.
Contributions are welcome. Please submit a pull request or open an issue to report bugs or request features.