From f96e82bdd7c96fe12de38956be501b715c4d6a9c Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Tue, 12 Sep 2023 16:34:17 +0200 Subject: [PATCH] Implement the config -l and config -m commands. --- chatmastermind/ai.py | 6 ++++++ chatmastermind/commands/config.py | 9 +++++++++ chatmastermind/configuration.py | 1 + 3 files changed, 16 insertions(+) diff --git a/chatmastermind/ai.py b/chatmastermind/ai.py index b97b5f1..622aa4f 100644 --- a/chatmastermind/ai.py +++ b/chatmastermind/ai.py @@ -59,6 +59,12 @@ class AI(Protocol): """ raise NotImplementedError + def print_models(self) -> None: + """ + Print all models supported by this AI. + """ + raise NotImplementedError + def tokens(self, data: Union[Message, Chat]) -> int: """ Computes the nr. of AI language tokens for the given message diff --git a/chatmastermind/commands/config.py b/chatmastermind/commands/config.py index 262164c..3714573 100644 --- a/chatmastermind/commands/config.py +++ b/chatmastermind/commands/config.py @@ -1,6 +1,8 @@ import argparse from pathlib import Path from ..configuration import Config +from ..ai import AI +from ..ai_factory import create_ai def config_cmd(args: argparse.Namespace) -> None: @@ -9,3 +11,10 @@ def config_cmd(args: argparse.Namespace) -> None: """ if args.create: Config.create_default(Path(args.create)) + elif args.list_models or args.print_model: + config: Config = Config.from_file(args.config) + ai: AI = create_ai(args, config) + if args.list_models: + ai.print_models() + else: + print(ai.config.model) diff --git a/chatmastermind/configuration.py b/chatmastermind/configuration.py index 5397f4a..1415eb2 100644 --- a/chatmastermind/configuration.py +++ b/chatmastermind/configuration.py @@ -39,6 +39,7 @@ class AIConfig: name: ClassVar[str] # a user-defined ID for an AI configuration entry ID: str + model: str = 'n/a' # the name must not be changed def __setattr__(self, name: str, value: Any) -> None: