quackamollie.core.meta.model_manager.meta_quackamollie_model_manager module

class quackamollie.core.meta.model_manager.meta_quackamollie_model_manager.MetaQuackamollieModelManager[source]

Bases: object

Metaclass for model managers managed by the QuackamollieModelManagerRegistry

_abc_impl = <_abc._abc_data object>
_model_families: None | Dict[str, List[ModelFamilyIcon]] = None
_model_list: None | List[str] = None
_regex_end_sentence: Pattern = re.compile('[-?!.;\\n]')
families: List[ModelFamilyIcon]
abstract async classmethod get_model_class(model_name: str) Type[MetaQuackamollieModel] | None[source]

Get the model class from the model name

Parameters:

model_name (str) – Name of the model as listed by cls.get_model_list

Returns:

A subclass of MetaQuackamollieModel

Return type:

Optional[Type[MetaQuackamollieModel]]

abstract async classmethod get_model_families() Dict[str, List[ModelFamilyIcon]][source]

Discover the models families available for the model manager at runtime asynchronously

Returns:

A dict with values the list of families indexed by model name

Return type:

Dict[str, List[ModelFamilyIcon]]

abstract async classmethod get_model_list() List[str][source]

Discover the models available for the model manager at runtime asynchronously

Returns:

A list of available models for the model manager

Return type:

List[str]

abstract classmethod parse_chat_history(chat_messages: List[ChatMessage] | None) List[source]

Parse the chat history given as a list of ChatMessage from the database model to a list compatible with the model manager’s models.

Parameters:
  • chat_messages – A list of ChatMessage from the database model

  • chat_messages – Optional[List[ChatMessage]]

Returns:

A list of messages formatted to be compatible with the model manager’s models.

Return type:

List

async classmethod request_model(model_manager_name: str, model_name: str, model_config: Any, message: Message)[source]

Request a LLM model with a given message and stream the response

Parameters:
  • model_manager_name (str) – The user readable name of the current model manager, as registered in the QuackamollieModelManagerRegistry

  • model_name (str) – Name of the model as listed by cls.get_model_list

  • model_config (Any) – Additional configuration given as a string through CLI or Telegram App Settings and retrieved from the database

  • message (Message) – The message as given by aiogram router

abstract classmethod reset()[source]

Reset the model manager dynamic fields to force reloading models. Be careful if used asynchronously