Skip to content

OpenAI powered chatbot that answers University of Lleida Q&A

License

Notifications You must be signed in to change notification settings

marcmelis/secretariadigital

Repository files navigation

Secretaria Digital API

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.

Installation

  1. Clone the repository:
git clone https://github.com/marcmelis/secretariadigital.git
  1. Change into the project directory:
cd secretariadigital
  1. Install the required dependencies:
pip install -r requirements.txt
  1. 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.

Usage

  1. Run the Flask server:
python app.py
  1. 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.

Deployment to Heroku

  1. Install the Heroku CLI.

  2. Log in to your Heroku account:

heroku login
  1. Create a new Heroku app:
heroku create your-app-name

Replace your-app-name with a unique name for your app.

  1. 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.

  1. Deploy your code to Heroku:
git push heroku main
  1. Your API is now available at https://your-app-name.herokuapp.com. You can make a POST request to the /answer_query endpoint using curl:
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.

Generate Embeddings

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:

  1. 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.

  2. 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.

License

This project is licensed under the MIT License. See LICENSE for details.

About

OpenAI powered chatbot that answers University of Lleida Q&A

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published