Spaces:
Sleeping
Sleeping
| 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) | |
| ------------------------------------------------------------------------- | |
| ''' |