导入方式修改
Some checks failed
构建并部署 AI Agent 服务 / deploy (push) Failing after 6m44s

This commit is contained in:
2026-05-05 23:17:00 +08:00
parent b5c15ef445
commit 3ae9daa01a
51 changed files with 445 additions and 532 deletions

View File

@@ -23,7 +23,7 @@ from .base import (
FallbackServiceChain,
SingletonServiceManager
)
from app.config import (
from ..config import (
VLLM_BASE_URL,
LLM_API_KEY,
ZHIPUAI_API_KEY,
@@ -203,7 +203,7 @@ class LocalSmallModelProvider(BaseServiceProvider[BaseChatModel]):
"""
def __init__(self, model: str = None):
from app.config import SMALL_LOCAL_MODEL_NAME, SMALL_VLLM_BASE_URL, SMALL_LLM_API_KEY
from ..config import SMALL_LOCAL_MODEL_NAME, SMALL_VLLM_BASE_URL, SMALL_LLM_API_KEY
super().__init__("local_small")
self._model = model or SMALL_LOCAL_MODEL_NAME
self._base_url = SMALL_VLLM_BASE_URL
@@ -242,7 +242,7 @@ class DeepSeekSmallModelProvider(BaseServiceProvider[BaseChatModel]):
"""
def __init__(self, model: str = None):
from app.config import SMALL_DEEPSEEK_MODEL, SMALL_DEEPSEEK_API_KEY, SMALL_DEEPSEEK_API_BASE
from ..config import SMALL_DEEPSEEK_MODEL, SMALL_DEEPSEEK_API_KEY, SMALL_DEEPSEEK_API_BASE
super().__init__("deepseek_small")
self._model = model or SMALL_DEEPSEEK_MODEL
self._api_key = SMALL_DEEPSEEK_API_KEY

View File

@@ -21,7 +21,7 @@ from .base import (
FallbackServiceChain,
SingletonServiceManager
)
from app.config import (
from ..config import (
LLAMACPP_EMBEDDING_URL,
LLAMACPP_API_KEY,
ZHIPUAI_API_KEY,

View File

@@ -27,7 +27,7 @@ from .base import (
FallbackServiceChain,
SingletonServiceManager
)
from app.config import (
from ..config import (
LLAMACPP_RERANKER_URL,
LLAMACPP_API_KEY,
ZHIPUAI_API_KEY,
@@ -92,20 +92,33 @@ class LocalLlamaCppRerankService(BaseRerankService):
"documents": documents,
}
logger.info(f"[LocalLlamaCppRerank] 调用 rerank API: {base}/rerank")
logger.info(f"[LocalLlamaCppRerank] 请求 payload: query={query[:50]}, documents数量={len(documents)}")
with httpx.Client(timeout=120) as client:
response = client.post(
f"{base}/rerank",
headers=headers,
json=payload,
)
response.raise_for_status()
logger.info(f"[LocalLlamaCppRerank] 响应状态码: {response.status_code}")
if response.status_code != 200:
logger.error(f"[LocalLlamaCppRerank] 请求失败: {response.status_code}")
logger.error(f"[LocalLlamaCppRerank] 响应内容: {response.text[:500]}")
response.raise_for_status()
data = response.json()
logger.info(f"[LocalLlamaCppRerank] 响应数据类型: {type(data)}")
if isinstance(data, dict) and "results" in data:
results = data["results"]
results_sorted = sorted(results, key=lambda x: x["index"])
return [item["relevance_score"] for item in results_sorted]
scores = [item["relevance_score"] for item in results_sorted]
logger.info(f"[LocalLlamaCppRerank] 返回 {len(scores)} 个得分")
return scores
else:
logger.error(f"[LocalLlamaCppRerank] 未知响应格式: {type(data)}")
raise ValueError(f"未知的 rerank API 响应格式: {data}")
@@ -207,11 +220,13 @@ class LLMFallbackRerankService(BaseRerankService):
if not documents:
return []
logger.info(f"[LLMFallbackRerank] 开始为 {len(documents)} 个文档打分")
scores = []
for doc in documents:
for i, doc in enumerate(documents):
score = self._score_single_document(query, doc)
scores.append(score)
logger.info(f"[LLMFallbackRerank] doc[{i}] score={score:.4f}")
return scores
def _score_single_document(self, query: str, document: str) -> float: