feat: add chat histories in prompt

pull/126/head
John Wang 3 years ago
parent 1b6e3ef964
commit 171a02a505

@ -157,11 +157,6 @@ And answer according to the language of the user's question.
else: else:
messages: List[BaseMessage] = [] messages: List[BaseMessage] = []
if pre_prompt:
# append pre prompt as system message
system_message = PromptBuilder.to_system_message(pre_prompt, inputs)
messages.append(system_message)
human_inputs = { human_inputs = {
"query": query "query": query
} }
@ -170,19 +165,27 @@ And answer according to the language of the user's question.
if chain_output: if chain_output:
human_inputs['context'] = chain_output human_inputs['context'] = chain_output
human_message_prompt = """Use the following CONTEXT as your learned knowledge. human_message_instruction = """Use the following CONTEXT as your learned knowledge.
[CONTEXT] [CONTEXT]
{context} {context}
[END CONTEXT] [END CONTEXT]
When answer to user: When answer to user:
- Incorporate the conversation history to answer the user.
- If you don't know, just say that you don't know. - If you don't know, just say that you don't know.
- If you don't know when you are not sure, ask for clarification. - If you don't know when you are not sure, ask for clarification.
Avoid mentioning that you obtained the information from the context. Avoid mentioning that you obtained the information from the context.
And answer according to the language of the user's question. And answer according to the language of the user's question.
"""
if pre_prompt:
human_inputs.update(inputs)
human_message_instruction += pre_prompt + "\n"
Q:{query} human_message_prompt = human_message_instruction + "Q:{query}\nA:"
A:""" else:
if pre_prompt:
human_inputs.update(inputs)
human_message_prompt = pre_prompt + "\n" + human_message_prompt
# construct main prompt # construct main prompt
human_message = PromptBuilder.to_human_message( human_message = PromptBuilder.to_human_message(

Loading…
Cancel
Save