configuration et al: implemented new Config format
This commit is contained in:
@@ -3,18 +3,35 @@ Creates different AI instances, based on the given configuration.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
from .configuration import Config
|
||||
from typing import cast
|
||||
from .configuration import Config, OpenAIConfig, default_ai_ID
|
||||
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.
|
||||
Creates an AI subclass instance from the given arguments
|
||||
and configuration file.
|
||||
"""
|
||||
if args.ai == 'openai':
|
||||
# FIXME: create actual 'OpenAIConfig' and set values from 'args'
|
||||
# FIXME: use actual name from config
|
||||
return OpenAI("openai", config.openai)
|
||||
if args.ai:
|
||||
try:
|
||||
ai_conf = config.ais[args.ai]
|
||||
except KeyError:
|
||||
raise AIError(f"AI ID '{args.ai}' does not exist in this configuration")
|
||||
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':
|
||||
ai = OpenAI(cast(OpenAIConfig, ai_conf))
|
||||
if args.model:
|
||||
ai.config.model = args.model
|
||||
if args.max_tokens:
|
||||
ai.config.max_tokens = args.max_tokens
|
||||
if args.temperature:
|
||||
ai.config.temperature = args.temperature
|
||||
return ai
|
||||
else:
|
||||
raise AIError(f"AI '{args.ai}' is not supported")
|
||||
|
||||
Reference in New Issue
Block a user