chat: ChatDB now correctly ignores files that contain no valid messages
This commit is contained in:
@@ -370,7 +370,7 @@ class Message():
|
||||
try:
|
||||
question_idx = text.index(Question.txt_header) + 1
|
||||
except ValueError:
|
||||
raise MessageError(f"Question header '{Question.txt_header}' not found in '{file_path}'")
|
||||
raise MessageError(f"'{file_path}' does not contain a valid message")
|
||||
try:
|
||||
answer_idx = text.index(Answer.txt_header)
|
||||
question = Question.from_list(text[question_idx:answer_idx])
|
||||
@@ -390,9 +390,12 @@ class Message():
|
||||
* Message.model_yaml_key: str [Optional]
|
||||
"""
|
||||
with open(file_path, "r") as fd:
|
||||
data = yaml.load(fd, Loader=yaml.FullLoader)
|
||||
data[cls.file_yaml_key] = file_path
|
||||
return cls.from_dict(data)
|
||||
try:
|
||||
data = yaml.load(fd, Loader=yaml.FullLoader)
|
||||
data[cls.file_yaml_key] = file_path
|
||||
return cls.from_dict(data)
|
||||
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:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user