Skip to content

Commit

Permalink
qa prompt v6, extract question prompt v6, use XML to distinguish comp…
Browse files Browse the repository at this point in the history
…lex data segments (#1674)
  • Loading branch information
beastoin authored Jan 11, 2025
2 parents 1d77a1c + fec93df commit a14dfeb
Show file tree
Hide file tree
Showing 2 changed files with 229 additions and 51 deletions.
36 changes: 36 additions & 0 deletions backend/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,42 @@ def get_sender_name(message: Message) -> str:

return '\n'.join(formatted_messages)

@staticmethod
def get_messages_as_xml(
messages: List['Message'],
use_user_name_if_available: bool = False,
use_plugin_name_if_available: bool = False
) -> str:
sorted_messages = sorted(messages, key=lambda m: m.created_at)

def get_sender_name(message: Message) -> str:
if message.sender == 'human':
return 'User'
# elif use_plugin_name_if_available and message.plugin_id is not None:
# plugin = next((p for p in plugins if p.id == message.plugin_id), None)
# if plugin:
# return plugin.name RESTORE ME
return message.sender.upper() # TODO: use plugin id

formatted_messages = [
f"""
<message>
<created_at>
{message.created_at.strftime('%d %b %Y at %H:%M UTC')}
</created_at>
<sender>
{get_sender_name(message)}
</sender>
<content>
{message.text}
</content>
</message>
""".replace(' ', '').replace('\n\n\n', '\n\n').strip()
for message in sorted_messages
]

return '\n'.join(formatted_messages)


class ResponseMessage(Message):
ask_for_nps: Optional[bool] = False
Expand Down
Loading

0 comments on commit a14dfeb

Please sign in to comment.