Loading repository dataβ¦
Loading repository dataβ¦
IbraheemGanayim / repository
π Flask App with OpenAI, PostgreSQL, Docker and Pytest π§ A containerized Flask API Backend Project, featuring OpenAI integration, PostgreSQL for data management and unit tests powered by Pytestβall orchestrated via Docker Compose. π―
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
Welcome to the Flask OpenAI Project repository! This project demonstrates a containerized Flask application that interacts with a PostgreSQL database, powered by Docker. It includes a simple question-answering API, database integration using SQLAlchemy and automated database migrations via Alembic. Unit tests are also implemented to ensure the robustness of the /ask API endpoint. πͺ
/ask endpoint that processes questions and responds with real answers powered by OpenAIβs API./ask API, ensuring code reliability.Hereβs an overview of the projectβs main files and directories:
π¦ flask-openai-assignment
βββ π migrations # Alembic migration files for database
βββ π Dockerfile # Docker configuration for the Flask app
βββ π docker-compose.yml # Docker Compose configuration to orchestrate containers
βββ π requirements.txt # Python dependencies
βββ π app.py # Main Flask application file
βββ π models.py # Database models for SQLAlchemy
βββ π app_test.py # Unit tests for the app
βββ π README.md # Project documentation
To get this project up and running on your local machine, follow the instructions below:
git clone https://github.com/IbraheemGanayim/flask-openai-assignment.git
cd flask-openai-assignment
.env file in the root directory and add the following:
OPENAI_API_KEY=your_openai_api_key_here
Ensure that Docker is installed and running on your machine, then run:
docker-compose up --build
This command will:
Once everything is up and running, the API will be accessible at:
Test the /ask endpoint by sending a POST request:
curl -X POST http://localhost:5000/ask -H "Content-Type: application/json" -d '{"question": "What is AI?"}'
To ensure everything works as expected, you can run unit tests inside the Flask container.
Enter the Flask container:
docker exec -it insait-flask-app /bin/sh
Run the tests:
pytest app_test.py
Alembic is used to handle database migrations. You can generate and apply new migrations with the following commands:
Create a new migration:
alembic revision --autogenerate -m "your migration message"
Apply the migration:
alembic upgrade head
This project follows a logical development workflow:
/ask endpoint./ask
{
"question": "What is AI?"
}
{
"question": "What is AI?",
"answer": "AI stands for Artificial Intelligence, which refers to..."
}
Feel free to reach out if you have any questions! π