Provider Model

Verification functions for provider models in the Smarter app.

These functions are responsible for verifying various capabilities of provider models, such as streaming, tools, text input, image input, audio input, fine-tuning, search, code interpreter, text to image, text to audio, text to text, translation, and summarization. Each verification function checks if the capability is already verified and valid. If not, it performs a test to verify the capability and updates the verification status accordingly.

smarter.apps.provider.verification.provider_model.ACCOUNT_POLICY_ERROR_MARKERS = ('third_party_data_sharing_blocked',)

Error codes of a provider error that blames a setting of the account, not the model, whatever its status code.

Together AI, for example, answers a 403 third_party_data_sharing_blocked for a model that it serves through a third party until the organization enables third-party data sharing. The model works once the setting is on.

('third_party_data_sharing_blocked', )
smarter.apps.provider.verification.provider_model.BILLING_ERROR_MARKERS = ('credit balance', 'billing', 'insufficient_quota', 'exceeded your current quota')

Text of a provider error that blames the account’s credit or quota, whatever its status code.

(
    'credit balance',
    'billing',
    'insufficient_quota',
    'exceeded your current quota',
)
smarter.apps.provider.verification.provider_model.INCONCLUSIVE_STATUS_CODES = (401, 402, 408, 429)

Provider http status codes, besides 5xx, that describe the account or the provider rather than the model.

(401, 402, 408, 429)
exception smarter.apps.provider.verification.provider_model.ProviderModelVerificationInconclusive[source]

Bases: Exception

Raised by a check when its provider’s error says nothing about the model.

An invalid api key, an account without credit, a rate limit, a provider outage or a network error makes every model of the provider fail, working or not. verify_provider_model() catches it, and leaves the model’s verifications and its is_active as they were.

smarter.apps.provider.verification.provider_model.VERIFICATION_MAX_COMPLETION_TOKENS = 1024

The completion budget of the checks that read the model’s answer.

Reasoning models spend their budget on reasoning tokens first, and return no text at all when it runs out, so a budget of a few tokens fails them.

smarter.apps.provider.verification.provider_model.completion_text(response)[source]

Return the stripped text of a chat completion’s first choice.

The content is usually a string. Some providers return a list of typed parts instead, whose text parts are joined (see content_part_text()).

Parameters:

response – A chat completion.

Return type:

str

Returns:

The text, or an empty string when the message has none, as when a reasoning model runs out of tokens.

smarter.apps.provider.verification.provider_model.content_part_text(part)[source]

Return the text of one part of a message’s content, or an empty string if it is not a text part.

Some providers, e.g. Mistral, return a message’s content as a list of typed parts, such as {"type": "thinking", ...} and {"type": "text", "text": "..."}. The openai client passes them on as dicts, or as objects with attributes.

Parameters:

part – One part of the content, a dict or an object.

Return type:

str

Returns:

The part’s text, if its type is text, and otherwise an empty string.

smarter.apps.provider.verification.provider_model.log_check_failure(check, provider_model, error)[source]

Log that one of a provider model’s checks failed.

A provider’s http error (an APIStatusError, such as a 404 for a retired model) is an expected answer, so it is logged with its message and without a traceback. Any other exception gets the traceback, since it may be a bug in the check itself.

Parameters:
Return type:

None

smarter.apps.provider.verification.provider_model.provider_api_key(provider_model)[source]

Return the api key of a model’s Provider, for a check’s call to the provider.

Parameters:

provider_model (ProviderModel) – The model that is checked.

Return type:

str | None

Returns:

The decrypted api key, or None if its Secret has no value.

Raises:

SmarterValueError – if the Provider has no api key Secret, which the check’s except handles as a failed check.

smarter.apps.provider.verification.provider_model.raise_if_inconclusive(error)[source]

Raise ProviderModelVerificationInconclusive if error is about the account or the provider, not the model.

Anthropic, for example, reports an account without credit as a 400 invalid_request_error, so the error’s text is checked as well as its status code.

Parameters:

error (Exception) – The exception that a check’s call to the provider raised.

Raises:

ProviderModelVerificationInconclusive – if the error does not show that the model fails the check.

Return type:

None

smarter.apps.provider.verification.provider_model.should_log(level)[source]

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

smarter.apps.provider.verification.provider_model.verify_model_audio_input(provider_model, **kwargs)[source]

Verify audio input capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_code_interpreter(provider_model, **kwargs)[source]

Verify code interpreter capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_fine_tuning(provider_model, **kwargs)[source]

Verify fine-tuning capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_image_input(provider_model, **kwargs)[source]

Verify image input capabilities of the provider model.

Return type:

bool

Verify search capabilities of the provider model.

DEPRECATED: OpenAI has deprecated the search endpoint.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_streaming(provider_model, **kwargs)[source]

Verify streaming capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_summarization(provider_model, **kwargs)[source]

Verify summarization capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_text_input(provider_model, **kwargs)[source]

Verify text input capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_text_to_audio(provider_model, **kwargs)[source]

Verify text to audio capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_text_to_image(provider_model, **kwargs)[source]

Verify text to image capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_text_to_text(provider_model, **kwargs)[source]

Verify text to text capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_tools(provider_model, **kwargs)[source]

Verify tools capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_model_translation(provider_model, **kwargs)[source]

Verify translation capabilities of the provider model.

Return type:

bool

smarter.apps.provider.verification.provider_model.verify_provider_model(provider_model_id, **kwargs)[source]

Run every check that the provider model’s supports_* fields call for, then activate or deactivate it.

A model that passes every check is activated, and one that fails any is deactivated. When a check’s provider error is about the account or the provider rather than the model (see raise_if_inconclusive()), the run stops and the model is left as it was.

Parameters:

provider_model_id – The id of the ProviderModel to verify.