Skip to content

Commit

Permalink
added ContentFormatter escape special characters for message content (#…
Browse files Browse the repository at this point in the history
…10319)



---------

Co-authored-by: Manikanta5112 <[email protected]>
  • Loading branch information
Manikanta5112 and mani5112 authored Oct 6, 2023
1 parent d17416e commit 56048b9
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions libs/langchain/langchain/chat_models/azureml_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,36 @@ class LlamaContentFormatter(ContentFormatterBase):
def _convert_message_to_dict(message: BaseMessage) -> Dict:
"""Converts message to a dict according to role"""
if isinstance(message, HumanMessage):
return {"role": "user", "content": message.content}
return {
"role": "user",
"content": ContentFormatterBase.escape_special_characters(
message.content
),
}
elif isinstance(message, AIMessage):
return {"role": "assistant", "content": message.content}
return {
"role": "assistant",
"content": ContentFormatterBase.escape_special_characters(
message.content
),
}
elif isinstance(message, SystemMessage):
return {"role": "system", "content": message.content}
return {
"role": "system",
"content": ContentFormatterBase.escape_special_characters(
message.content
),
}
elif (
isinstance(message, ChatMessage)
and message.role in LlamaContentFormatter.SUPPORTED_ROLES
):
return {"role": message.role, "content": message.content}
return {
"role": message.role,
"content": ContentFormatterBase.escape_special_characters(
message.content
),
}
else:
supported = ",".join(
[role for role in LlamaContentFormatter.SUPPORTED_ROLES]
Expand Down

0 comments on commit 56048b9

Please sign in to comment.