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 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=falsePOST /workbench/api/listview/owned/?page=1&page_size=25&invalidate_cache=truePOST /workbench/api/listview/shared/?page=2&page_size=10&invalidate_cache=false
- class smarter.apps.prompt.views.listview.api.PromptListApiCloneView(**kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewAPI 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:llm_client_id>/<str:new_name>/ /workbench/api/listview/clone/123/?new_name=cloned_llm_client/
- Parameters:
request (HttpRequest) – The HTTP request object containing the parameters for cloning.
args – Additional positional arguments (not used).
kwargs –
Additional keyword arguments, including:
llm_client_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:
llm_client_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:
- class smarter.apps.prompt.views.listview.api.PromptListApiDeleteView(**kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewAPI 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:
llm_client_id (str): The ID of the LLMClient to be deleted.
- Returns:
A JsonResponse indicating the success or failure of the deletion.
- Return type:
- class smarter.apps.prompt.views.listview.api.PromptListApiRenameView(**kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewAPI 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:
llm_client_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:
- class smarter.apps.prompt.views.listview.api.PromptListApiView(**kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewList API view for the Smarter workbench web console.
This view returns a paginated list of LLMClients accessible to the authenticated user, supporting filters for owned, shared, or all LLMClients. Results are cached for responsiveness, with optional cache invalidation. User authentication is required.
- Example URL Paths:
/workbench/api/listview/ /workbench/api/listview/all/ /workbench/api/listview/all/?page=1&page_size=50&invalidate_cache=false /workbench/api/listview/owned/ /workbench/api/listview/owned/?page=1&page_size=25&invalidate_cache=true /workbench/api/listview/shared/ /workbench/api/listview/shared/?page=2&page_size=10&invalidate_cache=false
- Features:
Returns paginated LLMClients for the authenticated user.
Supports filtering by ‘owned’, ‘shared’, or ‘all’.
Caches results for improved performance.
Allows cache invalidation via request.
Requires user authentication.
- DEFAULT_PAGE_SIZE
Default number of LLMClients per page.
- Type:
- post(request, *args, **kwargs)[source]
Handles POST requests to retrieve LLMClients based on filters and pagination.
- Keyword Arguments:
ownership_filter (str, optional) – ‘owned’, ‘shared’, or ‘all’. Defaults to ‘all’.
page (int, optional) – Page number for pagination. Defaults to 1.
invalidate_cache (bool, optional) – If true, invalidates cache before fetching results. Defaults to False.
page_size (int, optional) – Number of LLMClients per page. Defaults to DEFAULT_PAGE_SIZE.
- 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 retrieve a list of LLMClients based on ownership filters and pagination.
The response includes the authenticated user’s profile, an admin profile for reference, and the list of LLMClients serialized as JSON.
- Parameters:
request (
HttpRequest) – The HTTP request object containing query parameters for filtering and pagination.args – Additional positional arguments (not used).
kwargs –
Additional keyword arguments, including:
ownership_filter (str, optional): Filter for LLMClients based on ownership. Can be ‘owned’, ‘shared’, or ‘all’. Defaults to ‘all’.
page (int, optional): Page number for pagination. Defaults to 1.
page_size (int, optional): Number of LLMClients to return per page. Defaults to DEFAULT_PAGE_SIZE.
invalidate_cache (bool, optional): If true, invalidates the cache for the user’s LLMClients before fetching results. Defaults to False.
- Returns:
A JsonResponse containing the user’s profile, an admin profile, and a list of LLMClients based on the specified filters and pagination.
- Return type:
- smarter.apps.prompt.views.listview.api.should_log_verbose(level)[source]
Check if logging should be done based on the waffle switch.