Commit 17e7b130 by 周峻哲

问答出现预设场景,历史不展示的情况

parent 7e960d29
......@@ -38,7 +38,7 @@ prompt1 = """'''
PROMPT1 = PromptTemplate(input_variables=["context", "question"], template=prompt1)
# 预设的安全响应
SAFE_RESPONSE = "抱歉,我无法回答这个问题。"
SAFE_RESPONSE = "您好,我不具备人类属性,因此没有名字。我可以协助您完成范围广泛的任务并提供有关各种主题的信息,比如回答问题,提是供定义和解释及建议。如果您有任何问题,请随时向我提问。"
BLOCKED_KEYWORDS = ["文心一言", "百度", "模型"]
class QA:
......@@ -88,10 +88,10 @@ class QA:
self.cur_oquestion = _question
history = self.get_history()
if self.contains_blocked_keywords(_question):
self.cur_answer = SAFE_RESPONSE
yield [(self.cur_oquestion, self.cur_answer)]
return
# if self.contains_blocked_keywords(_question):
# self.cur_answer = SAFE_RESPONSE
# yield [(self.cur_oquestion, self.cur_answer)]
# return
self.cur_similarity = self.get_similarity(_aquestion=self.cur_oquestion)
self.cur_question = self.prompt.format(context=self.cur_similarity, question=self.cur_oquestion)
......@@ -115,7 +115,7 @@ class QA:
history.append((self.cur_oquestion, self.cur_answer))
async for token in callback.aiter():
self.cur_answer += token
if self.contains_blocked_keywords(self.cur_answer):
if self.contains_blocked_keywords(self.cur_oquestion):
self.cur_answer = SAFE_RESPONSE
history[-1] = (self.cur_oquestion, self.cur_answer)
yield history
......
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