Workbench View
PromptWorkbenchView is a Django class-based view responsible for serving the main prompt application page within the Smarter dashboard web app.
It hosts Smarter Chat, the React app of the LLMClient prompt workbench, as the web console hosts all of its React apps: the template includes the app’s Vite build assets from Django’s static files, and renders the app’s root element, whose attributes configure it. The React app then takes over the UI from there.
- class smarter.apps.prompt.views.detailviews.prompt_workbench_view.PromptWorkbenchView(**kwargs)[source]
Bases:
SmarterAuthenticatedNeverCachedWebViewPrompt app view for the Smarter web application.
This view is responsible for serving the main prompt application page within the Smarter dashboard web app. It hosts Smarter Chat, a React app that is built with Vite into Django’s static files, like every other React app of the web console. The React app then takes over the UI from there.
Key Features:
Django Template Integration: The view renders
react/smarter-chat.html, whosereact_smarter_chattemplate tag includes the React app’s hashed JavaScript and CSS files, from its Vite manifest.json, and whose root div passes the app its configuration as attributes.ReactJS UI Bootstrapping: The React app (https://github.com/smarter-sh/smarter-chat, cloned into smarter/react/packages/smarter-chat) renders the interactive prompt UI after the initial page load.
Flexible URL Patterns: The view supports both sandbox and production URL formats, allowing it to work with deployed and not-yet-deployed LLMClients.
Authentication Protected: This view requires the user to be authenticated. If the user is not authenticated, access is denied.
Cache Control: The view uses Django’s never_cache decorator to ensure that the browser does not cache the prompt page itself. This prevents issues where a user logs out and then logs back in without a full page refresh.
Example Usage:
- Sandbox mode:
- Production mode:
- Returns:
Renders the Django template for the prompt app, with the React app’s assets and configuration context.
- See Also:
PromptConfigView — for the endpoint that provides configuration data to the React app.
- dispatch(request, *args, **kwargs)[source]
Dispatch method to handle the request for the main prompt application page.
This method is responsible for preparing and serving the Django template that bootstraps the ReactJS prompt UI within the Smarter dashboard web app. It passes the React app’s configuration to the template, which renders it as the attributes of the app’s root element.
Key Features:
Django Template Integration: Uses Django’s template system to render the main prompt page, with the React app’s build assets and root div.
ReactJS UI Bootstrapping: The template includes the React build (JavaScript and CSS) from Django’s static files. The React app then takes over rendering the interactive prompt UI after the initial page load.
Flexible URL Patterns: Supports both sandbox and production URL formats, allowing the view to work with both deployed and not-yet-deployed LLMClients.
Authentication Protected: Requires the user to be authenticated. If the user is not authenticated, access is denied.
Cache Control: Uses Django’s never_cache decorator to prevent the browser from caching the prompt page, ensuring session security.
- Parameters:
request (
HttpRequest) – The incoming HTTP request object.*args – Additional positional arguments.
**kwargs – Additional keyword arguments.
- Returns:
Renders the Django template for the prompt app, with the React app’s assets and configuration context.
- Return type:
HttpResponse
See also
PromptConfigViewThe endpoint that provides configuration data to the React app.
- llmclient_helper: LLMClientHelper | None = None
- property log_stream_url: str
The url of the user’s server log stream, which Smarter Chat displays in its Console.
- Returns:
The url of
smarter.apps.dashboard.views.terminal_emulator.api.streams.stream_user_logs(), or an empty string if log viewing in the browser is disabled, in which case Smarter Chat has no “Server Logs” tab. Seesmarter.apps.dashboard.views.terminal_emulator.enabled.server_logs_enabled().- Return type:
- root_id = 'smarter-chat-root'
- template_path: str = 'react/smarter-chat.html'
- exception smarter.apps.prompt.views.detailviews.prompt_workbench_view.SmarterChatappViewError(message='')[source]
Bases:
SmarterExceptionBase class for all SmarterChatapp errors.
- property get_formatted_err_message
- class smarter.apps.prompt.views.detailviews.prompt_workbench_view.SmarterPromptSession(request, session_key, *args, llmclient=None, **kwargs)[source]
Bases:
SmarterHelperMixinHelper class that provides methods for creating a session key and client key.
- __init__(request, session_key, *args, llmclient=None, **kwargs)[source]
Note: this needs to exist; something in the Python MRO requires it, even if it does nothing.
If you remove this, you will get a mysterious error about something downstream expecting exactly one object.
- property chat_helper
- clean_url(url)[source]
Clean the url of any query strings and trailing ‘/config/’ strings.
- Return type:
- property formatted_class_name: str
Returns a formatted string of the class name for logging purposes.
- property llmclient
- property prompt
- request: HttpRequest | None = None
- property session_key: str
The session key for this prompt session.
This is used to identify the prompt session and is generated by the /config/ endpoint.
- smarter.apps.prompt.views.detailviews.prompt_workbench_view.should_log(level)[source]
Check if logging should be done based on the waffle switch.
- smarter.apps.prompt.views.detailviews.prompt_workbench_view.should_log_verbose(level)[source]
Check if logging should be done based on the waffle switch.