Compare commits
No commits in common. "c5c4a6628f688a6a93dc57e33406f3aca8cce415" and "caf5244d520aecaf482013d6a04c230de704f9b6" have entirely different histories.
c5c4a6628f
...
caf5244d52
@ -7,13 +7,10 @@ from typing import List, Dict, Any, Optional
|
|||||||
|
|
||||||
def read_file(fname: pathlib.Path, tags_only: bool = False) -> Dict[str, Any]:
|
def read_file(fname: pathlib.Path, tags_only: bool = False) -> Dict[str, Any]:
|
||||||
with open(fname, "r") as fd:
|
with open(fname, "r") as fd:
|
||||||
tagline = fd.readline().strip().split(':', maxsplit=1)[1].strip()
|
|
||||||
# also support tags separated by ',' (old format)
|
|
||||||
separator = ',' if ',' in tagline else ' '
|
|
||||||
tags = [t.strip() for t in tagline.split(separator)]
|
|
||||||
if tags_only:
|
if tags_only:
|
||||||
return {"tags": tags}
|
return {"tags": [x.strip() for x in fd.readline().strip().split(':')[1].strip().split(',')]}
|
||||||
text = fd.read().strip().split('\n')
|
text = fd.read().strip().split('\n')
|
||||||
|
tags = [x.strip() for x in text.pop(0).split(':')[1].strip().split(',')]
|
||||||
question_idx = text.index("=== QUESTION ===") + 1
|
question_idx = text.index("=== QUESTION ===") + 1
|
||||||
answer_idx = text.index("==== ANSWER ====")
|
answer_idx = text.index("==== ANSWER ====")
|
||||||
question = "\n".join(text[question_idx:answer_idx]).strip()
|
question = "\n".join(text[question_idx:answer_idx]).strip()
|
||||||
@ -24,7 +21,7 @@ def read_file(fname: pathlib.Path, tags_only: bool = False) -> Dict[str, Any]:
|
|||||||
|
|
||||||
def dump_data(data: Dict[str, Any]) -> str:
|
def dump_data(data: Dict[str, Any]) -> str:
|
||||||
with io.StringIO() as fd:
|
with io.StringIO() as fd:
|
||||||
fd.write(f'TAGS: {" ".join(data["tags"])}\n')
|
fd.write(f'TAGS: {", ".join(data["tags"])}\n')
|
||||||
fd.write(f'=== QUESTION ===\n{data["question"]}\n')
|
fd.write(f'=== QUESTION ===\n{data["question"]}\n')
|
||||||
fd.write(f'==== ANSWER ====\n{data["answer"]}\n')
|
fd.write(f'==== ANSWER ====\n{data["answer"]}\n')
|
||||||
return fd.getvalue()
|
return fd.getvalue()
|
||||||
@ -32,7 +29,7 @@ def dump_data(data: Dict[str, Any]) -> str:
|
|||||||
|
|
||||||
def write_file(fname: str, data: Dict[str, Any]) -> None:
|
def write_file(fname: str, data: Dict[str, Any]) -> None:
|
||||||
with open(fname, "w") as fd:
|
with open(fname, "w") as fd:
|
||||||
fd.write(f'TAGS: {" ".join(data["tags"])}\n')
|
fd.write(f'TAGS: {", ".join(data["tags"])}\n')
|
||||||
fd.write(f'=== QUESTION ===\n{data["question"]}\n')
|
fd.write(f'=== QUESTION ===\n{data["question"]}\n')
|
||||||
fd.write(f'==== ANSWER ====\n{data["answer"]}\n')
|
fd.write(f'==== ANSWER ====\n{data["answer"]}\n')
|
||||||
|
|
||||||
|
|||||||
@ -15,11 +15,11 @@ def process_tags(tags: list[str], extags: list[str], otags: list[str]) -> None:
|
|||||||
printed_messages = []
|
printed_messages = []
|
||||||
|
|
||||||
if tags:
|
if tags:
|
||||||
printed_messages.append(f"Tags: {' '.join(tags)}")
|
printed_messages.append(f"Tags: {', '.join(tags)}")
|
||||||
if extags:
|
if extags:
|
||||||
printed_messages.append(f"Excluding tags: {' '.join(extags)}")
|
printed_messages.append(f"Excluding tags: {', '.join(extags)}")
|
||||||
if otags:
|
if otags:
|
||||||
printed_messages.append(f"Output tags: {' '.join(otags)}")
|
printed_messages.append(f"Output tags: {', '.join(otags)}")
|
||||||
|
|
||||||
if printed_messages:
|
if printed_messages:
|
||||||
print("\n".join(printed_messages))
|
print("\n".join(printed_messages))
|
||||||
@ -41,7 +41,7 @@ def message_to_chat(message: Dict[str, str],
|
|||||||
append_message(chat, 'user', message['question'])
|
append_message(chat, 'user', message['question'])
|
||||||
append_message(chat, 'assistant', message['answer'])
|
append_message(chat, 'assistant', message['answer'])
|
||||||
if with_tags:
|
if with_tags:
|
||||||
tags = " ".join(message['tags'])
|
tags = ", ".join(message['tags'])
|
||||||
append_message(chat, 'tags', tags)
|
append_message(chat, 'tags', tags)
|
||||||
if with_file:
|
if with_file:
|
||||||
append_message(chat, 'file', message['file'])
|
append_message(chat, 'file', message['file'])
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user