This project sets up a Dockerized environment with a Python application and an SQL database to manage multiple-choice questions (MCQs) and their answers. The application also integrates with OpenAI's API to generate MCQs.
- Docker and Docker Compose installed on your machine.
- An OpenAI API key. You can get one from OpenAI.
docker_mcq_project_with_openai/
│
├── Dockerfile
├── docker-compose.yml
├── app.py
├── requirements.txt
└── README.md
- Dockerfile: Defines the Docker image for the Python application.
- docker-compose.yml: Configures Docker services, including the Python application and the MySQL database.
- app.py: The main Python application that handles MCQs and integrates with OpenAI.
- requirements.txt: Lists the Python dependencies for the project.
- README.md: This file.
-
Clone the repository:
git clone git@github.com:fahdi/docker-python-quiz-openai.git cd docker-python-quiz-openai
-
Replace
your_openai_api_key_here
indocker-compose.yml
with your actual OpenAI API key. -
Build and start the Docker containers:
docker-compose up --build
This command will build the Docker images and start the containers. Your application should be accessible at http://localhost:5000
.
You can add an MCQ manually by sending a POST request to the /add_mcq
endpoint with the following JSON payload:
{
"question": "What is the capital of France?",
"answer": "Paris"
}
You can generate an MCQ using OpenAI by sending a POST request to the /generate_mcq
endpoint with the following JSON payload:
{
"prompt": "Generate an MCQ about world geography."
}
You can retrieve all MCQs by sending a GET request to the /mcqs
endpoint.
- URL:
/add_mcq
- Method:
POST
- Request Payload:
{ "question": "Question text", "answer": "Answer text" }
- Response:
{ "message": "MCQ added successfully" }
- URL:
/generate_mcq
- Method:
POST
- Request Payload:
{ "prompt": "Prompt for generating MCQ" }
- Response:
{ "message": "MCQ generated and added successfully" }
- URL:
/mcqs
- Method:
GET
- Response:
[ { "id": 1, "question": "Question text", "answer": "Answer text" }, ... ]
This project is licensed under the MIT License. See the LICENSE file for more details.