Replies: 1 comment 4 replies
-
🤖 Hello, Yes, it is indeed possible to split the formatting instructions into system roles for response generation in ConversationalRetrievalChain. The formatting instructions are handled by the Here is the relevant code: _ROLE_MAP = {"human": "Human: ", "ai": "Assistant: "}
def _get_chat_history(chat_history: List[CHAT_TURN_TYPE]) -> str:
buffer = ""
for dialogue_turn in chat_history:
if isinstance(dialogue_turn, BaseMessage):
role_prefix = _ROLE_MAP.get(dialogue_turn.type, f"{dialogue_turn.type}: ")
buffer += f"\n{role_prefix}{dialogue_turn.content}"
elif isinstance(dialogue_turn, tuple):
human = "Human: " + dialogue_turn[0]
ai = "Assistant: " + dialogue_turn[1]
buffer += "\n" + "\n".join([human, ai])
else:
raise ValueError(
f"Unsupported chat history format: {type(dialogue_turn)}."
f" Full chat history: {chat_history} "
)
return buffer This function iterates over the chat history and checks the type of each dialogue turn. If the dialogue turn is an instance of In the context shared, the You can find the relevant code in the following files:
I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to specify the format for response generation in a system role.
The current specification is to give the reconstructed questions, materials and formatting instructions all at once, but can the formatting instructions be split into system roles?
Thank you in advance.
Beta Was this translation helpful? Give feedback.
All reactions