Skip to content

Commit

Permalink
Update: main.py to include test endpoint for external API integration
Browse files Browse the repository at this point in the history
  • Loading branch information
JoseFredes committed Aug 24, 2024
1 parent c67e865 commit bcacc4f
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from fastapi import FastAPI
from typing import Union

import httpx
from openAI.client import OpenAIClient
from rules.rules import CLOSE_HAND, OPEN_HAND, PINCH_GRIP
import requests

app = FastAPI()

Expand Down Expand Up @@ -43,11 +44,32 @@ def read_root():
return {"response": rule}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}

@app.post("/train-data")
@app.get("/test")
def train_data(data: dict):
return {"data": data}
url = "http://10.67.10.73:8080/data"
headers = {
"Content-Type": "application/json",
}
data = [
{"engine": "upper_thumb", "value": 1},
{"engine": "lower_thumb", "value": 0.8},
{"engine": "index_finger", "value": 0.50},
{"engine": "middle_finger", "value": 0},
{"engine": "ring_finger", "value": 0},
{"engine": "pinky_finger", "value": 0},
]

# Convertir la lista de diccionarios en una cadena JSON
engine_status_list_json = {"engine_status_list_json": data}

# Incluirla en los parámetros de la consulta en la URL
# params = {
# "engine_status_list": engine_status_list_json
# }

response = requests.post(url, headers=headers, data=engine_status_list_json)
# response = httpx.post(url, headers=headers, data=engine_status_list_json)
return {"external_response": response.json()}


0 comments on commit bcacc4f

Please sign in to comment.