Commit 2bf3362d by 文靖昊

大模型生成的相关问题优化

parent 4d063424
...@@ -173,6 +173,9 @@ def question(chat_request: ChatRequest, token: str = Header(None)): ...@@ -173,6 +173,9 @@ def question(chat_request: ChatRequest, token: str = Header(None)):
result = ext.extend_query(question, history) result = ext.extend_query(question, history)
matches = re.findall(r'"([^"]+)"', result.content) matches = re.findall(r'"([^"]+)"', result.content)
print(matches) print(matches)
if len(matches)>3:
matches = matches[:3]
print(matches)
prompt = "" prompt = ""
for h in history: for h in history:
prompt += "问:{}\n答:{}\n\n".format(h[0], h[1]) prompt += "问:{}\n答:{}\n\n".format(h[0], h[1])
...@@ -225,6 +228,9 @@ def re_generate(chat_request: ReGenerateRequest, token: str = Header(None)): ...@@ -225,6 +228,9 @@ def re_generate(chat_request: ReGenerateRequest, token: str = Header(None)):
history = crud.get_last_history_before_turn_id(str(session_id),last_turn_id) history = crud.get_last_history_before_turn_id(str(session_id),last_turn_id)
result = ext.extend_query(question, history) result = ext.extend_query(question, history)
matches = re.findall(r'"([^"]+)"', result.content) matches = re.findall(r'"([^"]+)"', result.content)
if len(matches)>3:
matches = matches[:3]
print(matches)
prompt = "" prompt = ""
for h in history: for h in history:
prompt += "问:{}\n答:{}\n\n".format(h[0], h[1]) prompt += "问:{}\n答:{}\n\n".format(h[0], h[1])
......
...@@ -74,7 +74,7 @@ class GetSimilarityWithExt: ...@@ -74,7 +74,7 @@ class GetSimilarityWithExt:
return unique_documents return unique_documents
DEFAULT_PROMPT = """作为一个向量检索助手,你的任务是结合历史记录,从不同角度,为“原问题”生成个不同版本的“检索词”,从而提高向量检索的语义丰富度,提高向量检索的精度。生成的问题要求指向对象清晰明确,并与“原问题语言相同”。例如: DEFAULT_PROMPT = """作为一个向量检索助手,你的任务是结合历史记录,从不同角度,为“原问题”生成个不同版本的“检索词”,从而提高向量检索的语义丰富度,提高向量检索的精度。生成的问题要求指向对象清晰明确,并与“原问题语言相同”。例如:
历史记录: 历史记录:
''' '''
''' '''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment