27 lines
760 B
Python
27 lines
760 B
Python
"""
|
|
Creates different AI instances, based on the given configuration.
|
|
"""
|
|
|
|
import argparse
|
|
from typing import cast
|
|
from .configuration import Config, OpenAIConfig, default_ai_ID
|
|
from .ai import AI, AIError
|
|
from .ais.openai_cmm 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:
|
|
ai_conf = config.ais[args.ai]
|
|
elif default_ai_ID in config.ais:
|
|
ai_conf = config.ais[default_ai_ID]
|
|
else:
|
|
raise AIError("No AI name given and no default exists")
|
|
|
|
if ai_conf.name == 'openai':
|
|
return OpenAI(cast(OpenAIConfig, ai_conf))
|
|
else:
|
|
raise AIError(f"AI '{args.ai}' is not supported")
|