Brokers
Smarter API Proxy Manifest handler.
The broker implements the smarter CLI commands for Proxies:
apply: create or update the Proxy from its manifest.spec.providerandspec.apiKeyare resolved to the Provider and Secret of those names that the user may read.describe: the manifest, with the Proxy’s URL, and the URL and Secret it forwards with.get: the Proxies that the user may read, including the built-in ones.delete: delete the user’s Proxy.
Proxies are not deployed: they work as soon as they are applied. So deploy, undeploy,
logs and prompt are not implemented.
- class smarter.apps.proxy.manifest.brokers.proxy.SAMProxyBroker(*args, **kwargs)[source]
Bases:
AbstractBrokerBroker for
SAMProxy manifests.It converts between Proxy manifests and the
ProxyDjango ORM model.spec.provideris the name of a Provider that the manifest’s owner may read, e.g. a built-in one.spec.apiKeyis the name of a Secret of the owner’s account. The user’s own takes precedence. They are stored as foreign keys, and rendered as names, never the API key itself.- property ORMMetaModelClass: Type[Proxy]
Return the Django ORM meta model class for the broker.
- Returns:
The Django ORM meta model class definition for the broker.
- Return type:
- property ORMModelClass: Type[Proxy]
Return the Django ORM model class for the broker.
- Returns:
The Django ORM model class definition for the broker.
- Return type:
- property SerializerClass: Type[ModelSerializer]
The Django ORM model serializer class for the Proxy.
- apply(request, *args, **kwargs)[source]
Create or update the user’s Proxy from the manifest.
Note
tags are handled separately because they are of type TaggableManager and require a different method to set them.
- Return type:
- cache_invalidations()[source]
Invalidate the cached Proxy, and the user’s cached Proxy lists.
- Return type:
- delete(request, *args, **kwargs)[source]
Delete the user’s Proxy.
Its Provider and Secret are not deleted.
- Return type:
- deploy(request, *args, **kwargs)[source]
Deploy a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the deploy operation.
- Return type:
- describe(request, *args, **kwargs)[source]
Return the Proxy as a manifest: the user’s own, else their account’s, else the built-in one.
- Return type:
- django_orm_to_manifest_dict(proxy=None)[source]
Convert a Proxy, by default the user’s, into a manifest dict, with its status.
- example_manifest(request, *args, **kwargs)[source]
Return an example Proxy manifest, for Anthropic’s Messages API.
- Return type:
- get(request, *args, **kwargs)[source]
Return the Proxies that the user may read, optionally filtered by name.
- Return type:
- logs(request, *args, **kwargs)[source]
Get logs for a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the logs for the resource.
- Return type:
- property manifest: SAMProxy | None
The Proxy manifest, as a Pydantic model, from the manifest loader.
- prompt(request, *args, **kwargs)[source]
Invoke a prompt operation.
This abstract method should be implemented by subclasses to provide prompt-based interactions with the broker resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the prompt response.
- Return type:
- property proxy: Proxy | None
The user’s own Proxy with the broker’s name, if it exists.
It is never created here:
apply()does that.
- readable_proxy()[source]
The Proxy that the user means by the broker’s name: their own, else their account’s, else the built-in one.
describeuses it, so that users can read the built-in Proxies’ manifests.
- resolve_provider(name)[source]
The Provider named by spec.provider: the user’s own, else the most recently updated one that they may read.
- Return type:
- resolve_secret(name)[source]
The Secret named by spec.apiKey, or
Noneif it is not set: the user’s own, else their account’s.Unlike the Provider, the Secret must belong to the user’s account, so that a Proxy cannot send another account’s API key, e.g. the platform’s, to a base URL of its owner’s choosing. See
may_use_secret().
- undeploy(request, *args, **kwargs)[source]
Undeploy a resource.
- Parameters:
request (
HttpRequest) – The HTTP request object.args – Additional positional arguments.
kwargs – Additional keyword arguments.
- Returns:
A SmarterJournaledJsonResponse containing the result of the undeploy operation.
- Return type:
- exception smarter.apps.proxy.manifest.brokers.proxy.SAMProxyBrokerError(message=None, thing=None, command=None, stack_trace=None)[source]
Bases:
SAMBrokerErrorBase exception for Smarter API Proxy Broker handling.
- property get_formatted_err_message