Views

LLMClient api/v1/llmclients CRUD views.

class smarter.apps.llmclient.api.v1.views.views.LLMClientAPIKeyListView(*args, **kwargs)[source]

Bases: ListViewBase

LLMClientAPIKey list view for smarter api.

contract_model

alias of LLMClientApiKey

get_queryset(*args, **kwargs)[source]

Return the api keys of the account’s LLMClient named by the url’s llmclient_id.

Returns:

The LLMClientAPIKey rows, with their tokens.

Raises:

Http404 – when the account has no such LLMClient.

serializer_class

alias of LLMClientAPIKeySerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientAPIKeyView(*args, **kwargs)[source]

Bases: ViewBase

LLMClientAPIKey view for smarter api.

delete(request, llmclient_id, apikey_id)[source]

Unlink an api key from the account’s LLMClient, and redirect to the list url.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • apikey_id (int) – The id of the LLMClientAPIKey.

Returns:

A redirect to the list url, or a 500 response if the delete fails.

get(request, llmclient_id, apikey_id)[source]

Return an api key of the account’s LLMClient as an LLMClientApiKey.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • apikey_id (int) – The id of the LLMClientAPIKey.

Returns:

The api key’s json, or 404 if the LLMClient or api key is not found.

post(request, llmclient_id, apikey_id=None)[source]

Link a SmarterAuthToken to the account’s LLMClient, and redirect to the new link.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • apikey_id (int | None) – The primary key of the SmarterAuthToken.

Returns:

A redirect to the new LLMClientAPIKey; 404 if the LLMClient or token is not found; 400 if the link could not be created.

serializer_class

alias of LLMClientAPIKeySerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientCustomDomainListView(*args, **kwargs)[source]

Bases: ListViewBase

LLMClientCustomDomain list view for smarter api.

contract_model

alias of LLMClientApiCustomDomain

get_queryset(*args, **kwargs)[source]

Return the custom domain of the account’s LLMClient named by the url’s llmclient_id.

Returns:

The LLMClientCustomDomain rows, zero or one.

Raises:

Http404 – when the account has no such LLMClient.

serializer_class

alias of LLMClientCustomDomainSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientCustomDomainView(*args, **kwargs)[source]

Bases: ViewBase

LLMClientCustomDomain view for smarter api.

delete(request, llmclient_id, customdomain_id)[source]

Detach the custom domain from the LLMClient.

The domain itself is kept: LLMClient.custom_domain is on_delete=CASCADE, so deleting the domain would delete the LLMClient too.

get(request, llmclient_id, customdomain_id)[source]

Return the account LLMClient’s custom domain as an LLMClientApiCustomDomain.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • customdomain_id (int) – The id of the LLMClientCustomDomain.

Returns:

The custom domain’s json, or 404 if the LLMClient does not use that domain.

post(request, llmclient_id, customdomain_id)[source]

Attach the custom domain to the LLMClient, through LLMClient.custom_domain.

If the LLMClient is deployed and the domain is verified, queues deploy_custom_api() to serve it on its custom host.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient, which must belong to the user’s account.

  • customdomain_id (int) – The id of the LLMClientCustomDomain.

Returns:

A redirect to the request’s url, or a 409 response if another LLMClient uses the domain.

serializer_class

alias of LLMClientCustomDomainSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientDeployView(*args, **kwargs)[source]

Bases: ViewBase

LLMClient deployment view for smarter api.

post(request, llmclient_id)[source]

Mark the account’s LLMClient deployed, and save it.

Saving it sends the LLMClient’s signals, whose receivers deploy it.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

Returns:

An empty 200 response, or 400 if the save fails.

serializer_class

alias of LLMClientSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientExtensionsListView(*args, **kwargs)[source]

Bases: ListViewBase

LLMClientExtensions list view for smarter api.

contract_model

alias of LLMClientApiExtension

get_queryset(*args, **kwargs)[source]

Return the extensions of the account’s LLMClient named by the url’s llmclient_id, sorted by slug.

Returns:

The LLMClientExtensions rows, with their Extensions.

Raises:

Http404 – when the account has no such LLMClient.

serializer_class

alias of LLMClientExtensionsSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientExtensionsView(*args, **kwargs)[source]

Bases: ViewBase

LLMClientExtensions view for smarter api.

delete(request, llmclient_id, extension_id)[source]

Remove an extension from the account’s LLMClient, and redirect to the list url.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • extension_id (int) – The id of the LLMClientExtensions link row.

Returns:

A redirect to the list url, or a 500 response if the delete fails.

get(request, llmclient_id, extension_id)[source]

Return an extension of the account’s LLMClient as an LLMClientApiExtension.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • extension_id (int) – The id of the LLMClientExtensions link row.

Returns:

The extension’s json, or 404 if the LLMClient or link is not found.

serializer_class

alias of LLMClientExtensionsSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientListView(*args, **kwargs)[source]

Bases: ListViewBase

LLMClient list view for smarter api.

dispatch(request, *args, **kwargs)[source]

Dispatch the request, then, if it succeeded, set llmclients to those the user can read.

Parameters:

request (HttpRequest) – The request.

Returns:

The response.

get_queryset(*args, **kwargs)[source]

Return the LLMClients that the user has read permission for.

Returns:

The LLMClients.

item(row)[source]

An LLMClient of the response, whose canDelete is the requesting user’s.

llmclients: QuerySet[LLMClient] | None
serializer_class

alias of LLMClientSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientPluginListView(*args, **kwargs)[source]

Bases: ListViewBase

LLMClientPlugin list view for smarter api.

get_queryset(*args, **kwargs)[source]

Return the plugins of the account’s LLMClient named by the url’s llmclient_id.

Returns:

The LLMClientPlugin rows.

Raises:

Http404 – when the account has no such LLMClient.

item(row)[source]

A plugin of the response, whose canDelete is the requesting user’s.

serializer_class

alias of LLMClientPluginSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientPluginView(*args, **kwargs)[source]

Bases: ViewBase

LLMClientPlugin view for smarter api.

delete(request, llmclient_id, plugin_id)[source]

Remove a plugin from the account’s LLMClient, and redirect to the list url.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • plugin_id (int) – The id of the LLMClientPlugin.

Returns:

A redirect to the list url, or a 500 response if the delete fails.

get(request, llmclient_id, plugin_id)[source]

Return a plugin of the account’s LLMClient as an LLMClientApiPlugin.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int) – The id of the LLMClient.

  • plugin_id (int) – The id of the LLMClientPlugin.

Returns:

The plugin’s json, or 404 if the LLMClient or plugin is not found.

patch(request, llmclient_id, plugin_id)[source]

Reload a plugin of the account’s LLMClient from the request’s json body, and redirect to it.

Parameters:
  • request (Request) – The request, whose body is json.

  • llmclient_id (int) – The id of the LLMClient.

  • plugin_id (int) – The id of the LLMClientPlugin.

Returns:

A redirect to the plugin, or a 400 response if the body is invalid.

post(request, llmclient_id)[source]

Add a plugin to the account’s LLMClient, from the request’s data, and redirect to it.

Parameters:
  • request (Request) – The request, whose data is passed to LLMClientPlugin.load().

  • llmclient_id (int) – The id of the LLMClient.

Returns:

A redirect to the new LLMClientPlugin, or a 400 response if it could not be loaded.

serializer_class

alias of LLMClientPluginSerializer

class smarter.apps.llmclient.api.v1.views.views.LLMClientView(*args, **kwargs)[source]

Bases: ViewBase

LLMClient view for smarter api.

delete(request, *args, llmclient_id=None, **kwargs)[source]

Delete the LLMClient, and redirect to the list url.

A superuser can delete any LLMClient by llmclient_id; anyone else deletes the view’s LLMClient.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int | None) – The id of the LLMClient.

Returns:

A redirect to the list url, or a 500 response if the delete fails.

dispatch(request, *args, **kwargs)[source]

Pop hashed_id from the url kwargs, then dispatch the request.

Parameters:

request (HttpRequest) – The request.

Returns:

The response.

get(request, llmclient_id=None)[source]

Return the LLMClient as an LLMClientApiLLMClient.

Parameters:
  • request (Request) – The request.

  • llmclient_id (int | None) – The id of the LLMClient. Unused: initial() has already found it.

Returns:

The LLMClient’s json.

Raises:

NotFound – when the url identifies no LLMClient.

get_queryset(*args, **kwargs)[source]

Return a queryset of the view’s LLMClient.

Returns:

The LLMClient found by initial(), as a one-row queryset.

hashed_id: str | None = None
initial(request, *args, **kwargs)[source]

Find the LLMClient, after DRF has authenticated the request and before the handler runs.

llmclient: LLMClient | None = None
llmclient_id: int | None = None
patch(request, *args, llmclient_id=None, **kwargs)[source]

Set the request’s fields on the LLMClient, save it, and redirect to its detail url.

Keys that are not attributes of the LLMClient are ignored.

Parameters:
  • request (Request) – The request, whose data is a json dict of field values.

  • llmclient_id (int | None) – The id of the LLMClient. Unused: initial() has already found it.

Returns:

A redirect to the LLMClient; 404 if there is none; 400 if the data is not a dict or fails validation; 500 if the save fails.

post(request, *args, **kwargs)[source]

Create an LLMClient from the request’s data, and redirect to its detail url.

Parameters:

request (Request) – The request, whose data are the LLMClient’s field values.

Returns:

A redirect to the new LLMClient, or a 400 response if it could not be created.

serializer_class

alias of LLMClientSerializer

class smarter.apps.llmclient.api.v1.views.views.ListViewBase(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAdminListAPIView

Base class for all llmclient list views.

A subclass sets contract_model, the model of smarter.apps.llmclient.contract.models that each row of its response is built with.

class smarter.apps.llmclient.api.v1.views.views.ViewBase(*args, **kwargs)[source]

Bases: SmarterAdminAPIView

Base class for all llmclient detail views.

Their GET responses are built from the models of smarter.apps.llmclient.contract.models, which the Smarter api’s OpenAPI document publishes.