https://github.com/liemtv96/FastAPI-Kafka-MongoDB-OpenAI
Create a scalable FastAPI application that serves an endpoint to recommend things to do in a given country during a specific season by consulting the OpenAI API, store the results in MongoDB.
https://github.com/liemtv96/FastAPI-Kafka-MongoDB-OpenAI
docker docker-compose fastapi kafka mongodb openai python3
Last synced: 6 days ago
JSON representation
Create a scalable FastAPI application that serves an endpoint to recommend things to do in a given country during a specific season by consulting the OpenAI API, store the results in MongoDB.
- Host: GitHub
- URL: https://github.com/liemtv96/FastAPI-Kafka-MongoDB-OpenAI
- Owner: riottecboi
- Created: 2024-06-01T09:12:26.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-12T05:59:21.000Z (about 2 years ago)
- Last Synced: 2025-01-04T11:29:24.393Z (over 1 year ago)
- Topics: docker, docker-compose, fastapi, kafka, mongodb, openai, python3
- Language: Python
- Homepage:
- Size: 22.2 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FastAPI-Kafka-MongoDB-OpenAI
Create a scalable FastAPI application that serves an endpoint to recommend three things to do in a given country during a specific season by consulting the OpenAI API.
Additionally, integrate a distributed component for background processing to handle the OpenAI API calls asynchronously, store the results in MongoDB, and signal completion.

## Installation & Usage
This project running on Python 3.11, so please be sure that you are install Python 3.11 on your machine
````bash
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.11
`````
Use the package manager [pip](https://pip.pypa.io/en/stable/)
````bash
sudo apt-get install python3-pip
`````
````bash
python3.11 -m pip install virtualenv
python3.11 -m venv
`````
activate the virtual environment
````bash
source /bin/activate
`````
to install packages.
```bash
python3.11 -m pip install -r requirements.txt
```
To run this project, you will need to add the following environment variables to your `app/core/config.py` or `app/core/settings.cfg` file
- `KAFKA_BOOTSTRAP_SERVERS`
- `KAFKA_TOPIC`
- `MONGODB_URI`
- `MONGODB_DATABASE`
- `OPENAI_KEY`
Running a script
```bash
# Run a uvicorn service to serve FastAPI
uvicorn main:app --host 0.0.0.0 --port 3000
# Run a background worker
python3.11 background-worker.py
```
## Docker

In the project, I have declared [docker compose](https://docs.docker.com/compose/install/linux/#install-using-the-repository) file to create Kafka Zookeeper/Kafka/MongoDB services
````bash
docker-compose -f docker-compose.yml up -d
```````
when all the containers are up, we need to check for the network name which being used to run with those services
````bash
docker network ls
```````
```bash
docker build -f docker/Dockerfile -t .
docker run --name fastapi-app --network -p 3000:8000 -d
```
Now, the FastAPI run on port 3000 at your machine
