Skip to content

Commit

Permalink
feat (fastapi): new fastapi example
Browse files Browse the repository at this point in the history
  • Loading branch information
santanche committed Oct 5, 2024
1 parent 2bf0ed2 commit adb5270
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
9 changes: 9 additions & 0 deletions service/ai/correlation/claude.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 5 additions & 9 deletions service/ai/claude.md → service/ai/prediction/claude.md
Original file line number Diff line number Diff line change
@@ -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
* GET /predict
19 changes: 19 additions & 0 deletions service/basic/README.md
Original file line number Diff line number Diff line change
@@ -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
~~~
11 changes: 11 additions & 0 deletions service/basic/fastapi/main.py
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit adb5270

Please sign in to comment.