From adb5270b73753ce920f458d577b008d61fb414f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Sat, 5 Oct 2024 10:03:21 -0300 Subject: [PATCH] feat (fastapi): new fastapi example --- service/ai/correlation/claude.md | 9 +++++++++ service/ai/{ => prediction}/claude.md | 14 +++++--------- service/basic/README.md | 19 +++++++++++++++++++ service/basic/fastapi/main.py | 11 +++++++++++ 4 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 service/ai/correlation/claude.md rename service/ai/{ => prediction}/claude.md (63%) create mode 100644 service/basic/README.md create mode 100644 service/basic/fastapi/main.py diff --git a/service/ai/correlation/claude.md b/service/ai/correlation/claude.md new file mode 100644 index 00000000..fb467149 --- /dev/null +++ b/service/ai/correlation/claude.md @@ -0,0 +1,9 @@ +# Conversas com Claude.ai - Componentization + +## Solicitando um Serviço de Correlação + +Given a file "intake-person-demo(age).csv" with the following file fields: age, gender, ethnicity, and fcid_code. Create a FastAPI service that has the following endpoint: + +GET /correlation + +This service receives the fcid_code of a food product. It returns the correlation between the age and intake_bw of the food product. The data to calculate the correlation comes from the csv file. \ No newline at end of file diff --git a/service/ai/claude.md b/service/ai/prediction/claude.md similarity index 63% rename from service/ai/claude.md rename to service/ai/prediction/claude.md index f0dd1041..ad28ef21 100644 --- a/service/ai/claude.md +++ b/service/ai/prediction/claude.md @@ -1,24 +1,20 @@ -Given a file "intake-person-demo(age).csv" with the following file fields: age, gender, ethnicity, and fcid_code. Create a FastAPI service that has the following endpoint: +# Conversas com Claude.ai - Componentization -GET /correlation - -This service receives the fcid_code of a food product. It returns the correlation between the age and intake_bw of the food product. The data to calculate the correlation comes from the csv file. - ------ +## Passo 2 - Transformando Workflow em Componente Given a . Create a python class to execute logistic regression predictions with two operations: * train: Receives the csv file path file with the following file fields: age, gender, ethnicity, and fcid_code. Trains a logistic regression model to predict the fcid_code given age, gender, and ethnicity. * predict: Receives three parameters (age, gender, and ethnicity) and predicts the fcid_code with the logistic regression model. ------ +### Exemplo de uso Can you give me a example of code using this class to do predictions with the following parameters: * train: file path = "intake-person-demo(beans).csv" * predict: age=31; gender=1; ethnicity=2 ------ +## Passo 3 - Componente para Serviço Can you transform this code into a FastAPI service with two endpoints: * POST /train -* GET /predict \ No newline at end of file +* GET /predict diff --git a/service/basic/README.md b/service/basic/README.md new file mode 100644 index 00000000..aa1c1818 --- /dev/null +++ b/service/basic/README.md @@ -0,0 +1,19 @@ +# FastAPI +https://fastapi.tiangolo.com/ + +# Installing + +This statement forces a specific version of FastAPI installation when the default is not the latest. + +~~~ +pip3 install "fastapi[standard]"==0.112.0 +~~~ + +# Simple Example + +Examples derived from the tutorial: +https://fastapi.tiangolo.com/ + +~~~ +fastapi dev main.py +~~~ \ No newline at end of file diff --git a/service/basic/fastapi/main.py b/service/basic/fastapi/main.py new file mode 100644 index 00000000..8d984746 --- /dev/null +++ b/service/basic/fastapi/main.py @@ -0,0 +1,11 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def read_root(): + return {"Hello": "World"} + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: str | None = None): + return {"item_id": item_id, "q": q}