Providers

A chat provider convenience class. This class is a collection of all the chat providers and their handlers. It also provides a default provider and handler.

There are a few objectives of this class: 1. To provide a single point of access to all the chat providers. 2. To hide complexity introduced into the provider classes due to Pydantic models. 3. To provide a default provider and handler.

smarter.apps.prompt.providers.providers.CACHE_TIMEOUT = 10

Cache timeout in seconds for chat providers. This is to allow for short-term caching of provider instances. For now, this only benefits inner-process calls that lead to multiple instantiatiaons of the same provider within a short time frame.

However, the objective to to increase the cache timeout as observed usage patterns emerge that are confirmed to be cache safe.

class smarter.apps.prompt.providers.providers.ChatProviders(*args, **kwargs)[source]

Bases: SmarterHelperMixin

Collection of all the chat providers.

property all: list[str]
property all_handlers: Dict[str, HandlerProtocol]

A dictionary of all the handler callables. handlers must conform to HandlerProtocol.

property default: OpenAIChatProvider
default_handler(user, chat, data, plugins=None, functions=None)[source]

Expose the handler method of the default provider

Return type:

Union[dict, list]

get_cache_key(chat)[source]

Get the cache key for the chat object.

Return type:

str

get_handler(provider=None)[source]

A convenience method to get a handler by provider name.

Return type:

HandlerProtocol

property googleai: GoogleAIChatProvider
googleai_handler(user, chat, data, plugins=None, functions=None)[source]

Expose the handler method of the googleai provider

Return type:

Union[dict, list]

logger_helper(verb, msg)[source]
property metaai: MetaAIChatProvider
metaai_handler(user, chat, data, plugins=None, functions=None)[source]

Expose the handler method of the metaai provider

Return type:

Union[dict, list]

property openai: OpenAIChatProvider
openai_handler(user, chat, data, plugins=None, functions=None)[source]

Expose the handler method of the default provider

Return type:

Union[dict, list]

validate_chat(chat)[source]

Validate the chat object.

Return type:

None

smarter.apps.prompt.providers.providers.should_log(level)[source]

Check if logging should be done based on the waffle switch.

smarter.apps.prompt.providers.providers.should_log_caching(level)[source]

Check if logging should be done based on the waffle switch.