Added option '-W' to print chat history with filenames

This commit is contained in:
2023-08-05 08:09:35 +02:00
parent b57d78a875
commit 32bd17594b
4 changed files with 20 additions and 12 deletions
+5 -3
View File
@@ -15,7 +15,8 @@ def read_file(fname: str, tags_only: bool = False) -> Dict[str, Any]:
answer_idx = text.index("==== ANSWER ====")
question = "\n".join(text[question_idx:answer_idx]).strip()
answer = "\n".join(text[answer_idx + 1:]).strip()
return {"question": question, "answer": answer, "tags": tags}
return {"question": question, "answer": answer, "tags": tags,
"file": pathlib.Path(fname).name}
def dump_data(data: Dict[str, Any]) -> str:
@@ -63,7 +64,8 @@ def create_chat(question: Optional[str],
tags: Optional[List[str]],
extags: Optional[List[str]],
config: Dict[str, Any],
with_tags: bool = False
with_tags: bool = False,
with_file: bool = False
) -> List[Dict[str, str]]:
chat: List[Dict[str, str]] = []
append_message(chat, 'system', config['system'].strip())
@@ -81,7 +83,7 @@ def create_chat(question: Optional[str],
extags_do_not_match = \
not extags or not data_tags.intersection(extags)
if tags_match and extags_do_not_match:
message_to_chat(data, chat, with_tags)
message_to_chat(data, chat, with_tags, with_file)
if question:
append_message(chat, 'user', question)
return chat