Skip to content

Commit

Permalink
pformat conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
huyiwen committed May 24, 2024
1 parent 1df318f commit 8686424
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions utilization/utils/conversation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from copy import deepcopy
from functools import lru_cache
from pprint import pformat
from typing import Dict, Iterator, List, Literal, NewType, Optional, Tuple, Union

from jinja2.exceptions import TemplateError
Expand Down Expand Up @@ -298,7 +299,7 @@ def get_segs(

# source
source = self.messages[example_ed:source_ed]
assert example_ed + 1 == source_ed, f"Invalid source messages: {source}"
assert source_ed - example_ed <= 1, f"Invalid source messages: {source}"

results = {"system": system, "examples": examples, "source": source, "target": target}
if seg:
Expand Down Expand Up @@ -350,6 +351,7 @@ def add(
assert isinstance(assistant, str)
messages.append({"role": "assistant", "content": assistant})
else:
assert isinstance(other, Conversation)
messages = other.messages
conv = Conversation(messages=deepcopy(self.messages))
# add a copy of other messages
Expand All @@ -372,13 +374,13 @@ def add_(
assert isinstance(assistant, str)
messages.append({"role": "assistant", "content": assistant})
else:
assert isinstance(other, Conversation)
messages = other.messages
# add a copy of other messages
self.messages.extend(messages)
return self

def __repr__(self):
output = f"Conversation id: {self.uuid}\n"
for message in self.messages:
output += f" > {message['role']}: {message['content']}\n"
output += pformat(self.messages)
return output

0 comments on commit 8686424

Please sign in to comment.