added option '-w' to print chat history with tags

This commit is contained in:
2023-08-04 18:15:04 +02:00
parent bcfb41917a
commit b57d78a875
4 changed files with 13 additions and 6 deletions
+2 -1
View File
@@ -55,7 +55,7 @@ def process_and_display_chat(args: argparse.Namespace,
question_parts.append(f"```\n{r.read().strip()}\n```")
full_question = '\n\n'.join(question_parts)
chat = create_chat(full_question, tags, extags, config)
chat = create_chat(full_question, tags, extags, config, args.with_tags)
display_chat(chat, dump, args.only_source_code)
return chat, full_question, tags
@@ -94,6 +94,7 @@ def create_parser() -> argparse.ArgumentParser:
parser.add_argument('-n', '--number', help='Number of answers to produce', type=int, default=1)
parser.add_argument('-s', '--source', nargs='*', help='Source add content of a file to the query')
parser.add_argument('-S', '--only-source-code', help='Print only source code', action='store_true')
parser.add_argument('-w', '--with-tags', help="Print chat with tags.", action='store_true')
tags_arg = parser.add_argument('-t', '--tags', nargs='*', help='List of tag names', metavar='TAGS')
tags_arg.completer = tags_completer # type: ignore
extags_arg = parser.add_argument('-e', '--extags', nargs='*', help='List of tag names to exclude', metavar='EXTAGS')
+3 -2
View File
@@ -62,7 +62,8 @@ 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],
with_tags: bool = False
) -> List[Dict[str, str]]:
chat: List[Dict[str, str]] = []
append_message(chat, 'system', config['system'].strip())
@@ -80,7 +81,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)
message_to_chat(data, chat, with_tags)
if question:
append_message(chat, 'user', question)
return chat
+5 -1
View File
@@ -34,10 +34,14 @@ def append_message(chat: List[Dict[str, str]],
def message_to_chat(message: Dict[str, str],
chat: List[Dict[str, str]]
chat: List[Dict[str, str]],
with_tags: bool = False
) -> None:
append_message(chat, 'user', message['question'])
append_message(chat, 'assistant', message['answer'])
if with_tags:
tags = ", ".join(message['tags'])
append_message(chat, 'tags', tags)
def display_source_code(content: str) -> None: