Spaces:
Sleeping
Sleeping
File size: 1,560 Bytes
5fc69e4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
import httpx
from typing import Any, Dict
from config import HF_SERVE_URL, HF_TIMEOUT
async def _post(endpoint: str, payload: Dict[str, Any]) -> Dict[str, Any]:
"""
Hugging Face Spaces์ POST ์์ฒญ์ ๋ณด๋ด๋ ๋ด๋ถ ํจ์.
endpoint๋ '/predict_main' ๊ฐ์ ์๋ ๊ฒฝ๋ก.
"""
url = f"{HF_SERVE_URL.rstrip('/')}{endpoint}"
async with httpx.AsyncClient(timeout=HF_TIMEOUT) as client:
response = await client.post(url, json=payload)
response.raise_for_status()
return response.json()
async def call_main(payload: Dict[str, Any]) -> Dict[str, Any]:
"""
๋ฉ์ธ ๋ชจ๋ธ ์ถ๋ก ํธ์ถ ํจ์.
"""
return await _post("/predict_main", payload)
'''
----------- ์๋ ๋ด์ฉ์ ai-server๋ด๋ถ์ ์ผ๋ก ๊ตฌํ [์ถํ ์์ ๊ฐ๋ฅ]--------------
async def call_preprocess(payload: Dict[str, Any]) -> Dict[str, Any]:
return await _post("/predict_preprocess", payload)
async def call_postprocess(payload: Dict[str, Any]) -> Dict[str, Any]:
return await _post("/predict_postprocess", payload)
async def call_rag(payload: Dict[str, Any]) -> Dict[str, Any]:
"""
RAG ๊ธฐ๋ฐ ์ถ๋ก ํธ์ถ ํจ์ (์: ๋ฌธ์ ๊ฒ์ + ์์ฑ).
"""
return await _post("/hf-serve/predict_rag", payload)
async def call_adapter_test(payload: Dict[str, Any]) -> Dict[str, Any]:
"""
Adapter ํ
์คํธ์ฉ ์๋ํฌ์ธํธ ํธ์ถ ํจ์.
"""
return await _post("/hf-serve/test_adapter", payload)
-------------------------------------------------------------------------
''' |