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)


-------------------------------------------------------------------------
'''