Merge branch 'main' of stage.fjerkroa.no:ok/ChatMastermind
This commit is contained in:
@@ -15,7 +15,8 @@ def read_file(fname: pathlib.Path, 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:
|
||||
@@ -62,7 +63,10 @@ def save_answers(question: str,
|
||||
def create_chat(question: Optional[str],
|
||||
tags: Optional[List[str]],
|
||||
extags: Optional[List[str]],
|
||||
config: Dict[str, Any]
|
||||
config: Dict[str, Any],
|
||||
match_all_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())
|
||||
@@ -75,12 +79,15 @@ def create_chat(question: Optional[str],
|
||||
else:
|
||||
continue
|
||||
data_tags = set(data.get('tags', []))
|
||||
tags_match = \
|
||||
not tags or data_tags.intersection(tags)
|
||||
tags_match: bool
|
||||
if match_all_tags:
|
||||
tags_match = not tags or set(tags).issubset(data_tags)
|
||||
else:
|
||||
tags_match = not tags or bool(data_tags.intersection(tags))
|
||||
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)
|
||||
message_to_chat(data, chat, with_tags, with_file)
|
||||
if question:
|
||||
append_message(chat, 'user', question)
|
||||
return chat
|
||||
@@ -102,4 +109,7 @@ def get_tags(config: Dict[str, Any], prefix: Optional[str]) -> List[str]:
|
||||
result.append(tag)
|
||||
else:
|
||||
result.append(tag)
|
||||
return list(set(result))
|
||||
return result
|
||||
|
||||
def get_tags_unique(config: Dict[str, Any], prefix: Optional[str]) -> List[str]:
|
||||
return list(set(get_tags(config, prefix)))
|
||||
|
||||
Reference in New Issue
Block a user