diff --git a/README.md b/README.md index 4fb1d08..c661200 100644 --- a/README.md +++ b/README.md @@ -79,8 +79,7 @@ cmm hist [--print | --convert FORMAT] [-t OTAGS]... [-k ATAGS]... [-x XTAGS]... * `-t, --or-tags OTAGS`: List of tags (one must match) * `-k, --and-tags ATAGS`: List of tags (all must match) * `-x, --exclude-tags XTAGS`: List of tags to exclude -* `-w, --with-tags`: Print chat history with tags -* `-W, --with-files`: Print chat history with filenames +* `-w, --with-metadata`: Print chat history with metadata (tags, filenames, AI, etc.) * `-S, --source-code-only`: Only print embedded source code * `-A, --answer SUBSTRING`: Filter for answer substring * `-Q, --question SUBSTRING`: Filter for question substring diff --git a/chatmastermind/chat.py b/chatmastermind/chat.py index 2640c8b..eea78c6 100644 --- a/chatmastermind/chat.py +++ b/chatmastermind/chat.py @@ -255,14 +255,14 @@ class Chat: return sum(m.tokens() for m in self.messages) def print(self, source_code_only: bool = False, - with_tags: bool = False, with_files: bool = False, + with_metadata: bool = False, paged: bool = True) -> None: output: list[str] = [] for message in self.messages: if source_code_only: output.append(message.to_str(source_code_only=True)) continue - output.append(message.to_str(with_tags, with_files)) + output.append(message.to_str(with_metadata)) if paged: print_paged('\n'.join(output)) else: diff --git a/chatmastermind/commands/hist.py b/chatmastermind/commands/hist.py index e84e761..de7dd66 100644 --- a/chatmastermind/commands/hist.py +++ b/chatmastermind/commands/hist.py @@ -57,8 +57,7 @@ def print_chat(args: argparse.Namespace, config: Config) -> None: Path(config.db), mfilter=mfilter) chat.print(args.source_code_only, - args.with_tags, - args.with_files) + args.with_metadata) def hist_cmd(args: argparse.Namespace, config: Config) -> None: diff --git a/chatmastermind/main.py b/chatmastermind/main.py index a803d0e..482806c 100755 --- a/chatmastermind/main.py +++ b/chatmastermind/main.py @@ -79,9 +79,7 @@ def create_parser() -> argparse.ArgumentParser: hist_group = hist_cmd_parser.add_mutually_exclusive_group(required=True) hist_group.add_argument('-p', '--print', help='Print the DB chat history', action='store_true') hist_group.add_argument('-c', '--convert', help='Convert all message files to the given format [txt|yaml]', metavar='FORMAT') - hist_cmd_parser.add_argument('-w', '--with-tags', help="Print chat history with tags.", - action='store_true') - hist_cmd_parser.add_argument('-W', '--with-files', help="Print chat history with filenames.", + hist_cmd_parser.add_argument('-w', '--with-metadata', help="Print chat history with metadata (tags, filename, AI, etc.).", action='store_true') hist_cmd_parser.add_argument('-S', '--source-code-only', help='Only print embedded source code', action='store_true') diff --git a/chatmastermind/message.py b/chatmastermind/message.py index ced11bb..8e7a55d 100644 --- a/chatmastermind/message.py +++ b/chatmastermind/message.py @@ -422,7 +422,7 @@ class Message(): except Exception: raise MessageError(f"'{file_path}' does not contain a valid message") - def to_str(self, with_tags: bool = False, with_file: bool = False, source_code_only: bool = False) -> str: + def to_str(self, with_metadata: bool = False, source_code_only: bool = False) -> str: """ Return the current Message as a string. """ @@ -432,10 +432,11 @@ class Message(): if self.answer: output.extend(self.answer.source_code(include_delims=True)) return '\n'.join(output) if len(output) > 0 else '' - if with_tags: + if with_metadata: output.append(self.tags_str()) - if with_file: output.append('FILE: ' + str(self.file_path)) + output.append('AI: ' + str(self.ai)) + output.append('MODEL: ' + str(self.model)) output.append(Question.txt_header) output.append(self.question) if self.answer: diff --git a/tests/test_chat.py b/tests/test_chat.py index fca61e5..7616dde 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -41,10 +41,14 @@ class TestChat(TestChatBase): self.message1 = Message(Question('Question 1'), Answer('Answer 1'), {Tag('atag1'), Tag('btag2')}, + ai='FakeAI', + model='FakeModel', file_path=pathlib.Path(f'0001{msg_suffix}')) self.message2 = Message(Question('Question 2'), Answer('Answer 2'), {Tag('btag2')}, + ai='FakeAI', + model='FakeModel', file_path=pathlib.Path(f'0002{msg_suffix}')) self.maxDiff = None @@ -156,17 +160,21 @@ Answer 2 self.assertEqual(mock_stdout.getvalue(), expected_output) @patch('sys.stdout', new_callable=StringIO) - def test_print_with_tags_and_file(self, mock_stdout: StringIO) -> None: + def test_print_with_metadata(self, mock_stdout: StringIO) -> None: self.chat.msg_add([self.message1, self.message2]) - self.chat.print(paged=False, with_tags=True, with_files=True) + self.chat.print(paged=False, with_metadata=True) expected_output = f"""{TagLine.prefix} atag1 btag2 FILE: 0001{msg_suffix} +AI: FakeAI +MODEL: FakeModel {Question.txt_header} Question 1 {Answer.txt_header} Answer 1 {TagLine.prefix} btag2 FILE: 0002{msg_suffix} +AI: FakeAI +MODEL: FakeModel {Question.txt_header} Question 2 {Answer.txt_header} diff --git a/tests/test_message.py b/tests/test_message.py index 6e39143..b79bcae 100644 --- a/tests/test_message.py +++ b/tests/test_message.py @@ -856,6 +856,8 @@ class MessageToStrTestCase(unittest.TestCase): def setUp(self) -> None: self.message = Message(Question('This is a question.'), Answer('This is an answer.'), + ai=('FakeAI'), + model=('FakeModel'), tags={Tag('atag1'), Tag('btag2')}, file_path=pathlib.Path('/tmp/foo/bla')) @@ -869,11 +871,13 @@ This is an answer.""" def test_to_str_with_tags_and_file(self) -> None: expected_output = f"""{TagLine.prefix} atag1 btag2 FILE: /tmp/foo/bla +AI: FakeAI +MODEL: FakeModel {Question.txt_header} This is a question. {Answer.txt_header} This is an answer.""" - self.assertEqual(self.message.to_str(with_tags=True, with_file=True), expected_output) + self.assertEqual(self.message.to_str(with_metadata=True), expected_output) class MessageRmFileTestCase(unittest.TestCase):