Contract
The Smarter Chat api contract. See The Chat API Contract.
Pydantic models of the Smarter Chat api contract.
They describe the requests and responses of the configuration and prompt apis, and the prompt’s progress events.
These models are the contract’s single source of truth:
version 2 responses are built from them, by
smarter.apps.prompt.contract.builders,version 1 responses, which are built as before for older clients, are validated against them by the tests,
the JSON Schema in
chat-contract.schema.jsonis generated from them (manage.py export_chat_contract_schema), and Smarter Chat generates its TypeScript types from that schema, and validates its test fixtures against it.
No field is a bare list[Any] or dict[str, Any]: lists are of named models, and a value
that is stored as arbitrary JSON, e.g. a tool’s result, is a PromptChatApiJson, which is
exactly JSON. The models of Django ORM rows (PromptChatApiOrmModel) and of the session’s
history have exactly their fields. The LLMClient, the messages, the meta data and the completion
allow extra fields, which the LLM providers and the Console use, and which Smarter Chat displays as
is. Adding a field is backward compatible. Removing or renaming one that is declared here is not.
- smarter.apps.prompt.contract.models.CONTRACT_MODELS: tuple[type[BaseModel], ...] = (<class 'smarter.apps.prompt.contract.models.PromptChatApiMessage'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiErrorBody'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiErrorResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigRequest'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigResponseV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptRequest'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptResponseV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiCompletionV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiFailureV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProgressEvent'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProgressResult'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProviderRequestResponse'>)
The models whose JSON Schema is exported.
Their dependencies are exported with them.
( <class 'smarter.apps.prompt.contract.models.PromptChatApiMessage'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiErrorBody'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiErrorResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigRequest'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiConfigResponseV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptRequest'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptResponse'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiPromptResponseV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiCompletionV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiFailureV1'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProgressEvent'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProgressResult'>, <class 'smarter.apps.prompt.contract.models.PromptChatApiProviderRequestResponse'>, )
- smarter.apps.prompt.contract.models.LEGACY_KEY_RENAMES = (('llmclient', 'chatbot'), ('account_number', 'accountNumber'), ('prompt_history', 'chat_history'))
The key renames of version 1 of the configuration, for the versions of Smarter Chat that expect.
‘chatbot’ rather than ‘llmclient’. Each applies to every key that contains it, at every depth.
( ('llmclient', 'chatbot'), ('account_number', 'accountNumber'), ('prompt_history', 'chat_history'), )
- class smarter.apps.prompt.contract.models.PromptChatApiAudioPart(**data)[source]
Bases:
PromptChatApiModelA message’s audio part.
- input_audio: PromptChatApiInputAudio
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiChatbotV1(**data)[source]
Bases:
PromptChatApiLLMClientBaseThe LLMClient, in version 1 of the configuration, whose keys are renamed: llmclient becomes chatbot.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiChoice(**data)[source]
Bases:
PromptChatApiModelA choice of a chat completion.
- message: PromptChatApiMessage | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiCompletion(**data)[source]
Bases:
BaseModelThe LLM’s chat completion, in the format of the OpenAI api, with only these fields.
Smarter’s own additions,
smarterandmetadata, are not part of it: the messages, plugins and tools are inPromptChatApiPromptResult, andmetadata, which describes the tool calls with their plugins’ owners, is returned only to the cli.- choices: list[PromptChatApiChoice]
- model_config = {'extra': 'ignore'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- usage: PromptChatApiUsage | None
- class smarter.apps.prompt.contract.models.PromptChatApiCompletionV1(**data)[source]
Bases:
PromptChatApiModelThe parsed body of a successful prompt, version 1: a chat completion, with Smarter’s additions.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter: PromptChatApiSmarterCompletionV1
- class smarter.apps.prompt.contract.models.PromptChatApiConfig(**data)[source]
Bases:
PromptChatApiConfigBaseThe configuration, version 2.
PromptConfigView.config()builds one, from which every response is derived:public()for a deployed LLMClient’s own host, andto_v1()for older clients.- extensions: PromptChatApiExtensionList | None
- history: PromptChatApiHistory
- llmclient: PromptChatApiLLMClient
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugins: PromptChatApiPluginList
- public()[source]
The public configuration.
A deployed LLMClient’s own host returns it to the pages that embed Smarter Chat.
The LLMClient is reduced to
PUBLIC_LLMCLIENT_FIELDS, without e.g. its owner’s profile, the history to the session’s own messages, without the requests that Smarter sent to the LLM, the meta data toPUBLIC_META_DATA_FIELDS, and the plugins and extensions to their counts.- Returns:
A new configuration.
- Return type:
- to_v1()[source]
The same configuration, in version 1 of the contract.
Its keys are renamed at every depth: see
LEGACY_KEY_RENAMES.- Returns:
The version 1 configuration.
- Return type:
- class smarter.apps.prompt.contract.models.PromptChatApiConfigRequest(**data)[source]
Bases:
PromptChatApiModelThe configuration api’s request body.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiConfigResponse(**data)[source]
Bases:
PromptChatApiEnvelopeThe configuration api’s response, version 2.
- data: PromptChatApiConfig
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiConfigResponseV1(**data)[source]
Bases:
PromptChatApiEnvelopeThe configuration api’s response, version 1.
- data: PromptChatApiConfigV1
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiConfigV1(**data)[source]
Bases:
PromptChatApiConfigBaseThe configuration, version 1.
- chatbot: PromptChatApiChatbotV1
- extensions: PromptChatApiExtensionListV1 | None
- history: PromptChatApiHistoryV1
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugins: PromptChatApiPluginListV1
- smarter.apps.prompt.contract.models.PromptChatApiContentPart
A part of a message whose content is a list of parts, by its
type.alias of
Annotated[PromptChatApiTextPart|PromptChatApiImagePart|PromptChatApiAudioPart|PromptChatApiFilePart|PromptChatApiRefusalPart, FieldInfo(annotation=NoneType, required=True, discriminator=’type’)]
- class smarter.apps.prompt.contract.models.PromptChatApiEnvelope(**data)[source]
Bases:
PromptChatApiModelThe fields that every journaled response adds beside
data.- metadata: PromptChatApiJournalMetadata
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiErrorBody(**data)[source]
Bases:
PromptChatApiModelThe error of a failed request: the same shape for every error of the configuration and prompt apis.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiErrorResponse(**data)[source]
Bases:
PromptChatApiModelThe body of an error response of the configuration or prompt apis, in both versions of the contract.
- error: PromptChatApiErrorBody
- metadata: PromptChatApiJournalMetadata | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiExtensionList(**data)[source]
Bases:
PromptChatApiModelThe LLMClient’s extensions.
The list itself is returned only in the complete configuration, with
?verbose=true.- extensions: list[PromptChatApiLLMClientExtension]
- meta_data: PromptChatApiListMetaData
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiExtensionListV1(**data)[source]
Bases:
PromptChatApiModelThe LLMClient’s extensions, in version 1.
- extensions: list[PromptChatApiLLMClientExtensionV1]
- meta_data: PromptChatApiListMetaData
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiFailureV1(**data)[source]
Bases:
PromptChatApiModelThe parsed body of a failed prompt, version 1.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- response: PromptChatApiCompletionV1
- class smarter.apps.prompt.contract.models.PromptChatApiFilePart(**data)[source]
Bases:
PromptChatApiModelA message’s file part.
- file: PromptChatApiFileRef
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiFileRef(**data)[source]
Bases:
PromptChatApiModelThe file of a file part: its base64 data, or the id of an uploaded file.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiFunctionCall(**data)[source]
Bases:
PromptChatApiModelThe function that an assistant message calls.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiHistory(**data)[source]
Bases:
PromptChatApiHistoryBaseThe chat session’s history, in version 2.
Only
chat_historyis public.prompt_tool_call_historyis in the complete configuration with?verbose=true, and the other histories are returned only to the cli.- llmclient_request_history: list[PromptChatApiLLMClientRequest] | None
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiHistoryV1(**data)[source]
Bases:
PromptChatApiHistoryBaseThe chat session’s history, in version 1.
- chatbot_request_history: list[PromptChatApiLLMClientRequestV1] | None
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiImagePart(**data)[source]
Bases:
PromptChatApiModelA message’s image part.
- image_url: PromptChatApiImageUrl
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiImageUrl(**data)[source]
Bases:
PromptChatApiModelThe image of an image part: an http(s) or base64 data url.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiInputAudio(**data)[source]
Bases:
PromptChatApiModelThe audio of an audio part: base64 encoded.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiJournalMetadata(**data)[source]
Bases:
PromptChatApiModelThe journal’s record of a request, which every journaled response carries.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- type smarter.apps.prompt.contract.models.PromptChatApiJson = _AllowAnyJson]
A value that is stored, and returned, as arbitrary JSON: a string, number, boolean, null, or a.
list or object of them. It is used only where the value has no fixed shape, e.g. a tool’s result.
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClient(**data)[source]
Bases:
PromptChatApiLLMClientBaseThe LLMClient, in version 2 of the configuration.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientExtension(**data)[source]
Bases:
PromptChatApiOrmModelAn extension of the LLMClient: a
smarter.apps.llmclient.models.LLMClientExtensions.- classmethod from_model(link)[source]
The contract’s model of an extension of the LLMClient.
- Parameters:
link (
LLMClientExtensions) – The row, whoseextensionand itsinstalled_versionshould be fetched with it.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientExtensionV1(**data)[source]
Bases:
PromptChatApiOrmModelAn extension of the LLMClient, in version 1, whose
llmclientis renamedchatbot.- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientPlugin(**data)[source]
Bases:
PromptChatApiOrmModelA plugin of the LLMClient: a
smarter.apps.llmclient.models.LLMClientPlugin.- classmethod from_model(plugin)[source]
The contract’s model of a plugin of the LLMClient.
- Parameters:
plugin (
LLMClientPlugin) – The row, whoseplugin_metaand its tags should be prefetched.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugin_meta: PromptChatApiPluginMeta
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientPluginV1(**data)[source]
Bases:
PromptChatApiOrmModelA plugin of the LLMClient, in version 1, whose
llmclientis renamedchatbot.- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugin_meta: PromptChatApiPluginMeta
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientRequest(**data)[source]
Bases:
PromptChatApiOrmModelA request to the LLMClient’s prompt api: a
smarter.apps.llmclient.models.LLMClientRequests.- classmethod from_model(row)[source]
The contract’s model of a request to the LLMClient’s prompt api.
- Parameters:
row (
LLMClientRequests) – The row.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- request: PromptChatApiPromptRequest | None
- class smarter.apps.prompt.contract.models.PromptChatApiLLMClientRequestV1(**data)[source]
Bases:
PromptChatApiOrmModelA request to the LLMClient’s prompt api, in version 1, whose
llmclientis renamedchatbot.- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- request: PromptChatApiPromptRequest | None
- class smarter.apps.prompt.contract.models.PromptChatApiLambdaResponseV1(**data)[source]
Bases:
PromptChatApiModelA prompt’s result, version 1: an AWS Lambda style response, whose body is a JSON string.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiListMetaData(**data)[source]
Bases:
PromptChatApiModelThe counts of a list of the LLMClient’s plugins or extensions.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiMessage(**data)[source]
Bases:
PromptChatApiModelA message, in the format of the OpenAI chat completion api.
Smarter adds two roles, which are only displayed and never sent to an LLM:
smarter, a note about what the backend did, andsmarter_error, a failed prompt’s error.- content: str | list[Annotated[PromptChatApiTextPart | PromptChatApiImagePart | PromptChatApiAudioPart | PromptChatApiFilePart | PromptChatApiRefusalPart, FieldInfo(annotation=NoneType, required=True, discriminator='type')]] | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- tool_calls: list[PromptChatApiToolCall] | None
- class smarter.apps.prompt.contract.models.PromptChatApiMetaData(**data)[source]
Bases:
PromptChatApiModelThe LLMClient’s state.
The complete configuration, with
?verbose=true, adds the rest ofLLMClientHelper.to_json().- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiOrmModel(**data)[source]
Bases:
BaseModelBase class of the contract’s models of Django ORM rows.
Their fields are exactly the rows’ fields, so extra fields are forbidden. Each is built from its row by
from_model().- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.apps.prompt.contract.models.PromptChatApiPluginClass
the choices of
PluginMeta.plugin_class.See
PluginMeta.PLUGIN_CLASSES.- Type:
A plugin’s class
alias of
Literal[‘api’, ‘skill’, ‘sql’, ‘static’, ‘websearch’, ‘imagesearch’]
- class smarter.apps.prompt.contract.models.PromptChatApiPluginList(**data)[source]
Bases:
PromptChatApiModelThe LLMClient’s plugins.
The list itself is returned only in the complete configuration, with
?verbose=true.- meta_data: PromptChatApiListMetaData
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugins: list[PromptChatApiLLMClientPlugin]
- class smarter.apps.prompt.contract.models.PromptChatApiPluginListV1(**data)[source]
Bases:
PromptChatApiModelThe LLMClient’s plugins, in version 1.
- meta_data: PromptChatApiListMetaData
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- plugins: list[PromptChatApiLLMClientPluginV1]
- class smarter.apps.prompt.contract.models.PromptChatApiPluginMeta(**data)[source]
Bases:
PromptChatApiOrmModelA plugin’s metadata: a
smarter.apps.llmtool.models.PluginMeta.Its owner is left out: the configuration never includes a user’s profile.
- classmethod from_model(plugin_meta)[source]
The contract’s model of a plugin’s metadata.
- Parameters:
plugin_meta (
PluginMeta) – The row, whose tags should be prefetched.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPluginSelection(**data)[source]
Bases:
PromptChatApiOrmModelA plugin selector’s activation: a
smarter.apps.llmtool.models.PluginSelectorHistory.- classmethod from_model(row)[source]
The contract’s model of a plugin selector’s activation.
- Parameters:
row (
PluginSelectorHistory) – The row.- Returns:
The model.
- Return type:
- messages: list[PromptChatApiMessage] | None
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiProgressEvent(**data)[source]
Bases:
PromptChatApiModelThe data of a
progressevent: a step of a running prompt.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- smarter.apps.prompt.contract.models.PromptChatApiProgressEventType
The
typeof a progress event.See
smarter.apps.prompt.progress.PromptProgressEvents.alias of
Literal[‘llm_request’, ‘tool_requested’, ‘tool_responded’, ‘plugin_called’, ‘mcp_tool_called’, ‘mcp_tool_responded’, ‘mcp_tool_failed’]
- class smarter.apps.prompt.contract.models.PromptChatApiProgressResult(**data)[source]
Bases:
PromptChatApiModelThe data of the final
resultevent.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptPluginUsage(**data)[source]
Bases:
PromptChatApiOrmModelA plugin that the chat session used: a
smarter.apps.prompt.models.PromptPluginUsage.- classmethod from_model(row)[source]
The contract’s model of a plugin that the chat session used.
- Parameters:
row (
PromptPluginUsage) – The row.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptRequest(**data)[source]
Bases:
PromptChatApiModelThe prompt api’s request body: the chat thread, with only the roles that LLMs accept.
- messages: list[PromptChatApiMessage]
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptResponse(**data)[source]
Bases:
PromptChatApiEnvelopeThe prompt api’s response, version 2.
A failed prompt has
errortoo, and its http status is the LLM provider’s. Itsdata.messagesinclude asmarter_errormessage, which is also saved in the session’s history.- error: PromptChatApiErrorBody | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptResponseV1(**data)[source]
Bases:
PromptChatApiEnvelopeThe prompt api’s response, version 1.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptResult(**data)[source]
Bases:
PromptChatApiModelThe result of a prompt, version 2.
- completion: PromptChatApiCompletion | None
- messages: list[PromptChatApiMessage]
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiPromptToolCall(**data)[source]
Bases:
PromptChatApiOrmModelA tool call of the chat session: a
smarter.apps.prompt.models.PromptToolCall.- classmethod from_model(row)[source]
The contract’s model of a tool call of the chat session.
- Parameters:
row (
PromptToolCall) – The row.- Returns:
The model.
- Return type:
- model_config = {'extra': 'forbid'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiProviderErrorV1(**data)[source]
Bases:
PromptChatApiModelThe LLM provider’s error, version 1.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiProviderRequest(**data)[source]
Bases:
PromptChatApiModelThe chat session’s conversation, as the request body that Smarter sends to the LLM provider.
It is a request to an OpenAI-compatible
v1/chat/completionsapi, without any of Smarter’s own content: nosmarterorsmarter_errormessages, nosmarter_*fields, no api url or key. It can be sent with curl, or pasted into the Prompt Passthrough page. Its messages are the whole conversation, including the latest answer, so that a prompt engineer can add the next user message. Its model, temperature, token limit and tools are those of the session’s latest prompt, or the LLMClient’s, before its first prompt.The provider request api,
/api/v1/llm-clients/<hashed_id>/provider-request/, returns it, to the workbench only. Fields without a value are left out.- messages: list[PromptChatApiMessage]
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiProviderRequestResponse(**data)[source]
Bases:
PromptChatApiEnvelopeThe provider request api’s response.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiRefusalPart(**data)[source]
Bases:
PromptChatApiModelAn assistant message’s refusal part.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiSmarterCompletionV1(**data)[source]
Bases:
PromptChatApiModelSmarter’s additions to a completion, version 1.
- messages: list[PromptChatApiMessage]
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiStyleSection(**data)[source]
Bases:
PromptChatApiModelA section of the LLMClient’s styles: the colors of one of chatscope’s components.
A section has only the settings that its component has, in the manifest’s
spec.config.styles. Seesmarter.apps.llmclient.manifest.models.llmclient.styles.- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiStyles(**data)[source]
Bases:
PromptChatApiModelThe look of the LLMClient’s chat: its manifest’s
spec.config.styles, with snake_case keys.Smarter Chat applies it as css custom properties. Every setting is optional, and one that is left out keeps the chat’s default.
- buttons: PromptChatApiStyleSection | None
- conversation_header: PromptChatApiStyleSection | None
- incoming_message: PromptChatApiStyleSection | None
- main_container: PromptChatApiStyleSection | None
- message_input: PromptChatApiStyleSection | None
- message_list: PromptChatApiStyleSection | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- outgoing_message: PromptChatApiStyleSection | None
- typing_indicator: PromptChatApiStyleSection | None
- class smarter.apps.prompt.contract.models.PromptChatApiTextPart(**data)[source]
Bases:
PromptChatApiModelA message’s text part, in the format of the OpenAI chat completion api.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiTokenDetails(**data)[source]
Bases:
PromptChatApiModelThe breakdown of a completion’s tokens.
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiToolCall(**data)[source]
Bases:
PromptChatApiModelA tool call of an assistant message, in the format of the OpenAI chat completion api.
- function: PromptChatApiFunctionCall
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class smarter.apps.prompt.contract.models.PromptChatApiUsage(**data)[source]
Bases:
PromptChatApiModelA chat completion’s token usage.
- completion_tokens_details: PromptChatApiTokenDetails | None
- model_config = {'extra': 'allow'}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- prompt_tokens_details: PromptChatApiTokenDetails | None
- smarter.apps.prompt.contract.models.legacy_key_names(value)[source]
A value whose dict keys are renamed for version 1.
See
LEGACY_KEY_RENAMES.- Parameters:
value (
TypeAliasType) – A JSON value: a dict or a list is renamed, anything else is returned as is.- Returns:
The value, with its keys renamed at every depth.
- Return type:
TypeAliasType
Builders of the Smarter Chat api contract’s responses.
The configuration view builds a PromptChatApiConfig, whose methods derive its responses.
These functions serve both views, and turn a prompt’s result into what the client receives:
requested_contract()reads the version of the contract that the client asked for.without_diagnostics()removes the complete LLM requests and responses from a prompt’s result.prompt_result_v2()turns a prompt’s result into version 2.chat_error_response()is the one error response of both apis.
- exception smarter.apps.prompt.contract.builders.PromptChatApiError(message)[source]
Bases:
ExceptionThe base class of the errors that the configuration and prompt apis return.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorBadRequest(message)[source]
Bases:
PromptChatApiErrorThe request is malformed, e.g. a prompt without a body.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorForbidden(message)[source]
Bases:
PromptChatApiErrorThe LLMClient requires authentication, and the client didn’t provide it.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorInternal(message)[source]
Bases:
PromptChatApiErrorAn unexpected error.
Its details are logged, never returned.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorLLMProvider(message)[source]
Bases:
PromptChatApiErrorThe LLM provider rejected the prompt.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorNotFound(message)[source]
Bases:
PromptChatApiErrorThe LLMClient doesn’t exist, or the client may not use it.
- exception smarter.apps.prompt.contract.builders.PromptChatApiErrorNotReady(message)[source]
Bases:
PromptChatApiErrorThe LLMClient exists, but can’t be initialized.
- smarter.apps.prompt.contract.builders.chat_error_response(request, error, thing, command)[source]
The error response of the configuration and prompt apis.
It is a
PromptChatApiErrorResponse, the same shape in both versions of the contract, without a stack trace.- Parameters:
request (
HttpRequest) – The api’s request.error (
PromptChatApiError) – The error, whose class name, message and status the response describes.thing (
SmarterJournalThings) – The journal’s thing.command (
SmarterJournalCliCommands) – The journal’s command.
- Returns:
The error response.
- Return type:
- smarter.apps.prompt.contract.builders.prompt_result_v2(response)[source]
A prompt’s result, in version 2 of the contract.
- Parameters:
response (
Any) – A prompt’s Lambda style result, as the provider’s handler returns it.- Returns:
The response’s
data(aPromptChatApiPromptResult), itserror(aPromptChatApiErrorBody, or None if the prompt succeeded), and its http status.- Return type:
- smarter.apps.prompt.contract.builders.requested_contract(request)[source]
The version of the contract that the client receives.
- Parameters:
request (
HttpRequest|None) – The configuration or prompt api’s request.- Returns:
CHAT_CONTRACT_V2, the default, unless theX-Smarter-Capabilitiesheader listschat-contract-v1(and notchat-contract-v2), or the client is a version of Smarter Chat that lists no contract capability, which reads version 1 only.- Return type:
- smarter.apps.prompt.contract.builders.without_diagnostics(response)[source]
A prompt’s result without the complete requests to and responses from the LLM.
The provider adds them to the completion’s
smarterobject, asDIAGNOSTIC_COMPLETION_KEYS, for thesmartercli. They include the system prompt and every tool result, so a browser never receives them. Nor does it receive the completion’smetadata(DIAGNOSTIC_COMPLETION_TOP_KEYS), whose tool calls describe each plugin with its owner’s profile.
Constants of the Smarter Chat api contract.
The contract is versioned. Version 2 is the default. Version 1, the original shape, is deprecated, and returned only to clients that need it:
a client that asks for it, with
chat-contract-v1in theX-Smarter-Capabilitiesrequest header, a comma-separated list of the capabilities that the client supports,Smarter Chat (
X-Smarter-Client: @smarter.sh/ui-chat) when it lists no contract capability, which is what its versions up to 0.7 do, so that the pages that installed them keep working,the
smartercli’s prompt, whose output its clients parse.
A client may also ask for version 2 explicitly, with chat-contract-v2, as Smarter Chat does. The
header is in CORS_ALLOW_HEADERS on every Smarter platform, so a new client can send it to an
older platform, which ignores it.
- smarter.apps.prompt.contract.const.CAPABILITIES_HEADER = 'HTTP_X_SMARTER_CAPABILITIES'
request.METAkey of theX-Smarter-Capabilitiesrequest header.
- smarter.apps.prompt.contract.const.CHAT_CONTRACT_V1: Final = 1
the original contract, with legacy key names, and the prompt’s completion as a JSON.
string.
typing_extensions.deprecatedcan’t mark a constant (PEP 702 covers classes and functions only), so every version 1 model, andto_v1(), is marked instead.- Type:
Deprecated
- smarter.apps.prompt.contract.const.CHAT_CONTRACT_V1_CAPABILITY = 'chat-contract-v1'
The capability with which a client asks for the deprecated version 1 of the contract.
- smarter.apps.prompt.contract.const.CHAT_CONTRACT_V2: Final = 2
plain key names, and the prompt’s messages and completion as JSON.
- Type:
The current contract
- smarter.apps.prompt.contract.const.CHAT_CONTRACT_V2_CAPABILITY = 'chat-contract-v2'
The capability with which a client asks for version 2 of the contract.
- smarter.apps.prompt.contract.const.CLIENT_HEADER = 'HTTP_X_SMARTER_CLIENT'
request.METAkey of theX-Smarter-Clientrequest header.
- smarter.apps.prompt.contract.const.DEFAULT_CHAT_CONTRACT = 2
The version of the contract that a client receives unless it needs version 1.
- smarter.apps.prompt.contract.const.DIAGNOSTIC_COMPLETION_KEYS = ('first_iteration', 'second_iteration')
The keys of a completion’s
smarterobject that hold the complete LLM requests and responses.They are returned only to the
smartercli, never to a browser.('first_iteration', 'second_iteration')
- smarter.apps.prompt.contract.const.DIAGNOSTIC_COMPLETION_TOP_KEYS = ('metadata',)
metadatadescribes the.prompt’s tool calls with each plugin’s
PluginMeta, including its owner’s profile.('metadata', )
- Type:
The keys of a completion that are returned only to the
smartercli
- smarter.apps.prompt.contract.const.EXAMPLE_PATH = '/Users/mcdaniel/Desktop/gh/smarter-sh/smarter/smarter/smarter/apps/prompt/contract/chat-contract.example.json'
An example JSON of each of the contract’s models, generated by
smarter.apps.prompt.contract.example.
- smarter.apps.prompt.contract.const.LEGACY_CHAT_CLIENT = '@smarter.sh/ui-chat'
The
X-Smarter-Clientof Smarter Chat.Its versions that list no contract capability, up to 0.7, read version 1 only.
- smarter.apps.prompt.contract.const.PUBLIC_LLMCLIENT_FIELDS = ('id', 'name', 'description', 'version', 'deployed', 'provider', 'default_model', 'default_system_role', 'app_name', 'app_assistant', 'app_welcome_message', 'app_example_prompts', 'app_placeholder', 'app_info_url', 'app_file_attachment', 'total_tools', 'styles', 'url_llmclient')
The LLMClient fields of the public configuration.
The public configuration is returned by a deployed LLMClient’s own host, which pages that embed Smarter Chat call. Workbench and platform api urls, and the cli, receive every field.
( 'id', 'name', 'description', 'version', 'deployed', 'provider', 'default_model', 'default_system_role', 'app_name', 'app_assistant', 'app_welcome_message', 'app_example_prompts', 'app_placeholder', 'app_info_url', 'app_file_attachment', 'total_tools', 'styles', 'url_llmclient', )
- smarter.apps.prompt.contract.const.PUBLIC_META_DATA_FIELDS = ('ready', 'is_valid', 'is_deployed', 'is_custom_domain', 'is_authentication_required')
The
meta_datafields of the public configuration.( 'ready', 'is_valid', 'is_deployed', 'is_custom_domain', 'is_authentication_required', )
- smarter.apps.prompt.contract.const.SCHEMA_PATH = '/Users/mcdaniel/Desktop/gh/smarter-sh/smarter/smarter/smarter/apps/prompt/contract/chat-contract.schema.json'
The JSON Schema of the contract, generated from
smarter.apps.prompt.contract.models.
- smarter.apps.prompt.contract.const.VERBOSE_PARAMETER = 'verbose'
?verbose=true.Without it, the configuration has what a chat needs: the LLMClient, its state, the session’s messages, and the counts of its plugins and extensions. With it, a client that may read the LLMClient also receives the session’s tool calls, the complete
meta_data, and the lists of plugins and extensions, which the workbench’s Console displays. A deployed LLMClient’s own host ignores it.- Type:
The configuration api’s query parameter that asks for its diagnostic parts
- smarter.apps.prompt.contract.const.VERBOSE_VALUES = ('true', '1', 'yes')
The values of
VERBOSE_PARAMETERthat ask for the diagnostic parts, in lower case.('true', '1', 'yes')
The JSON Schema of the Smarter Chat api contract, generated from its Pydantic models.
manage.py export_chat_contract_schema writes it to chat-contract.schema.json, beside this
module, and a test fails if the committed file is out of date. Smarter Chat keeps a copy of it, from
which it generates its TypeScript types, and against which it validates its test fixtures.
- smarter.apps.prompt.contract.schema.chat_contract_schema()[source]
The contract’s JSON Schema (draft 2020-12): one definition, in
$defs, per model.
- smarter.apps.prompt.contract.schema.chat_contract_schema_json()[source]
The contract’s JSON Schema, as the text of
chat-contract.schema.json.- Returns:
The schema, as indented JSON, with a final newline.
- Return type:
- smarter.apps.prompt.contract.schema.write_chat_contract_schema(path='/Users/mcdaniel/Desktop/gh/smarter-sh/smarter/smarter/smarter/apps/prompt/contract/chat-contract.schema.json')[source]
Write the contract’s JSON Schema.
An example JSON of each model of the Smarter Chat api contract, generated from its JSON Schema.
manage.py export_chat_contract_example writes it to chat-contract.example.json, beside this
module, and a test fails if the committed file is out of date. Every example validates against its
model. Each declares all of its model’s fields, including the optional ones, so that it shows the
model’s complete shape. Its values are placeholders: a string is its field’s name, a number is 0, and
a choice is the first one.
- smarter.apps.prompt.contract.example.chat_contract_example()[source]
An example of each of
CONTRACT_MODELS, by the model’s name.
- smarter.apps.prompt.contract.example.chat_contract_example_json()[source]
The contract’s examples, as the text of
chat-contract.example.json.- Returns:
The examples, as indented JSON, with a final newline.
- Return type: