Prompt (Chat) URLS

URL configuration for Smarter deployed LLMClients.

Endpoints

Endpoint

Description

/

Named llm_client configuration view

/config/

Named llm_client configuration view

/prompt/

Default llm_client API view

See also

URL Patterns

 1# from django.contrib import admin
 2from django.urls import path
 3
 4from smarter.apps.llm_client.api.v1.views.default import DefaultLLMClientApiView
 5from smarter.apps.prompt.views.detailviews import PromptConfigView
 6
 7urlpatterns = [
 8    path("", PromptConfigView.as_view(), name="console_home"),
 9    path("config/", PromptConfigView.as_view(), name="llm_client_named_config"),
10    path("prompt/", DefaultLLMClientApiView.as_view(), name="llm_client_named_chat"),
11]
12
13__all__ = ["urlpatterns"]

PromptConfigView Class Reference

PromptConfigView is a Django class-based view responsible for providing.

configuration data to the ReactJS prompt UI component in the Smarter web application.

class smarter.apps.prompt.views.detailviews.prompt_config_view.PromptConfigView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Prompt configuration view for the Smarter web application.

This view is responsible for providing all configuration information required by the ReactJS prompt UI component. It is designed to be performant and efficient, as it is invoked on every user-facing browser load and refresh.

Key Features:

  • Django Template-Based: This view uses Django’s template system for rendering and does not rely on Django REST Framework (DRF) serializers for its main response. The configuration data is returned as a JSON response, but the view itself is structured as a Django class-based view.

  • CSRF Exempt: The view is decorated with @csrf_exempt because it is read-only and does not modify server-side data. This exemption is safe in this context and avoids unnecessary CSRF validation for GET and POST requests that only retrieve configuration data.

  • ReactJS UI Integration: The endpoint provides all necessary configuration and context information for the ReactJS prompt component. This includes llm_client metadata, plugin information, session keys, and historical data relevant to the prompt session. The React app consumes this configuration to initialize and render the prompt UI in the user’s browser.

  • Session-Based Architecture: Each prompt session is uniquely identified and managed by a globally unique 64-character session key. The session key is generated by RequestHelper.generate_session_key() and is persisted by the browser in a domain and path-specific cookie, meaning that this design supports an unlimited number of concurrent sessions per user, one per device per llm_client.

  • Performance Considerations: Since this endpoint is called on every browser load and refresh, performance is a primary concern. The view is optimized to minimize database queries and serialization overhead. Only a limited number of plugins (as defined by MAX_RETURNED_PLUGINS) are returned to avoid excessive payload sizes. Caching and efficient queryset usage are employed where possible to ensure fast response times for end users.

Example Usage:

Returns:
JSON response containing:
  • session_key: Unique identifier for the prompt session.

  • sandbox_mode: Boolean indicating if the llm_client is running in sandbox mode.

  • debug_mode: Boolean indicating if debug mode is enabled.

  • llm_client: Serialized llm_client configuration.

  • history: Prompt and plugin selector history for the session.

  • meta_data: Additional metadata for the llm_client.

  • plugins: Plugin metadata and a limited list of plugins.

Security:
  • The view is protected and requires the user to be authenticated, unless the llm_client is configured to allow unauthenticated access.

  • If authentication is required and the user is not authenticated, a 403 Forbidden response is returned.

See Also:
  • SmarterPromptSession: Helper class for managing prompt sessions.

  • LLMClientConfigSerializer, LLMClientPluginSerializer: Serializers for llm_client and plugin data.

  • LLMClientHelper: Helper for llm_client-related operations.

authentication_classes = None
clean_url(url)[source]

Clean the url of any query strings and trailing ‘/config/’ strings.

Return type:

str

command: SmarterJournalCliCommands | None = None
config()[source]

Assemble and return the configuration dictionary required by the ReactJS prompt UI component.

This method gathers all relevant context and configuration data for the prompt session and llm_client, and returns it as a dictionary suitable for JSON serialization. This configuration is consumed by the ReactJS frontend to initialize and render the prompt interface.

Key Features:

  • Django Template-Based: This logic is part of a Django class-based view and does not use Django REST Framework (DRF) serializers for the main response, though serializers are used for some nested data.

  • CSRF Exempt: The parent view is CSRF exempt because this endpoint is strictly read-only and does not modify server-side data.

  • ReactJS UI Integration: The returned dictionary provides all configuration and context information needed by the ReactJS prompt component, including llm_client metadata, plugin information, session keys, and prompt history.

  • Session-Based: The configuration is tied to a unique prompt session, as defined by the SmarterPromptSession helper, which uses a combination of the user’s IP address and device-identifying information to uniquely identify each session.

  • Performance: Since this endpoint is called on every browser load and refresh, the logic is optimized to minimize database queries and serialization overhead. Only a limited number of plugins (see MAX_RETURNED_PLUGINS) are returned to keep payloads small and response times fast.

Returns:

A dictionary containing all configuration data required by the ReactJS prompt UI component. The structure includes:

  • session_key: Unique identifier for the prompt session.

  • sandbox_mode: Boolean indicating if the llm_client is running in sandbox mode.

  • debug_mode: Boolean indicating if debug mode is enabled.

  • llm_client: Serialized llm_client configuration.

  • history: Prompt and plugin selector history for the session.

  • meta_data: Additional metadata for the llm_client.

  • plugins: Plugin metadata and a limited list of plugins.

Return type:

dict

Raises:

SmarterValueError – If the session or llm_client helper is not set.

See also

SmarterPromptSession : Helper class for managing prompt sessions. LLMClientConfigSerializer, LLMClientPluginSerializer : Serializers for llm_client and plugin data. LLMClientHelper : Helper for llm_client-related operations.

rtype:

dict[str, Any]

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

Handles incoming HTTP requests for the prompt configuration endpoint.

This method is responsible for orchestrating the retrieval and assembly of all configuration data required by the ReactJS prompt UI component. It is invoked on every user-facing browser load and refresh, making performance a critical concern.

Key Details:

  • Django Template-Based: This view uses Django’s class-based view and template system, not Django REST Framework (DRF). The response is a JSON object, but the view logic is not DRF-based.

  • CSRF Exempt: The view is decorated with @csrf_exempt because it is strictly read-only and does not modify server-side data. This avoids unnecessary CSRF validation for GET and POST requests that only retrieve configuration data.

  • ReactJS UI Integration: The endpoint provides all configuration and context information needed by the ReactJS prompt component, including llm_client metadata, plugin information, session keys, and prompt history.

  • Session-Based: Sessions are managed by the SmarterPromptSession helper, which uniquely defines a prompt session using a combination of the user’s IP address and device-identifying information. This ensures each device/browser instance receives a unique session key, which is used to track prompt history and plugin usage.

  • Performance: Since this endpoint is called on every browser load and refresh, it is optimized to minimize database queries and serialization overhead. Only a limited number of plugins are returned (see MAX_RETURNED_PLUGINS) to keep payloads small and response times fast.

Parameters:
  • request (HttpRequest) – The incoming HTTP request object.

  • llm_client_id (Optional[int], default=None) – The ID of the llm_client to retrieve configuration for, if specified.

  • *args – Additional positional arguments.

  • **kwargs – Additional keyword arguments.

Returns:

A JSON response containing all configuration data required by the ReactJS prompt UI component, or an error response if the request is invalid or unauthorized.

Return type:

Union[JsonResponse, HttpResponse, SmarterJournaledJsonErrorResponse]

See also

SmarterPromptSession : Helper class for managing prompt sessions. LLMClientConfigSerializer, LLMClientPluginSerializer : Serializers for llm_client and plugin data. LLMClientHelper : Helper for llm_client-related operations.

rtype:

Union[JsonResponse, HttpResponse, SmarterJournaledJsonErrorResponse]

property formatted_class_name: str

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

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

Get the llm_client configuration.

Return type:

Union[SmarterJournaledJsonResponse, HttpResponseNotAllowed]

legacy_config(config, replace_str, with_str)[source]

Recursively replaces any key value of ‘llm_client’ with ‘chatbot’ for legacy.

support of older versions of the React app that expect ‘chatbot’ instead of ‘llm_client’.

Return type:

Any

property llm_client: LLMClient | None
property llm_client_helper: LLMClientHelper | None
llm_client_name: str | None = None
permission_classes = (<class 'smarter.lib.drf.views.helpers.UnauthenticatedPermissionClass'>,)
post(request, *args, **kwargs)[source]

Get the llm_client configuration.

Return type:

SmarterJournaledJsonResponse

session: SmarterPromptSession | None = None
thing: SmarterJournalThings | None = None
smarter.apps.prompt.views.detailviews.prompt_config_view.should_log(level)[source]

Check if logging should be done based on the waffle switch.

smarter.apps.prompt.views.detailviews.prompt_config_view.should_log_verbose(level)[source]

Check if logging should be done based on the waffle switch.

DefaultLLMClientApiView Class Reference

Smarter Customer API view.

class smarter.apps.llm_client.api.v1.views.default.DefaultLLMClientApiView(**kwargs)[source]

Bases: LLMClientApiBaseViewSet

Main view for Smarter LLMClient API prompt prompts.

top-level viewset for customer-deployed Plugin-based Prompt APIs.

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

Smarter API LLMClient dispatch method.

Parameters:
  • request – Django HttpRequest object

  • args – Additional positional arguments

  • name – LLMClient name (str, optional)

  • kwargs – Additional keyword arguments

Example request payload:

{
    "session_key": "dde3dde5e3b97134f5bce5edf26ec05134da71d8485a86dfc9231149aaf0b0af",
    "messages": [
        {
            "role": "assistant",
            "content": "Welcome to Smarter!.  how can I assist you today?"
        },
        {
            "role": "user",
            "content": "Hello, World!"
        }
    ]
}