API
smarter.apps.prompt.views.listview.api
Django class-based API views for managing ChatBots in the Smarter workbench web console.
This module provides API endpoints for listing, cloning, deleting, and renaming ChatBots associated with the authenticated user, as well as any shared ChatBots. All views require user authentication and leverage caching for responsiveness.
Classes
- PromptListApiView
Returns a paginated list of ChatBots accessible to the authenticated user, supporting filters for owned, shared, or all ChatBots. Supports cache invalidation and pagination.
- PromptListApiCloneView
API endpoint for cloning an existing ChatBot. Requires the user to provide a new name.
- PromptListApiDeleteView
API endpoint for deleting a ChatBot owned by the user.
- PromptListApiRenameView
API endpoint for renaming a ChatBot owned by the user.
Features
Requires user authentication for all endpoints.
Supports filtering ChatBots 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(*args, **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:chatbot_id>/<str:new_name>/ /workbench/api/listview/clone/123/?new_name=cloned_chatbot/
- Parameters:
request (HttpRequest) – The HTTP request object containing the parameters for cloning.
args – Additional positional arguments (not used).
kwargs –
Additional keyword arguments, including:
chatbot_id (str): The ID of the ChatBot to be cloned.
new_name (str): The new name for the cloned ChatBot.
- Returns:
A JsonResponse containing the serialized data of the newly cloned ChatBot if successful, or an error message if the cloning fails.
- Return type:
JsonResponse
- post(request, *args, **kwargs)[source]
Handle POST requests to clone an existing ChatBot. Validates input parameters, checks for the existence of the ChatBot to be cloned, and creates a new ChatBot with the specified name. Invalidates the cache for the user’s ChatBots 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:
chatbot_id (str): The ID of the ChatBot to be cloned.
new_name (str): The new name for the cloned ChatBot.
- Returns:
A JsonResponse containing the serialized data of the newly cloned ChatBot if successful, or an error message if the cloning fails.
- Return type:
- class smarter.apps.prompt.views.listview.api.PromptListApiDeleteView(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewAPI view for deleting a ChatBot. This view is protected and requires the user to be authenticated.
- post(request, *args, **kwargs)[source]
Handle POST requests to delete an existing ChatBot. Validates input parameters, checks for the existence of the ChatBot to be deleted, and deletes the ChatBot if it exists. Invalidates the cache for the user’s ChatBots 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:
chatbot_id (str): The ID of the ChatBot to be deleted.
- Returns:
A JsonResponse indicating the success or failure of the deletion.
- Return type:
- class smarter.apps.prompt.views.listview.api.PromptListApiRenameView(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewAPI view for renaming a ChatBot. This view is protected and requires the user to be authenticated. The user must provide the ID of the ChatBot to rename and a new name for the ChatBot.
- post(request, *args, **kwargs)[source]
Handle POST requests to rename an existing ChatBot. Validates input parameters, checks for the existence of the ChatBot to be renamed, and renames the ChatBot if it exists. Invalidates the cache for the user’s ChatBots 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:
chatbot_id (str): The ID of the ChatBot to be renamed.
new_name (str): The new name for the ChatBot.
- Returns:
A JsonResponse indicating the success or failure of the renaming.
- Return type:
- class smarter.apps.prompt.views.listview.api.PromptListApiView(*args, **kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewList API view for the Smarter workbench web console.
This view returns a paginated list of ChatBots accessible to the authenticated user, supporting filters for owned, shared, or all ChatBots. 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 ChatBots 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 ChatBots per page.
- Type:
- post(request, *args, **kwargs)[source]
Handles POST requests to retrieve ChatBots 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 ChatBots per page. Defaults to DEFAULT_PAGE_SIZE.
- post(request, *args, **kwargs)[source]
Handle POST requests to retrieve a list of ChatBots based on ownership filters and pagination. The response includes the authenticated user’s profile, an admin profile for reference, and the list of ChatBots 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 ChatBots 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 ChatBots to return per page. Defaults to DEFAULT_PAGE_SIZE.
invalidate_cache (bool, optional): If true, invalidates the cache for the user’s ChatBots before fetching results. Defaults to False.
- Returns:
A JsonResponse containing the user’s profile, an admin profile, and a list of ChatBots 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.