[RAG] 全部LLM硬编码从deepseek-r1改为deepseek-v3;修复知识库问答source格式不匹配导致检索结果被丢弃
This commit is contained in:
@@ -34,7 +34,7 @@ async def search_engine_iter(query: str , uid: str):
|
||||
response = await search_engine_chat(uid = uid,
|
||||
query=query,
|
||||
search_engine_name="zhipu_search",
|
||||
model_name=LLM_MODELS[1],
|
||||
model_name=LLM_MODELS[0],
|
||||
temperature=TEMPERATURE, # Agent搜索互联网的时候,温度设为0.1
|
||||
history=[],
|
||||
top_k=VECTOR_SEARCH_TOP_K,
|
||||
|
||||
@@ -62,7 +62,7 @@ async def chat(query: str = Body(..., description="用户输入", examples=["恼
|
||||
|
||||
if prompt_name == "Search Summary":
|
||||
model = get_ChatOpenAI(
|
||||
model_name=LLM_MODELS[1],
|
||||
model_name=LLM_MODELS[0],
|
||||
temperature=temperature,
|
||||
max_tokens=max_tokens,
|
||||
callbacks=callbacks,
|
||||
|
||||
@@ -46,7 +46,7 @@ async def chat_comparison_test(
|
||||
executor.submit(
|
||||
get_llm_model_response,
|
||||
strategy_name="query rewrite",
|
||||
llm_model_name=LLM_MODELS[1],
|
||||
llm_model_name=LLM_MODELS[0],
|
||||
template_prompt_name="extract_key_points",
|
||||
prompt_param_dict={"time": datetime.now().strftime("%Y%m%d"), "context": context, "content": content},
|
||||
temperature=0.01,
|
||||
|
||||
@@ -44,7 +44,7 @@ async def gen_abstract(
|
||||
try:
|
||||
article_abstract = get_llm_model_response(
|
||||
strategy_name="gen_abstract",
|
||||
llm_model_name=LLM_MODELS[1],
|
||||
llm_model_name=LLM_MODELS[0],
|
||||
template_prompt_name="gen_abstract",
|
||||
prompt_param_dict={
|
||||
"context": context_summary, # 使用摘要或原文
|
||||
|
||||
@@ -44,7 +44,7 @@ async def gen_conclusion(
|
||||
try:
|
||||
article_conclusion = get_llm_model_response(
|
||||
strategy_name="gen_conclusion",
|
||||
llm_model_name=LLM_MODELS[1],
|
||||
llm_model_name=LLM_MODELS[0],
|
||||
template_prompt_name="gen_conclusion",
|
||||
prompt_param_dict={
|
||||
"context": context_summary, # 使用摘要或原文
|
||||
|
||||
@@ -43,7 +43,7 @@ async def gen_keywords(
|
||||
try:
|
||||
article_keywords = get_llm_model_response(
|
||||
strategy_name="gen_keywords",
|
||||
llm_model_name=LLM_MODELS[1],
|
||||
llm_model_name=LLM_MODELS[0],
|
||||
template_prompt_name="gen_keywords",
|
||||
prompt_param_dict={
|
||||
"context": context_summary, # 使用摘要或原文
|
||||
|
||||
@@ -44,7 +44,7 @@ async def gen_paragraph(
|
||||
try:
|
||||
article_paragraph = get_llm_model_response(
|
||||
strategy_name="gen_paragraph",
|
||||
llm_model_name=LLM_MODELS[1],
|
||||
llm_model_name=LLM_MODELS[0],
|
||||
template_prompt_name="gen_paragraph",
|
||||
prompt_param_dict={
|
||||
"context": context_summary, # 使用摘要或原文
|
||||
|
||||
@@ -19,7 +19,7 @@ async def gen_title(
|
||||
"content": "我们来玩成语接龙,我先来,生龙活虎"},
|
||||
{"role": "assistant", "content": "虎头虎脑"}]]
|
||||
),
|
||||
model_name: Optional[str] = Body(LLM_MODELS[1], description="LLM 模型名称。"),
|
||||
model_name: Optional[str] = Body(LLM_MODELS[0], description="LLM 模型名称。"),
|
||||
):
|
||||
"""
|
||||
根据一轮对话历史生成简洁标题\n
|
||||
@@ -32,7 +32,7 @@ async def gen_title(
|
||||
if model_name == "R1-70B":
|
||||
model_name = DEEPSEEK_MODELS[1]
|
||||
elif model_name == "QIANWEN":
|
||||
model_name = LLM_MODELS[1]
|
||||
model_name = LLM_MODELS[0]
|
||||
else:
|
||||
model_name = model_name
|
||||
|
||||
|
||||
@@ -138,7 +138,7 @@ async def knowledge_base_chat(query: str = Body(..., description="用户输入",
|
||||
if isinstance(max_tokens, int) and max_tokens <= 0:
|
||||
max_tokens = None
|
||||
if prompt_name == "policy_chat":
|
||||
model_name = LLM_MODELS[1]
|
||||
model_name = LLM_MODELS[0]
|
||||
model = get_ChatOpenAI(
|
||||
model_name=model_name,
|
||||
temperature=temperature,
|
||||
|
||||
@@ -364,7 +364,7 @@ async def search_engine_chat(uid: Optional[str]=Body(None, description="userID")
|
||||
"content": "虎头虎脑"}]]
|
||||
),
|
||||
stream: bool = Body(False, description="流式输出"),
|
||||
model_name: str = Body(LLM_MODELS[1], description="LLM 模型名称。"),
|
||||
model_name: str = Body(LLM_MODELS[0], description="LLM 模型名称。"),
|
||||
temperature: float = Body(TEMPERATURE, description="LLM 采样温度", ge=0.0, le=1.0),
|
||||
max_tokens: Optional[int] = Body(None, description="限制LLM生成Token数量,默认None代表模型最大值"),
|
||||
prompt_name: str = Body("default",
|
||||
@@ -483,7 +483,7 @@ async def search_engine_chat(uid: Optional[str]=Body(None, description="userID")
|
||||
search_engine_name: str,
|
||||
top_k: int,
|
||||
history: Optional[List[History]],
|
||||
model_name: str = LLM_MODELS[1],
|
||||
model_name: str = LLM_MODELS[0],
|
||||
prompt_name: str = prompt_name,
|
||||
kgo_search_type: str = kgo_search_type
|
||||
) -> AsyncIterable[str]:
|
||||
|
||||
@@ -72,7 +72,7 @@ async def self_kb_chat(
|
||||
async def knowledge_base_chat_iterator(
|
||||
query: str,
|
||||
model_name: str = LLM_MODELS[0],
|
||||
model_name1: str = LLM_MODELS[1],
|
||||
model_name1: str = LLM_MODELS[0],
|
||||
prompt_name: str = "self_default",
|
||||
) -> AsyncIterable[str]:
|
||||
nonlocal fileNames, history
|
||||
|
||||
@@ -116,15 +116,16 @@ def search_self_docs(
|
||||
if top_k > 50:
|
||||
data = docs
|
||||
else:
|
||||
# Milvus 已通过 expr 过滤了 source,无需再按 fileNames 二次过滤
|
||||
# (Milvus 的 source 可能是原始文件名,而 fileNames 是 embeddingId,格式不一致)
|
||||
data = [
|
||||
DocumentWithVSId(
|
||||
**{k: v for k, v in x[0].dict().items() if k != 'page_content'}, # 排除原有的 page_content
|
||||
**{k: v for k, v in x[0].dict().items() if k != 'page_content'},
|
||||
score=x[1],
|
||||
id=x[0].metadata.get("id"),
|
||||
page_content=f"【^[{index +1}]^ {x[0].page_content}】 " # 拼接索引和page_content
|
||||
page_content=f"【^[{index +1}]^ {x[0].page_content}】 "
|
||||
)
|
||||
for index, x in enumerate(docs) # 使用enumerate来获取索引
|
||||
if x[0].metadata.get("source") in flat_fileNames
|
||||
for index, x in enumerate(docs)
|
||||
]
|
||||
else:
|
||||
logger.warning(f"未找到知识库服务: {knowledge_base_name}")
|
||||
|
||||
Reference in New Issue
Block a user