v3接口restful风格,规范化接口;添加mcp服务器;新增log模块
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
import dashscope
|
||||
from http import HTTPStatus
|
||||
from backend.core.config import settings
|
||||
import logging
|
||||
|
||||
# 获取当前模块的专用 Logger
|
||||
# __name__ 会自动识别为 "backend.services.crawler_service" 这样的路径
|
||||
logger = logging.getLogger(__name__)
|
||||
class LLMService:
|
||||
"""
|
||||
LLM 服务封装层
|
||||
@@ -21,10 +25,10 @@ class LLMService:
|
||||
if resp.status_code == HTTPStatus.OK:
|
||||
return resp.output['embeddings'][0]['embedding']
|
||||
else:
|
||||
print(f"[ERROR] Embedding API Error: {resp}")
|
||||
logger.error(f"Embedding API Error: {resp}")
|
||||
return None
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Embedding Exception: {e}")
|
||||
logger.error(f"Embedding Exception: {e}")
|
||||
return None
|
||||
|
||||
def rerank(self, query: str, documents: list, top_n: int = 5):
|
||||
@@ -81,12 +85,12 @@ class LLMService:
|
||||
|
||||
return reranked_results
|
||||
else:
|
||||
print(f"[ERROR] Rerank API Error: {resp}")
|
||||
logger.error(f"Rerank API Error: {resp}")
|
||||
# 降级策略:如果 Rerank 挂了,直接返回粗排的前 N 个
|
||||
return documents[:top_n]
|
||||
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Rerank Exception: {e}")
|
||||
logger.error(f"Rerank Exception: {e}")
|
||||
# 降级策略
|
||||
return documents[:top_n]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user