question_cmd: input tag options without a tag (e. g. '-t') now select ALL tags

This commit is contained in:
2023-09-22 07:51:05 +02:00
parent 33df84beaa
commit 80c5dcc801
2 changed files with 25 additions and 9 deletions
+22 -6
View File
@@ -118,14 +118,13 @@ def make_msg_args(msg: Message, args: argparse.Namespace) -> argparse.Namespace:
# use those from the original message
if (args.AI is None
or args.model is None # noqa: W503
or args.output_tags is None # noqa: W503
or len(args.output_tags) == 0): # noqa: W503
or args.output_tags is None): # noqa: W503
msg_args = deepcopy(args)
if args.AI is None and msg.ai is not None:
msg_args.AI = msg.ai
if args.model is None and msg.model is not None:
msg_args.model = msg.model
if (args.output_tags is None or len(args.output_tags) == 0) and msg.tags is not None:
if args.output_tags is None and msg.tags is not None:
msg_args.output_tags = msg.tags
return msg_args
@@ -151,13 +150,30 @@ def repeat_messages(messages: list[Message], chat: ChatDB, args: argparse.Namesp
make_request(ai, chat, message, args)
def invert_input_tag_args(args: argparse.Namespace) -> None:
"""
Changes the semantics of the INPUT tags for this command:
* not tags specified on the CLI -> no tags are selected
* empty tags specified on the CLI -> all tags are selected
"""
if args.or_tags is None:
args.or_tags = set()
elif len(args.or_tags) == 0:
args.or_tags = None
if args.and_tags is None:
args.and_tags = set()
elif len(args.and_tags) == 0:
args.and_tags = None
def question_cmd(args: argparse.Namespace, config: Config) -> None:
"""
Handler for the 'question' command.
"""
mfilter = MessageFilter(tags_or=args.or_tags if args.or_tags is not None else set(),
tags_and=args.and_tags if args.and_tags is not None else set(),
tags_not=args.exclude_tags if args.exclude_tags is not None else set())
invert_input_tag_args(args)
mfilter = MessageFilter(tags_or=args.or_tags,
tags_and=args.and_tags,
tags_not=args.exclude_tags)
chat = ChatDB.from_dir(cache_path=Path(config.cache),
db_path=Path(config.db),
mfilter=mfilter)