Skip to content
ryanthomas8Public

About

Relational Database Query with LLM

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Postgres SQLAlchemy

Envrionment Set up

source scripts/venv-init.sh

Run

Docker Compose

Run the following docker compose command to start the services

docker compose up

Then run the following script to load test data into the postgres db

python scripts/load_sample_data.py

Run the following script to pull the gemma2 model in the Ollama docker container

docker exec -it ollama ollama pull gemma2

To stop, press crtl+c in the terminal and run the following commmand to stop the docker containers

docker compose down

Local

Run the following command to start the application;

bash start.sh
  • Activate the virtual environment
  • Run the PostgreSQL Docker container
  • Run Alembic migrations
  • Load sample data into the database
  • Run the Ollama Docker container
  • Pull the gemma2 model
  • Start the FastAPI app

To stop, press crtl+c in the terminal and run the following commmand to stop the docker containers

docker stop ollama some-postgres

Testing

CURL

Enter the following in your terminal:

Request:

curl -X 'POST' \
  'http://127.0.0.1:8000/ask' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "question": "What employees work on the AI Research project?"
}'

Response:

{
  "question": "What employees work on the AI Research project?",
  "sql_query": "SELECT \"employee\".\"name\"\nFROM employee_projects\nJOIN employee ON employee_projects.\"employee_id\" = employee.id\nWHERE employee_projects.\"project_id\" = 1;",
  "query_result": "\"[('John Doe',), ('Alice Brown',)]\"",
  "final_answer": "John Doe and Alice Brown work on the AI Research project.  \n"
}

SWAGGER

Visit the following FastAPI Swagger page to test the API endpoint: http://127.0.0.1:8000/docs

Enter in the following payload for the /ask POST endpoint

{
  "question": "What employees work on the AI Research project?"
}

Links

Other:

Quickly query postgress database:

docker exec -it some-postgres psql -U postgres

Python formatting:

pip install -r requirements-dev.txt
black . 

About

Relational Database Query with LLM

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages