API View

This module contains views to implement the React.

Guardrail list view in the Smarter Dashboard.

class smarter.apps.guardrail.views.listview.api.GuardrailListApiCloneView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Clone a guardrail for the authenticated user.

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 Guardrail.

Validates input parameters, checks for the existence of the Guardrail to be cloned, and creates a new Guardrail with the specified name. Invalidates the cache for the user’s Guardrails 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:

    • guardrail_id (str): The ID of the Guardrail to be cloned.

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

Returns:

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

Return type:

JsonResponse

class smarter.apps.guardrail.views.listview.api.GuardrailListApiDeleteView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Delete a guardrail for the authenticated user.

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 Guardrail.

Validates input parameters, checks for the existence of the Guardrail to be deleted, and deletes the Guardrail 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:

    • guardrail_id (str): The ID of the Guardrail to be deleted.

Returns:

A JsonResponse indicating the success or failure of the deletion.

Return type:

JsonResponse

class smarter.apps.guardrail.views.listview.api.GuardrailListApiRenameView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Rename a guardrail for the authenticated user.

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 Guardrail.

Validates input parameters, checks for the existence of the Guardrail to be renamed, and renames the Guardrail 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:

    • guardrail_id (str): The ID of the Guardrail to be renamed.

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

Returns:

A JsonResponse indicating the success or failure of the renaming.

Return type:

JsonResponse

class smarter.apps.guardrail.views.listview.api.GuardrailListApiView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Render the guardrail list view for the Smarter Workbench web console.

This view displays all guardrails available to the authenticated user as cards, providing a quick overview and access to guardrail details.

Parameters:
  • request (ASGIRequest) – Django HTTP request object.

  • args (tuple) – Additional positional arguments.

  • kwargs (dict) – Additional keyword arguments.

Returns:

Rendered HTML page with a card for each guardrail, or a 404 error page if the user is not authenticated.

Return type:

HttpResponse

property formatted_class_name: str

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

post(request, *args, **kwargs)[source]
Return type:

Union[JsonResponse, SmarterHttpResponseNotFound]