Compare commits

..

3 Commits

Author SHA1 Message Date
5ac824fd51 added new module 'openai.py' 2023-09-04 22:57:49 +02:00
edd5effd0c added new module 'ai.py' 2023-09-04 22:57:49 +02:00
86de631f66 cmm: added 'question' command 2023-09-04 22:57:49 +02:00
2 changed files with 24 additions and 26 deletions

View File

@ -30,8 +30,8 @@ def create_question_with_hist(args: argparse.Namespace,
Creates the "AI request", including the question and chat history as determined Creates the "AI request", including the question and chat history as determined
by the specified tags. by the specified tags.
""" """
tags = args.tags or [] tags = args.or_tags or []
xtags = args.xtags or [] xtags = args.exclude_tags or []
otags = args.output_tags or [] otags = args.output_tags or []
if not args.source_code_only: if not args.source_code_only:
@ -53,7 +53,7 @@ def create_question_with_hist(args: argparse.Namespace,
full_question = '\n\n'.join(question_parts) full_question = '\n\n'.join(question_parts)
chat = create_chat_hist(full_question, tags, xtags, config, chat = create_chat_hist(full_question, tags, xtags, config,
match_all_tags=True if args.atags else False, # FIXME match_all_tags=True if args.and_tags else False, # FIXME
with_tags=False, with_tags=False,
with_file=False) with_file=False)
return chat, full_question, tags return chat, full_question, tags
@ -94,7 +94,7 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None:
# if it's a new question, create and store it immediately # if it's a new question, create and store it immediately
if args.ask or args.create: if args.ask or args.create:
message = Message(question=Question(args.question), message = Message(question=Question(args.question),
tags=args.tags, tags=args.ouput_tags, # FIXME
ai=args.ai, ai=args.ai,
model=args.model) model=args.model)
chat.add_to_cache([message]) chat.add_to_cache([message])
@ -132,9 +132,9 @@ def hist_cmd(args: argparse.Namespace, config: Config) -> None:
Handler for the 'hist' command. Handler for the 'hist' command.
""" """
mfilter = MessageFilter(tags_or=args.tags, mfilter = MessageFilter(tags_or=args.or_tags,
tags_and=args.atags, tags_and=args.and_tags,
tags_not=args.etags, tags_not=args.exclude_tags,
question_contains=args.question, question_contains=args.question,
answer_contains=args.answer) answer_contains=args.answer)
chat = ChatDB.from_dir(Path('.'), chat = ChatDB.from_dir(Path('.'),
@ -172,17 +172,17 @@ def create_parser() -> argparse.ArgumentParser:
# a parent parser for all commands that support tag selection # a parent parser for all commands that support tag selection
tag_parser = argparse.ArgumentParser(add_help=False) tag_parser = argparse.ArgumentParser(add_help=False)
tag_arg = tag_parser.add_argument('-t', '--tags', nargs='+', tag_arg = tag_parser.add_argument('-t', '--or-tags', nargs='+',
help='List of tag names (one must match)', metavar='TAGS') help='List of tag names (one must match)', metavar='OTAGS')
tag_arg.completer = tags_completer # type: ignore tag_arg.completer = tags_completer # type: ignore
atag_arg = tag_parser.add_argument('-k', '--atags', nargs='+', atag_arg = tag_parser.add_argument('-k', '--and-tags', nargs='+',
help='List of tag names (all must match)', metavar='TAGS') help='List of tag names (all must match)', metavar='ATAGS')
atag_arg.completer = tags_completer # type: ignore atag_arg.completer = tags_completer # type: ignore
etag_arg = tag_parser.add_argument('-x', '--xtags', nargs='+', etag_arg = tag_parser.add_argument('-x', '--exclude-tags', nargs='+',
help='List of tag names to exclude', metavar='XTAGS') help='List of tag names to exclude', metavar='XTAGS')
etag_arg.completer = tags_completer # type: ignore etag_arg.completer = tags_completer # type: ignore
otag_arg = tag_parser.add_argument('-o', '--output-tags', nargs='+', otag_arg = tag_parser.add_argument('-o', '--output-tags', nargs='+',
help='List of output tag names, default is input', metavar='OTAGS') help='List of output tag names, default is input', metavar='OUTTAGS')
otag_arg.completer = tags_completer # type: ignore otag_arg.completer = tags_completer # type: ignore
# 'question' command parser # 'question' command parser
@ -191,12 +191,10 @@ def create_parser() -> argparse.ArgumentParser:
aliases=['q']) aliases=['q'])
question_cmd_parser.set_defaults(func=question_cmd) question_cmd_parser.set_defaults(func=question_cmd)
question_group = question_cmd_parser.add_mutually_exclusive_group(required=True) question_group = question_cmd_parser.add_mutually_exclusive_group(required=True)
question_group.add_argument('-a', '--ask', help='Ask a question') question_group.add_argument('-a', '--ask', nargs='+', help='Ask a question')
question_group.add_argument('-r', '--repeat', help='Repeat a question') question_group.add_argument('-c', '--create', nargs='+', help='Create a question')
question_group.add_argument('-c', '--create', help='Create a question') question_group.add_argument('-r', '--repeat', nargs='*', help='Repeat a question')
question_group.add_argument('-p', '--process', help='Process existing questions') question_group.add_argument('-p', '--process', nargs='*', help='Process existing questions')
question_cmd_parser.add_argument('-q', '--question', nargs='+', help='Question to ask or create', type=int)
question_cmd_parser.add_argument('-f', '--file', nargs='+', help='Message file(s) to repeat or process')
question_cmd_parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int) question_cmd_parser.add_argument('-m', '--max-tokens', help='Max tokens to use', type=int)
question_cmd_parser.add_argument('-T', '--temperature', help='Temperature to use', type=float) question_cmd_parser.add_argument('-T', '--temperature', help='Temperature to use', type=float)
question_cmd_parser.add_argument('-A', '--AI', help='AI to use') question_cmd_parser.add_argument('-A', '--AI', help='AI to use')

View File

@ -114,9 +114,9 @@ class TestHandleQuestion(CmmTestCase):
def setUp(self) -> None: def setUp(self) -> None:
self.question = "test question" self.question = "test question"
self.args = argparse.Namespace( self.args = argparse.Namespace(
tags=['tag1'], or_tags=['tag1'],
atags=None, and_tags=None,
xtags=['xtag1'], exclude_tags=['xtag1'],
output_tags=None, output_tags=None,
question=[self.question], question=[self.question],
source=None, source=None,
@ -143,12 +143,12 @@ class TestHandleQuestion(CmmTestCase):
open_mock = MagicMock() open_mock = MagicMock()
with patch("chatmastermind.storage.open", open_mock): with patch("chatmastermind.storage.open", open_mock):
ask_cmd(self.args, self.config) ask_cmd(self.args, self.config)
mock_print_tag_args.assert_called_once_with(self.args.tags, mock_print_tag_args.assert_called_once_with(self.args.or_tags,
self.args.xtags, self.args.exclude_tags,
[]) [])
mock_create_chat_hist.assert_called_once_with(self.question, mock_create_chat_hist.assert_called_once_with(self.question,
self.args.tags, self.args.or_tags,
self.args.xtags, self.args.exclude_tags,
self.config, self.config,
match_all_tags=False, match_all_tags=False,
with_tags=False, with_tags=False,