This is a Flask API that uses OpenAI's GPT model with a context fine tune to answer queries based on a set of documents. Users can send questions to the /answer_query
endpoint, and the API will return an answer based on the precomputed embeddings of the documents.
- Clone the repository:
git clone https://github.com/marcmelis/secretariadigital.git
- Change into the project directory:
cd secretariadigital
- Install the required dependencies:
pip install -r requirements.txt
- Set up your API key as an environment variable:
export API_KEY="your_openai_api_key"
Replace your_openai_api_key
with your actual OpenAI API key.
- Run the Flask server:
python app.py
- Make a POST request to the
/answer_query
endpoint:
curl -X POST -H "Content-Type: application/json" -d '{"user_message":"Your question here"}' http://localhost:5000/answer_query
Replace "Your question here"
with your actual question.
-
Install the Heroku CLI.
-
Log in to your Heroku account:
heroku login
- Create a new Heroku app:
heroku create your-app-name
Replace your-app-name
with a unique name for your app.
- Add your OpenAI API key to the Heroku app's environment variables:
heroku config:set API_KEY="your_openai_api_key"
Replace your_openai_api_key
with your actual OpenAI API key.
- Deploy your code to Heroku:
git push heroku main
- Your API is now available at
https://your-app-name.herokuapp.com
. You can make a POST request to the/answer_query
endpoint usingcurl
:
curl -X POST -H "Content-Type: application/json" -d '{"user_message":"Your question here"}' https://your-app-name.herokuapp.com/answer_query
Replace "Your question here"
with your actual question.
The script generate_embeddings.py
is used to generate embeddings for the document sections. These embeddings are used by the Assistant API to answer queries more efficiently.
To generate embeddings for your documents, follow these steps:
-
Make sure you have set up your API key as an environment variable or in the
config.py
file, as described in the Installation section. -
Run the
generate_embeddings.py
script:
python generate_embeddings.py
This script reads the input text from a .csv file, generates embeddings for each section, and writes the embeddings to another .csv file. If the embeddings file already exists, the script will only generate embeddings for new sections added to the input .csv file, without overwriting the existing embeddings.
The script will output the number of new embeddings generated and the total number of embeddings after the update.
Example output:
Writing 750 new embeddings. Current embeddings: 1000
This indicates that 750 new embeddings were generated, and the total number of embeddings is now 1000.
This project is licensed under the MIT License. See LICENSE for details.