Note
Documentation auto-generated by ai-docs.
This code repository contains a Python-based AI-assisted Q&A system for analyzing and answering questions about a given code repository. The system utilizes the Langchain library for text processing and retrieval, OpenAI's language model for generating answers, and the Chroma vector store for efficient text retrieval.
The primary purpose of this project is to provide developers with an interactive tool to explore and understand a codebase by asking questions about its content, structure, and functionality. The AI assistant is designed to provide concise, technically accurate answers based on the information available in the repository.
The codebase consists of three main Python files:
extract_repo.py: This module is responsible for extracting relevant code files from a local directory and converting them into a single text file for further processing.qna.py: This module defines theAskBotclass, which handles the question-answering process using the Langchain library and OpenAI's language model.run.py: This module serves as the main entry point for the application, orchestrating the repository extraction, AI assistant initialization, and user interaction.
The project utilizes the Poetry dependency management tool to handle its dependencies, which are specified in the pyproject.toml file.
To set up the development environment, follow these steps:
- Install Python 3.9 or later.
- Install Poetry by following the instructions at https://python-poetry.org/docs/#installation.
- Clone the repository and navigate to the project directory.
- Run
poetry installto install the required dependencies. - Create a
.envfile in the project root and add your OpenAI API key asOPENAI_API_KEY=your_api_key_here.
The repository has the following structure:
ai-qna/
├── ai_qna/
│ ├── __init__.py
│ ├── extract_repo.py
│ ├── qna.py
│ └── run.py
├── .gitignore
├── poetry.lock
├── pyproject.toml
└── README.md
- The
ai_qnadirectory contains the main Python modules for the project. - The
pyproject.tomlfile specifies the project dependencies and build system. - The
poetry.lockfile is generated by Poetry and contains the exact versions of the installed dependencies. - The
.gitignorefile specifies files and directories that should be ignored by Git. - The
README.mdfile provides an overview of the project.
-
Text extraction and preprocessing:
- The
extract_repo.pymodule handles the extraction of relevant code files from a local directory, skipping unnecessary files and directories. - It applies various filters to determine if a file is likely to be useful based on its path, name, and content.
- The extracted files are combined into a single text file for further processing.
- The
-
AI-assisted question answering:
- The
qna.pymodule defines theAskBotclass, which utilizes the Langchain library and OpenAI's language model to generate answers based on the provided code repository. - It uses the Chroma vector store to efficiently retrieve relevant text chunks based on the input question.
- The
RetrievalQAchain from Langchain is used to combine the retrieved text chunks and generate a coherent answer.
- The
-
User interaction and error handling:
- The
run.pymodule provides an interactive command-line interface for users to ask questions about the code repository. - It handles user input validation, displays progress indicators, and formats the output for better readability.
- The module also handles common error scenarios, such as missing command-line arguments or invalid repository paths.
- The
To install and set up the project, follow these steps:
- Ensure that you have Python 3.9 or later installed on your system.
- Clone the repository to your local machine using
git clone https://github.com/yourusername/ai-qna.git. - Navigate to the project directory:
cd ai-qna. - Install the required dependencies using Poetry:
poetry install. - Create a
.envfile in the project root and add your OpenAI API key asOPENAI_API_KEY=your_api_key_here.
To start using the AI-assisted Q&A system, follow these steps:
- Prepare the code repository you want to analyze by ensuring it is available on your local machine.
- Open a terminal and navigate to the project directory.
- Run the following command, replacing
<local repository directory>with the path to your code repository:python ai_qna/run.py <local repository directory> - The AI assistant will process the repository and prepare the Q&A environment. Once ready, it will display a welcome message and prompt you to ask a question.
- Type your question about the code repository and press Enter. The AI assistant will analyze the repository and generate an answer based on the available information.
- Continue asking questions until you have the information you need. To exit the program, type "exit" and press Enter.
Remember that the AI assistant's knowledge is limited to the content of the provided code repository. If the information you're looking for is not available in the repository, the assistant will let you know.
