API

Smarter.apps.prompt.views.listview.api

Django class-based API views for managing LLMClients in the Smarter workbench web console.

This module provides API endpoints for listing, cloning, deleting, and renaming LLMClients associated with the authenticated user, as well as any shared LLMClients. All views require user authentication and leverage caching for responsiveness.

Classes

  • PromptListApiView

    Returns a paginated list of LLMClients accessible to the authenticated user, supporting filters for owned, shared, or all LLMClients. Supports cache invalidation and pagination.

  • PromptListApiCloneView

    API endpoint for cloning an existing LLMClient. Requires the user to provide a new name.

  • PromptListApiDeleteView

    API endpoint for deleting a LLMClient owned by the user.

  • PromptListApiRenameView

    API endpoint for renaming a LLMClient owned by the user.

Features

  • Requires user authentication for all endpoints.

  • Supports filtering LLMClients by ownership (owned, shared, or all).

  • Provides pagination, search, sorting and cache invalidation options.

  • Returns results as JSON responses.

  • Uses Django’s class-based views and serializers.

Example Endpoints

  • POST /workbench/api/listview/

  • POST /workbench/api/listview/all/?page=1&page_size=50&invalidate_cache=false

  • POST /workbench/api/listview/owned/?page=1&page_size=25&invalidate_cache=true

  • POST /workbench/api/listview/shared/?page=2&page_size=10&invalidate_cache=false

smarter.apps.prompt.views.listview.api.FILTERS = {'pending': <Q: (AND: ('deployed', False))>}

The named filters of the LLMClient list.

?filter=pending lists the LLMClients that aren’t deployed yet, which the dashboard’s pending deployments link opens.

{'pending': <Q: (AND: ('deployed', False))>}
smarter.apps.prompt.views.listview.api.PENDING_FILTER = 'pending'

The name of the filter of the LLMClients that aren’t deployed yet.

class smarter.apps.prompt.views.listview.api.PromptListApiCloneView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

API view for cloning a listObject.

This view is protected and requires the user to be authenticated. The user must provide the ID of the listObject to clone and a new name for the cloned listObject.

The view handles POST requests to clone an existing listObject. It validates the input parameters, checks for the existence of the listObject to be cloned, and creates a new listObject with the specified name. After cloning, it invalidates the cache for the user’s listObjects to ensure that the new listObject appears in subsequent listings.

Example URL Paths:

/workbench/api/listview/clone/<int:llmclient_id>/<str:new_name>/ /workbench/api/listview/clone/123/?new_name=cloned_llmclient/

Parameters:
  • request (HttpRequest) – The HTTP request object containing the parameters for cloning.

  • args – Additional positional arguments (not used).

  • kwargs –

    Additional keyword arguments, including:

    • llmclient_id (str): The ID of the LLMClient to be cloned.

    • new_name (str): The new name for the cloned LLMClient.

Returns:

A JsonResponse containing the serialized data of the newly cloned LLMClient if successful, or an error message if the cloning fails.

Return type:

JsonResponse

property formatted_class_name: str

Returns a formatted string of the class name for logging purposes.

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

Handle POST requests to clone an existing LLMClient.

Validates input parameters, checks for the existence of the LLMClient to be cloned, and creates a new LLMClient with the specified name. Invalidates the cache for the user’s LLMClients after cloning.

Parameters:
  • request (HttpRequest) – The HTTP request object containing the parameters for cloning.

  • args – Additional positional arguments (not used).

  • kwargs –

    Additional keyword arguments, including:

    • llmclient_id (str): The ID of the LLMClient to be cloned.

    • new_name (str): The new name for the cloned LLMClient.

Returns:

A JsonResponse containing the serialized data of the newly cloned LLMClient if successful, or an error message if the cloning fails.

Return type:

JsonResponse

class smarter.apps.prompt.views.listview.api.PromptListApiDeleteView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

API view for deleting a LLMClient.

This view is protected and requires the user to be authenticated.

property formatted_class_name: str

Returns a formatted string of the class name for logging purposes.

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

Handle POST requests to delete an existing LLMClient.

Validates input parameters, checks for the existence of the LLMClient to be deleted, and deletes the LLMClient if it exists. Invalidates the cache for the user’s LLMClients after deletion.

Parameters:
  • request (HttpRequest) – The HTTP request object containing the parameters for deletion.

  • args – Additional positional arguments (not used).

  • kwargs –

    Additional keyword arguments, including:

    • llmclient_id (str): The ID of the LLMClient to be deleted.

Returns:

A JsonResponse indicating the success or failure of the deletion.

Return type:

JsonResponse

class smarter.apps.prompt.views.listview.api.PromptListApiRenameView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

API view for renaming a LLMClient.

This view is protected and requires the user to be authenticated. The user must provide the ID of the LLMClient to rename and a new name for the LLMClient.

property formatted_class_name: str

Returns a formatted string of the class name for logging purposes.

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

Handle POST requests to rename an existing LLMClient.

Validates input parameters, checks for the existence of the LLMClient to be renamed, and renames the LLMClient if it exists. Invalidates the cache for the user’s LLMClients after renaming.

Parameters:
  • request (HttpRequest) – The HTTP request object containing the parameters for renaming.

  • args – Additional positional arguments (not used).

  • kwargs –

    Additional keyword arguments, including:

    • llmclient_id (str): The ID of the LLMClient to be renamed.

    • new_name (str): The new name for the LLMClient.

Returns:

A JsonResponse indicating the success or failure of the renaming.

Return type:

JsonResponse

class smarter.apps.prompt.views.listview.api.PromptListApiView(**kwargs)[source]

Bases: SmarterListApiView

List API view of the LLMClients, for the Smarter workbench web console.

It returns a page of the LLMClients that the authenticated user owns, that are shared with them, or both, cached per user. See SmarterListApiView.

Example URL Paths:

/workbench/api/listview/ /workbench/api/listview/all/?page=1&page_size=50&invalidate_cache=false /workbench/api/listview/owned/?page=1&page_size=25&invalidate_cache=true /workbench/api/listview/shared/?page=2&page_size=10&search=support&ordering=-name /workbench/api/listview/all/?filter=pending

filters: ClassVar[Mapping[str, Q] | None] = {'pending': <Q: (AND: ('deployed', False))>}

The list’s named filters, if it has any.

listview_cache_kind: ClassVar[str] = 'LLMClient'

The list’s name in the cache, as connect_listview_cache() invalidates it, e.g. LLMClient.

model

alias of LLMClient

prefetch_related: ClassVar[tuple[str | Prefetch, ...]] = ('llmclientextensions_set__extension', 'llmclientplugin_set__plugin_meta', 'llmclientmcpclients_set__mcpclient', 'llmclientguardrails_set__guardrail', 'llmclientapikey_set__api_key')

The reverse and many-to-many relations that the serializer reads, besides the tags.

select_related: ClassVar[tuple[str, ...]] = ('custom_domain',)

The forward relations that the serializer reads, besides the owner’s.

serializer_class

alias of LLMClientSerializer

sort_fields: ClassVar[Mapping[str, str]] = {'createdAt': 'created_at', 'defaultModel': 'default_model', 'description': 'description', 'name': 'name', 'provider': 'provider', 'updatedAt': 'updated_at'}

The columns that the list may be sorted by.

See paginate_queryset().

smarter.apps.prompt.views.listview.api.SORT_FIELDS = {'createdAt': 'created_at', 'defaultModel': 'default_model', 'description': 'description', 'name': 'name', 'provider': 'provider', 'updatedAt': 'updated_at'}

The columns of the LLMClient list that it may be sorted by, and the fields that sort them.

{
    'createdAt': 'created_at',
    'defaultModel': 'default_model',
    'description': 'description',
    'name': 'name',
    'provider': 'provider',
    'updatedAt': 'updated_at',
}
smarter.apps.prompt.views.listview.api.should_log_verbose(level)[source]

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