message / chat: output improvements
This commit is contained in:
@@ -392,6 +392,30 @@ class Message():
|
||||
data[cls.file_yaml_key] = file_path
|
||||
return cls.from_dict(data)
|
||||
|
||||
def to_str(self, with_tags: bool = False, with_file: bool = False, source_code_only: bool = False) -> str:
|
||||
"""
|
||||
Return the current Message as a string.
|
||||
"""
|
||||
output: list[str] = []
|
||||
if source_code_only:
|
||||
# use the source code from answer only
|
||||
if self.answer:
|
||||
output.extend(self.answer.source_code(include_delims=True))
|
||||
return '\n'.join(output) if len(output) > 0 else ''
|
||||
if with_tags:
|
||||
output.append(self.tags_str())
|
||||
if with_file:
|
||||
output.append('FILE: ' + str(self.file_path))
|
||||
output.append(Question.txt_header)
|
||||
output.append(self.question)
|
||||
if self.answer:
|
||||
output.append(Answer.txt_header)
|
||||
output.append(self.answer)
|
||||
return '\n'.join(output)
|
||||
|
||||
def __str__(self) -> str:
|
||||
return self.to_str(False, False, False)
|
||||
|
||||
def to_file(self, file_path: Optional[pathlib.Path]=None) -> None: # noqa: 11
|
||||
"""
|
||||
Write a Message to the given file. Type is determined based on the suffix.
|
||||
|
||||
Reference in New Issue
Block a user