History

Prompt history views for smarter api.

They are mounted at /api/v1/prompts/history/, and return the chat sessions, tool calls and plugin usage of the sessions whose user the requesting user may manage, as the models of smarter.apps.prompt.contract.history: their own sessions, the sessions of their account’s users for an account admin, and every session for a superuser. A session holds a user’s conversation, so a user never reads another account’s, nor the platform’s.

class smarter.apps.prompt.api.v1.views.history.ChatHistoryListView(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAuthenticatedListAPIView

The user’s chat sessions: PromptHistoryApiSession models.

contract_model

alias of PromptHistoryApiSession

get_queryset()[source]

Return the chat sessions that the requesting user may manage.

serializer_class

alias of PromptSerializer

class smarter.apps.prompt.api.v1.views.history.ChatHistoryView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

One of the user’s chat sessions, by its id: a PromptHistoryApiSession.

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

Return the chat session whose id is kwargs["pk"], if the requesting user may manage its session.

Parameters:
  • request (Request) – The authenticated request.

  • args – Unused positional arguments.

  • kwargs – The url’s keyword arguments, with pk, the chat session’s id.

Returns:

A response whose body is the chat session as a PromptHistoryApiSession.

Raises:

django.http.Http404 – when no such chat session is visible to the user.

class smarter.apps.prompt.api.v1.views.history.ChatToolCallHistoryListView(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAuthenticatedListAPIView

The tool calls of the user’s chat sessions: PromptHistoryApiToolCall models.

contract_model

alias of PromptHistoryApiToolCall

get_queryset()[source]

Return the tool calls of the chat sessions that the requesting user may manage.

serializer_class

alias of PromptToolCallSerializer

class smarter.apps.prompt.api.v1.views.history.ChatToolCallHistoryView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

A tool call of the user’s chat sessions: a PromptHistoryApiToolCall.

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

Return the tool call whose id is kwargs["pk"], if the requesting user may manage its session.

Parameters:
  • request (Request) – The authenticated request.

  • args – Unused positional arguments.

  • kwargs – The url’s keyword arguments, with pk, the tool call’s id.

Returns:

A response whose body is the tool call as a PromptHistoryApiToolCall.

Raises:

django.http.Http404 – when no such tool call is visible to the user.

class smarter.apps.prompt.api.v1.views.history.PluginUsageHistoryListView(*args, **kwargs)[source]

Bases: ContractListMixin, SmarterAuthenticatedListAPIView

The plugin usage of the user’s chat sessions: PromptHistoryApiPluginUsage models.

contract_model

alias of PromptHistoryApiPluginUsage

get_queryset()[source]

Return the plugin usage of the chat sessions that the requesting user may manage.

item(row)[source]

A plugin usage of the response, whose plugin’s canDelete is the requesting user’s.

serializer_class

alias of PromptPluginUsageSerializer

class smarter.apps.prompt.api.v1.views.history.PluginUsageHistoryView(*args, **kwargs)[source]

Bases: SmarterAuthenticatedAPIView

A plugin usage of the user’s chat sessions: a PromptHistoryApiPluginUsage.

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

Return the plugin usage whose id is kwargs["pk"], if the requesting user may manage its session.

Parameters:
  • request (Request) – The authenticated request.

  • args – Unused positional arguments.

  • kwargs – The url’s keyword arguments, with pk, the plugin usage’s id.

Returns:

A response whose body is the plugin usage as a PromptHistoryApiPluginUsage.

Raises:

django.http.Http404 – when no such plugin usage is visible to the user.

smarter.apps.prompt.api.v1.views.history.plugin_usage_for_user(user)[source]

The plugin usage of the chat sessions whose user user may manage, newest first.

Parameters:

user (django.contrib.auth.models.User) – The requesting user.

Returns:

The plugin usage, with their sessions and plugins.

Return type:

QuerySet[PromptPluginUsage]

smarter.apps.prompt.api.v1.views.history.sessions_for_user(user)[source]

The chat sessions whose user user may manage, newest first.

Parameters:

user (django.contrib.auth.models.User) – The requesting user.

Returns:

The sessions.

Return type:

QuerySet[Prompt]

smarter.apps.prompt.api.v1.views.history.tool_calls_for_user(user)[source]

The tool calls of the chat sessions whose user user may manage, newest first.

Parameters:

user (django.contrib.auth.models.User) – The requesting user.

Returns:

The tool calls, with their sessions.

Return type:

QuerySet[PromptToolCall]