https://github.com/deven367/deven-cleric-backend
repo for the cleric assessment
https://github.com/deven367/deven-cleric-backend
fastapi gpt-4
Last synced: about 1 month ago
JSON representation
repo for the cleric assessment
- Host: GitHub
- URL: https://github.com/deven367/deven-cleric-backend
- Owner: deven367
- Archived: true
- Created: 2024-04-20T13:42:41.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-21T22:44:22.000Z (about 2 years ago)
- Last Synced: 2025-06-25T21:06:58.184Z (about 1 year ago)
- Topics: fastapi, gpt-4
- Language: Python
- Homepage: https://deven-cleric-backend.onrender.com/
- Size: 25.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# deven-cleric-backend
For the backend, I have used `fastapi` and `pydantic` for data validation. The model working on the backend to give insights from the logs is GPT-4.
The OpenAI's API key is set as an environment variable in the configuration on the deployment.
## To run the backend locally
```sh
pip install -r requirement.txt
```
Once the requirements are installed, run the command
```sh
uvicorn api:app --reload
```
to run the app locally.
## Model choice
Upon some testing, I found GPT-3.5 Turbo also working reliably. However, I went GPT-4 for a safer measure. GPT-4 takes slightly longer than GPT-3.5 for receiving the response, but the quality of the reponse is better than GPT-3.5.
## Code organization and approach
The code is organized in the following way:
```md
|- api.py # FastAPI app
|- ask_gp4.py # GPT-4 model
|- responses.py # Pydantic Response model
|- requirements.txt # Requirements
```
1. The `api.py` file contains the FastAPI app, which has two endpoints `/submit_question_and_documents` which takes a `POST` request with a JSON body containing the `question` key and urls of logs.
2. The `POST` request is validated using Pydantic models. The logs are fetched from the URLs by sending a `GET` request and the question and logs are sent to the GPT-4 model.
1. All the logs are concatenated and sent to the GPT-4 model, so that has the entire context for generating the response.
2. Once the logs are concatenated, the processed payload is written to a file.
3. The `GET` endpoint then reads the file, checks if the logs were fetched correctly, and if not, it returns an error. Else, it sends the payload to the GPT-4 model.
3. The `ask_gp4.py` file pings the GPT-4 endpoint, which is used to generate the response.
4. The `responses.py` file contains the Pydantic Response model, which is used to validate the response from the GPT-4 model.