This project provides a system for embedding source code files and generating responses to user queries using relevant code sections through the OpenAI API.
emb_save.py: Script for embedding and saving source code filesemb_ask.py: Script for finding relevant code based on user queries and generating responses via OpenAI APIemb_web.py: Web application for interacting with the embedded code and generating responses
- Ensure Python 3.x is installed.
- Install required libraries:
pip install flask requests numpy nltk - Obtain an OpenAI API key from the OpenAI website.
- Open
emb_save.pyand modify the following settings:
API_KEY: Enter your OpenAI API key.FOLDER_PATH: Specify the path to the folder containing source code files to be embedded.EXTENSIONS: Modify the file extensions to be processed as needed.
- Run the script:
python emb_save.py - Upon completion, an
embeddings.jsonlfile will be generated.
-
Open
emb_ask.pyand setAPI_KEYto your OpenAI API key. -
Run the script:
python emb_ask.py -
Enter your question at the user_input.
-
The generated response will be saved in a
response.mdfile.
-
Open
emb_web.pyand setAPI_KEYto your OpenAI API key. -
Ensure that the
.jsonlfiles containing the embeddings are in the same directory asemb_web.py. -
Run the web application:
python emb_web.py -
Open a web browser and navigate to
http://localhost:5000. -
Select the
.jsonlfiles you want to use for the query. -
Enter your question and submit.
-
The application will display the selected files, your question, and the generated answer.
- Securely manage your API key. Do not upload it to public repositories.
- Be mindful of API usage and associated costs.
- Processing large codebases may take considerable time.
- The web application (
emb_web.py) is set to run in debug mode. For production use, disable debug mode and use a production-ready WSGI server.
This project is provided under the MIT License.
We welcome all contributions, including bug reports, feature suggestions, and pull requests.