This repository contains a code snippet generator that utilizes the OpenAI API and interacts with a PostgreSQL database. Follow the instructions below to set up and run the application locally.
Features that are part of this code generation repository are:
- Web Interface for Code Generation
- Feedback Loop for Improvement
- Custom LLM Integration (Llama2 Locally Deployment using Ollama)
- Containerization of Flask Web App and PostgreSQL DB
- Prompt Security
- Snippet Management
- Snippet Testing System Using Exec
-
Create an
.envfile in the root directory of the project. -
Add the following configurations to the
.envfile:OPEN_AI_API=<Insert Your OpenAI API Key> DB_HOST="localhost" DB_PORT="5432" DB_USER="postgres" DB_PASSWORD="password" DB_DATABASE="code_snippet"
To install the Ollama library and run the Llama2 model locally, follow these steps:
-
Run the command below to download and install Ollama:
curl -fsSL https://ollama.com/install.sh | sh -
Once the installation is complete, run the Llama2 model using the command:
ollama run llama2
-
Verify that the model is deployed by testing it using the API endpoint:
curl http://localhost:11434/api/chat -d '{ "model": "mistral", "messages": [ { "role": "user", "content": "why is the sky blue?" } ] }'
To run a PostgreSQL container to connect to the database, execute the following commands:
```bash
sudo docker build -t my-postgres-image -f Dockerfile_postgres .
sudo docker run -d --name my-postgres-container --restart always -p 5432:5432 -v postgres:/var/lib/postgresql/data my-postgres-image
```
To run the code snippet container, use the following commands:
```bash
sudo docker build -t code-snippet -f Dockerfile_code .
sudo docker run -d -p 5001:5001 code-snippet
```
To run the application:
- Install the required dependencies using:
pip install -r requirements.txt
- Start the application by running:
python main.py
- Visit http://localhost:5001/ in your web browser.
- The application will start running. Select "GPT" to use the GPT model or "Custom LLM" to use a custom model.
