API View

This module contains views to implement the React.

LLMHost and LLMHostCompute list views in the Smarter Dashboard.

smarter.apps.llmhost.views.listview.api.COMPUTE_SORT_FIELDS = {'cpu': 'cpu', 'createdAt': 'created_at', 'description': 'description', 'gpuCount': 'gpu_count', 'instanceType': 'instance_type', 'name': 'name', 'pricePerHour': 'price_per_hour', 'updatedAt': 'updated_at'}

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

{
    'cpu': 'cpu',
    'createdAt': 'created_at',
    'description': 'description',
    'gpuCount': 'gpu_count',
    'instanceType': 'instance_type',
    'name': 'name',
    'pricePerHour': 'price_per_hour',
    'updatedAt': 'updated_at',
}
class smarter.apps.llmhost.views.listview.api.LLMHostComputeListApiCloneView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Clone an LLMHostCompute for the authenticated user: its spec, but not its node group, which.

Smarter creates when an LLMHost first needs one of the clone’s nodes.

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 LLMHostCompute that the user may read.

Parameters:

kwargs – llmhost_compute_id (str): the LLMHostCompute to clone. new_name (str): the clone’s name.

Returns:

The clone, serialized, or an error message.

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostComputeListApiDeleteView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Delete an LLMHostCompute that the authenticated user owns, and its node group.

Refused while LLMHosts use it.

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

Parameters:

kwargs – llmhost_compute_id (str): the LLMHostCompute to delete.

Returns:

A success or error message.

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostComputeListApiRenameView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Rename an LLMHostCompute that the authenticated user owns.

Refused while its node group exists, or LLMHosts use it.

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

Parameters:

kwargs – llmhost_compute_id (str): the LLMHostCompute to rename. new_name (str): its new name.

Returns:

The renamed LLMHostCompute, serialized, or an error message.

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostComputeListApiView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Return the LLMHostComputes available to the authenticated user, for the React list view in the Smarter Workbench web console: their own, and those shared with them, e.g. the built-in LLMHostComputes, which the Smarter admin owns.

property formatted_class_name: str

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

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

JsonResponse | SmarterHttpResponseNotFound

class smarter.apps.llmhost.views.listview.api.LLMHostListApiCloneView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Clone a llmhost 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 LLMHost.

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

    • llmhost_id (str): The ID of the LLMHost to be cloned.

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

Returns:

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

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostListApiDeleteView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Delete a llmhost 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 LLMHost.

Validates input parameters, checks for the existence of the LLMHost to be deleted, and deletes the LLMHost if it exists. Invalidates the cache for the user’s LLMHosts 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:

    • llmhost_id (str): The ID of the LLMHost to be deleted.

Returns:

A JsonResponse indicating the success or failure of the deletion.

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostListApiRenameView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Rename a llmhost 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 LLMHost.

Validates input parameters, checks for the existence of the LLMHost to be renamed, and renames the LLMHost if it exists. Invalidates the cache for the user’s LLMHosts 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:

    • llmhost_id (str): The ID of the LLMHost to be renamed.

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

Returns:

A JsonResponse indicating the success or failure of the renaming.

Return type:

JsonResponse

class smarter.apps.llmhost.views.listview.api.LLMHostListApiView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

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

This view displays all llmhosts available to the authenticated user as cards, providing a quick overview and access to llmhost 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 llmhost, 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:

JsonResponse | SmarterHttpResponseNotFound

smarter.apps.llmhost.views.listview.api.SORT_FIELDS = {'createdAt': 'created_at', 'description': 'description', 'isActive': 'is_active', 'name': 'name', 'updatedAt': 'updated_at'}

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

{
    'createdAt': 'created_at',
    'description': 'description',
    'isActive': 'is_active',
    'name': 'name',
    'updatedAt': 'updated_at',
}