cmm: replaced options '--with-tags' and '--with-file' with '--with-metadata'

This commit is contained in:
2023-10-01 10:11:16 +02:00
parent e4cb6eb22b
commit 8f56399844
7 changed files with 24 additions and 15 deletions
+2 -2
View File
@@ -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:
+1 -2
View File
@@ -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:
+1 -3
View File
@@ -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')
+4 -3
View File
@@ -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: