fix bug LLM
Browse files- app/llm.py +16 -12
app/llm.py
CHANGED
|
@@ -222,21 +222,25 @@ class LLMClient:
|
|
| 222 |
"""Generate text với HFS provider."""
|
| 223 |
endpoint = f"{self.base_url}/purechat"
|
| 224 |
payload = {"prompt": prompt}
|
| 225 |
-
logger.info(f"[LLM]
|
|
|
|
| 226 |
headers = {}
|
| 227 |
if self.api_key:
|
| 228 |
headers["Authorization"] = f"Bearer {self.api_key}"
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
@timing_decorator_async
|
| 242 |
async def chat(
|
|
|
|
| 222 |
"""Generate text với HFS provider."""
|
| 223 |
endpoint = f"{self.base_url}/purechat"
|
| 224 |
payload = {"prompt": prompt}
|
| 225 |
+
logger.info(f"[LLM][FLOW] Chuẩn bị gửi request tới HFS endpoint: {endpoint}")
|
| 226 |
+
logger.info(f"[LLM][FLOW] Payload gửi đi: {payload}")
|
| 227 |
headers = {}
|
| 228 |
if self.api_key:
|
| 229 |
headers["Authorization"] = f"Bearer {self.api_key}"
|
| 230 |
+
try:
|
| 231 |
+
response = await self._client.post(endpoint, headers=headers, json=payload)
|
| 232 |
+
logger.info(f"[LLM][FLOW] Đã nhận response từ HFS, status: {response.status_code}")
|
| 233 |
+
response.raise_for_status()
|
| 234 |
+
data = response.json()
|
| 235 |
+
logger.info(f"[LLM][FLOW] Response data: {data}")
|
| 236 |
+
if 'result' in data:
|
| 237 |
+
return data['result']
|
| 238 |
+
elif 'data' in data and isinstance(data['data'], list):
|
| 239 |
+
return data['data'][0]
|
| 240 |
+
return str(data)
|
| 241 |
+
except Exception as e:
|
| 242 |
+
logger.error(f"[LLM][FLOW][ERROR] Lỗi khi gọi HFS endpoint: {endpoint} | Exception: {e}")
|
| 243 |
+
raise
|
| 244 |
|
| 245 |
@timing_decorator_async
|
| 246 |
async def chat(
|