Chatapp Workbench View

PromptWorkbenchView is a Django class-based view responsible for serving the.

main prompt application page within the Smarter dashboard web app. It integrates the ReactJS prompt UI with the Django template system by injecting a React build artifact snippet (served from an AWS Cloudfront CDN) into the Django-rendered HTML template. The React app then takes over the UI from there.

class smarter.apps.prompt.views.detailviews.prompt_workbench_view.PromptWorkbenchView(**kwargs)[source]

Bases: SmarterAuthenticatedNeverCachedWebView

Prompt 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 integrates the ReactJS prompt UI with the Django template system by injecting a React build artifact snippet (served from an AWS Cloudfront CDN) into the Django-rendered HTML template. The React app then takes over the UI from there.

Key Features:

  • Django Template Integration: The view uses Django’s template system to render the main prompt page. It injects the React app’s loader script and root div into the template, allowing seamless integration between Django and React.

  • ReactJS UI Bootstrapping: The React build (JavaScript and CSS) is loaded from a CDN and injected into the DOM. The React app is responsible for rendering 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:

Returns:

Renders the Django template for the prompt app, injecting the React loader 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 injects the React loader script and configuration context into the template, enabling seamless integration between Django and React.

Key Features:

  • Django Template Integration: Uses Django’s template system to render the main prompt page, injecting the React app’s loader script and root div.

  • ReactJS UI Bootstrapping: Loads the React build (JavaScript and CSS) from a CDN and injects it into the DOM. 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, injecting the React loader and configuration context.

Return type:

HttpResponse

See also

PromptConfigView

The endpoint that provides configuration data to the React app.

llm_client: LLMClient | None = None
llm_client_helper: LLMClientHelper | None = None
reactjs_cdn_path = '/ui-chat/app-loader.js'
reactjs_loader_url = 'http://cdn.local.smarter.sh/ui-chat/app-loader.js'
template_path: str = 'prompt/workbench.html'
exception smarter.apps.prompt.views.detailviews.prompt_workbench_view.SmarterChatappViewError(message='')[source]

Bases: SmarterException

Base class for all SmarterChatapp errors.

property get_formatted_err_message
class smarter.apps.prompt.views.detailviews.prompt_workbench_view.SmarterPromptSession(request, session_key, *args, llm_client=None, **kwargs)[source]

Bases: SmarterHelperMixin

Helper class that provides methods for creating a session key and client key.

__init__(request, session_key, *args, llm_client=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:

str

property formatted_class_name: str

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

property llm_client
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.