2024-09-25 17:59:02 +09:00
|
|
|
from schemas.train_report_data import ReportData
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
import os, httpx
|
|
|
|
|
|
|
|
|
2024-09-25 23:51:19 +09:00
|
|
|
def send_data_call_api(project_id:int, model_id:int, data:ReportData, token):
|
2024-09-25 17:59:02 +09:00
|
|
|
try:
|
|
|
|
load_dotenv()
|
|
|
|
# main.py와 같은 디렉토리에 .env 파일 생성해서 따옴표 없이 입력
|
|
|
|
# API_BASE_URL = {url}
|
|
|
|
# API_KEY = {key}
|
|
|
|
base_url = os.getenv("API_BASE_URL")
|
|
|
|
headers = {
|
|
|
|
"Content-Type": "application/json"
|
|
|
|
}
|
|
|
|
if token:
|
|
|
|
headers["Authorization"] = f"Bearer {token}"
|
|
|
|
|
|
|
|
response = httpx.request(
|
|
|
|
method="POST",
|
|
|
|
url=base_url+f"/api/projects/{project_id}/reports/models/{model_id}",
|
|
|
|
json=data.model_dump(),
|
|
|
|
headers=headers
|
|
|
|
)
|
|
|
|
# status에 따라 예외 발생
|
|
|
|
response.raise_for_status()
|
|
|
|
except Exception as e:
|
|
|
|
print("report data failed: "+str(e))
|