From 484e16de4dba0c23f673e42d86c87c0dc1a9109e Mon Sep 17 00:00:00 2001 From: juk0de Date: Tue, 5 Sep 2023 23:24:20 +0200 Subject: [PATCH] added new module 'ai_factory' --- chatmastermind/ai_factory.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 chatmastermind/ai_factory.py diff --git a/chatmastermind/ai_factory.py b/chatmastermind/ai_factory.py new file mode 100644 index 0000000..c90366b --- /dev/null +++ b/chatmastermind/ai_factory.py @@ -0,0 +1,20 @@ +""" +Creates different AI instances, based on the given configuration. +""" + +import argparse +from .configuration import Config +from .ai import AI, AIError +from .ais.openai import OpenAI + + +def create_ai(args: argparse.Namespace, config: Config) -> AI: + """ + Creates an AI subclass instance from the given args and configuration. + """ + if args.ai == 'openai': + # FIXME: create actual 'OpenAIConfig' and set values from 'args' + # FIXME: use actual name from config + return OpenAI("openai", config.openai) + else: + raise AIError(f"AI '{args.ai}' is not supported")