From 0ee56458532e767a8bb696b2f7f7054a6afce208 Mon Sep 17 00:00:00 2001 From: juk0de Date: Thu, 21 Sep 2023 18:21:43 +0200 Subject: [PATCH] question_cmd: fixed AI and model arguments when repeating messages --- chatmastermind/commands/question.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/chatmastermind/commands/question.py b/chatmastermind/commands/question.py index e35bfe5..b9fb5d8 100644 --- a/chatmastermind/commands/question.py +++ b/chatmastermind/commands/question.py @@ -105,11 +105,21 @@ def make_request(ai: AI, chat: ChatDB, message: Message, args: argparse.Namespac print(response.tokens) -def repeat_messages(messages: list[Message], ai: AI, chat: ChatDB, args: argparse.Namespace) -> None: +def repeat_messages(messages: list[Message], chat: ChatDB, args: argparse.Namespace, config: Config) -> None: """ Repeat the given messages using the given arguments. """ + ai: AI for msg in messages: + ai_args = args + # if AI or model have not been specified, use those from the original message + if args.AI is None or args.model is None: + ai_args = args.copy() + if args.AI is None and msg.ai is not None: + ai_args.AI = msg.ai + if args.model is None and msg.model is not None: + ai_args.model = msg.model + ai = create_ai(ai_args, config) print(f"--------- Repeating message '{msg.msg_id()}': ---------") # overwrite the latest message if requested or empty # -> but not if it's in the DB! @@ -139,11 +149,10 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None: message = create_message(chat, args) if args.create: return - # create the correct AI instance - ai: AI = create_ai(args, config) # === ASK === if args.ask: + ai: AI = create_ai(args, config) make_request(ai, chat, message, args) # === REPEAT === elif args.repeat is not None: @@ -158,7 +167,7 @@ def question_cmd(args: argparse.Namespace, config: Config) -> None: # repeat given message(s) else: repeat_msgs = chat.msg_find(args.repeat, loc='disk') - repeat_messages(repeat_msgs, ai, chat, args) + repeat_messages(repeat_msgs, chat, args, config) # === PROCESS === elif args.process is not None: # TODO: process either all questions without an