DRF Serializers

LLMClient serializers.

class smarter.apps.llmclient.serializers.LLMClientAPIKeySerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

An api key of an LLMClient.

api_key is the SmarterAuthToken’s public key_id. The token’s primary key is its digest, a hash of the key, which the api never returns.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

class smarter.apps.llmclient.serializers.LLMClientConfigSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Serializer for the smarter.apps.prompt.views.PromptConfigView which should not be camelCased.

get_default_system_role(obj)[source]

Return the LLMClient’s default system role, with the current date and time prepended.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.default_system_role_enhanced.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

get_total_tools(obj)[source]

The number of tools that the LLMClient adds to a prompt.

Counted, and cached until the LLMClient’s tools change, rather than serialized: Smarter Chat’s configuration api reads it on every page load.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The length of LLMClientSerializer.get_tools(): its extensions, plugins and MCPClients.

Return type:

int

class smarter.apps.llmclient.serializers.LLMClientCustomDomainListSerializer(*args, **kwargs)[source]

Bases: MetaDataWithOwnershipModelSerializer

A custom domain: the resource’s metadata and owner, the domain, the llmclient that it serves, and its DNS records.

Used by the Custom Domain list in the web console, and by the CustomDomain broker’s get.

get_dns_records(obj)[source]

Return the custom domain’s DNS records, ordered by record name.

Parameters:

obj (LLMClientCustomDomain) – The custom domain.

Returns:

One {"name", "type", "value", "ttl"} dict per LLMClientCustomDomainDNS row.

get_llmclient(obj)[source]

The llmclient that the domain serves, or None if no llmclient uses it.

get_manifest_url(obj)[source]

The URL of the custom domain’s detail view, which renders its manifest.

Return type:

str

class smarter.apps.llmclient.serializers.LLMClientCustomDomainSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

A custom domain of an LLMClient: every model field, plus its annotations, all read-only.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

class smarter.apps.llmclient.serializers.LLMClientExtensionsSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

An Extension of an LLMClient: the link row, and the Extension’s slug as its name.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

class smarter.apps.llmclient.serializers.LLMClientGuardrailMiniSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

A Guardrail of an LLMClient: the link’s id, and the Guardrail’s name.

class smarter.apps.llmclient.serializers.LLMClientMCPClientMiniSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

An MCPClient of an LLMClient: the link’s id, and the MCPClient’s name.

class smarter.apps.llmclient.serializers.LLMClientPluginMiniSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

A Plugin of an LLMClient: the link’s id, and the Plugin’s name.

class smarter.apps.llmclient.serializers.LLMClientPluginSerializer(*args, **kwargs)[source]

Bases: SmarterCamelCaseSerializer

A Plugin of an LLMClient: the link row, with its PluginMeta nested, all read-only.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

class smarter.apps.llmclient.serializers.LLMClientRequestsSerializer(*args, **kwargs)[source]

Bases: ModelSerializer

Serializer for the LLMClientRequests model.

class smarter.apps.llmclient.serializers.LLMClientSerializer(*args, **kwargs)[source]

Bases: MetaDataWithOwnershipModelSerializer

An LLMClient: every model field, its owner, its related resources, and its computed hosts and urls.

Every field is read-only. The related resources (extensions, plugins, MCPClients, guardrails, custom domains and api keys) are serialized as nested lists.

get_api_keys(obj)[source]

Return the LLMClient’s api keys.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The serialized LLMClientAPIKey rows.

get_base_api_domain(obj)[source]

Return the base api domain that the LLMClient’s default hostname uses.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.base_api_domain.

get_base_default_host(obj)[source]

Return the part of the LLMClient’s default hostname after its RFC 1034 compliant name.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.base_default_host.

get_custom_domains(obj)[source]

Return the LLMClient’s custom domain, as a list of zero or one.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The serialized custom domain in a list, or an empty list if it has none.

get_custom_host(obj)[source]

Return the LLMClient’s hostname on its custom domain.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.custom_host.

get_custom_url(obj)[source]

Return the LLMClient’s url on its custom domain.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.custom_url.

get_default_host(obj)[source]

Return the LLMClient’s default hostname.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.default_host.

get_default_system_role(obj)[source]

Return the LLMClient’s default system role, with the current date and time prepended.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.default_system_role_enhanced.

get_default_url(obj)[source]

Return the LLMClient’s default url.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.default_url.

get_extensions(obj)[source]

Return the LLMClient’s extensions, sorted by the Extension’s slug.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The serialized LLMClientExtensions rows.

get_fields()[source]

Return the serializer’s fields, each marked read-only.

Returns:

The fields, keyed by name.

get_guardrails(obj)[source]

Return the LLMClient’s guardrails.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

One {"id", "name"} per LLMClientGuardrails row.

get_hashed_id(obj)[source]

Return the LLMClient’s hashed id.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.hashed_id.

get_hostname(obj)[source]

Return the LLMClient’s hostname, which depends on its deployment status.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.hostname.

get_is_authentication_required(obj)[source]

Return whether the LLMClient’s api requires authentication.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.is_authentication_required.

get_manifest_url(obj)[source]

Return the url of the LLMClient’s manifest page in the web console.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.manifest_url.

get_mcpclients(obj)[source]

Return the LLMClient’s MCPClients.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

One {"id", "name"} per LLMClientMCPClients row.

get_plugins(obj)[source]

Return the LLMClient’s plugins.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

One {"id", "name"} per LLMClientPlugin row.

get_ready(obj)[source]

Return whether the LLMClient is ready: in sandbox mode, or deployed with verified DNS and an issued certificate.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.ready.

get_rfc1034_compliant_name(obj)[source]

Return the LLMClient’s RFC 1034 compliant name, used in its hostnames.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.rfc1034_compliant_name.

get_sandbox_host(obj)[source]

Return the LLMClient’s sandbox hostname.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.sandbox_host.

get_sandbox_url(obj)[source]

Return the LLMClient’s sandbox url.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.sandbox_url.

get_tools(obj)[source]

The tools that the LLMClient offers the LLM: its extensions, plugins and MCPClients.

Guardrails are left out: they constrain a prompt, but the LLM can’t call them.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

One {"id", "name", "kind"} per extension, plugin and MCPClient, in that order. id is the link row’s id, and kind is Extension or the linked resource’s manifest kind.

Return type:

list[dict]

get_url(obj)[source]

Return the LLMClient’s url, which depends on its deployment status.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.url.

get_url_chat_config(obj)[source]

Return the api url of the LLMClient’s chat configuration.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.url_chat_config.

get_url_chatapp(obj)[source]

Return the (deprecated) url of the LLMClient’s ChatApp endpoint.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.url_chatapp.

get_url_llmclient(obj)[source]

Return the api url that the chat app posts new prompts to.

Parameters:

obj (LLMClient) – The LLMClient.

Returns:

The value of obj.url_llmclient.