Skip to content

Commit

Permalink
Fix time and prompt (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwxxzz authored Feb 20, 2025
1 parent 91242db commit 69ac112
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
30 changes: 26 additions & 4 deletions src/pai_rag/integrations/query_transform/pai_query_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,20 @@ def _run(self, query_bundle: QueryBundle, session_id, chat_history) -> QueryBund
chat_history = self._chat_store.get_messages(session_id)
chat_history_str = messages_to_history_str(chat_history)

logger.debug(f"Chat history: {chat_history_str}")
current_condense_question_prompt = PromptTemplate(
template="{}\n{}\n{}".format(
CONDENSE_QUESTION_CHAT_ENGINE_PROMPT_ZH,
CURRENT_TIME_PROMPT.format(
current_datetime=datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
),
CONDENSE_QUESTION_ANSWER_PROMPT_ZH,
)
)
logger.debug(
f"Chat history: {chat_history_str} \n condense_question_prompt: {current_condense_question_prompt}"
)
transformed_query_str = self._llm.predict(
self._condense_question_prompt,
current_condense_question_prompt,
question=query_str,
chat_history=chat_history_str,
)
Expand Down Expand Up @@ -265,9 +276,20 @@ async def _arun(
chat_history = self._chat_store.get_messages(key=session_id)
chat_history_str = messages_to_history_str(chat_history)

logger.debug(f"Chat history: {chat_history_str}")
current_condense_question_prompt = PromptTemplate(
template="{}\n{}\n{}".format(
CONDENSE_QUESTION_CHAT_ENGINE_PROMPT_ZH,
CURRENT_TIME_PROMPT.format(
current_datetime=datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
),
CONDENSE_QUESTION_ANSWER_PROMPT_ZH,
)
)
logger.debug(
f"Chat history: {chat_history_str} \n condense_question_prompt: {current_condense_question_prompt}"
)
transformed_query_str = await self._llm.apredict(
self._condense_question_prompt,
current_condense_question_prompt,
question=query_str,
chat_history=chat_history_str,
)
Expand Down
6 changes: 4 additions & 2 deletions src/pai_rag/integrations/synthesizer/prompt_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

DEFAULT_CUSTOM_PROMPT_TEMPLATE = """你的目标是提供准确、有用且易于理解的信息。
**任务要求:**
- 请严格按照上述提供的参考内容回答问题。如果参考内容中没有相关信息或与问题无关,请基于你的已有知识进行回答。
- 请严格根据提供的参考内容回答问题,仅参考与问题相关的内容并忽略所有不相关的信息。
- 如果参考内容中没有相关信息或与问题无关,请基于你的已有知识进行回答。
- 确保答案准确、简洁,并且使用与提问相同的语言。
- 回答时不要出现“从参考内容得出”、“从材料得出”等字眼
- 在回答过程中,请避免使用“从参考内容得出”、“从材料得出”、“根据参考内容”等措辞
- 保持回答的专业性和友好性。
- 如果需要更多信息来更好地回答问题,请礼貌地询问。
- 对于复杂的问题,尽量简化解释,使信息易于理解。
- 保持输出语言与输入语言的一致性。
- 对于涉及不安全/不道德/敏感/色情/暴力/赌博/违法等行为的问题,请明确拒绝提供所要求的信息,并简单解释为什么这样的请求不能被满足。
"""

Expand Down
4 changes: 3 additions & 1 deletion src/pai_rag/utils/prompt_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
### 技能 2: 生成搜索查询
- 生成的搜索查询应简洁、明确且与主题相关。
- 查询应尽可能广泛,以便获取更多相关信息。
- 如果查询与时间相关,需要带上对应时间信息。
- 时间相关查询:(1)高频波动信息(如黄金价格、外汇汇率、股票价格等):请提供具体且最新的时间信息,例如最新一天或实时数据,并使用适当的短时间间隔。(2)低频更新信息(如汽车评测、电影上映、歌曲发布等):请使用较宽泛的时间范围,如最近一个月或更长时间,并提供相关的时间信息。
- 非时间相关查询:避免随意添加时间信息,确保回答专注于查询的主要内容。
- 生成的查询格式为 JSON 对象:```{ "queries": ["query1", "query2"] }```。
### 技能 3: 确定无需搜索
Expand All @@ -119,6 +120,7 @@
- 在生成搜索查询时,确保每个查询都是独立的、简洁的,并且与主题相关。
- 保持输出格式的一致性,严格遵循给定的 JSON 格式要求。
- 简明扼要地专注于撰写高质量的搜索查询,避免不必要的详细说明、评论或假设。
- 保持输出语言与输入语言的一致性。
"""

CONDENSE_QUESTION_ANSWER_PROMPT_ZH = """## 聊天记录:
Expand Down

0 comments on commit 69ac112

Please # to comment.