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.
pip install -r requirement.txt
Once the requirements are installed, run the command
uvicorn api:app --reload
to run the app locally.
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.
The code is organized in the following way:
|- api.py # FastAPI app
|- ask_gp4.py # GPT-4 model
|- responses.py # Pydantic Response model
|- requirements.txt # Requirements
- The
api.py
file contains the FastAPI app, which has two endpoints/submit_question_and_documents
which takes aPOST
request with a JSON body containing thequestion
key and urls of logs. - The
POST
request is validated using Pydantic models. The logs are fetched from the URLs by sending aGET
request and the question and logs are sent to the GPT-4 model.- All the logs are concatenated and sent to the GPT-4 model, so that has the entire context for generating the response.
- Once the logs are concatenated, the processed payload is written to a file.
- 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.
- The
ask_gp4.py
file pings the GPT-4 endpoint, which is used to generate the response. - The
responses.py
file contains the Pydantic Response model, which is used to validate the response from the GPT-4 model.