How the Web Console Hosts It
In the web console, Smarter Chat is the LLMClient prompt engineering workbench, at
/workbench/llm-clients/<hashed_id>/prompt/. It is hosted exactly as the web console’s other
React apps are (see Django-React Integration):
Django renders a page with the app’s root element, the root element’s attributes configure the app,
and the app takes over from there.
The View, the Template and the Template Tag
Piece |
Role |
|---|---|
Requires a logged-in user, finds the LLMClient, and renders |
|
|
Extends the dashboard’s base template, includes the app’s css and JavaScript files, and
renders the root element, whose attributes are the |
|
The |
|
Reads the root element’s attributes, and renders |
The Root Element
The root element’s attributes are the app’s props. main.tsx throws an error if a required one
is missing, so the page fails loudly rather than rendering a broken chat.
Attribute |
Prop |
Value |
|---|---|---|
|
|
|
|
|
The LLMClient’s |
|
|
|
|
|
Django’s |
|
|
|
|
Django’s |
|
|
|
Django’s |
|
|
The |
|
|
A unique id of the page request, sent back as the |
|
|
The url of the user’s server log stream, or empty when log viewing in the browser is disabled
( |
Boolean attributes are compared case-insensitively with "true", so Django’s True works.
Changing what the workbench passes to the chat is a change in both repositories: the view’s context
and the template here, and main.tsx and index.html in Smarter Chat. See Adding a prop in
Developing Smarter Chat.
Authentication in the Workbench
The workbench page and the chat’s requests are authenticated by the web console’s Django session.
The chat’s requests are sent with credentials: "include", so the browser adds the session
cookie, and the chat adds the X-CSRFToken header from the CSRF cookie. Its apiUrl is on the
platform’s own domain, so the configuration request is same-origin. The prompt request, to the
LLMClient’s url_llmclient, is also on the platform domain, under /api/v1/.
A workbench url is a sandbox url: the LLMClient requires an authenticated user there whether it is
deployed or not, and the configuration’s sandbox_mode is true.
Builds and Static Files
npm run build, in the React workspace, writes the app into
smarter/smarter/static/react/@smarter.sh/ui-chat/, with a manifest.json that has a
_custom entry of the build’s time, version and environment. collectstatic copies it into
staticfiles, from which it is served. In development, use make react-build, and restart
smarter-app afterwards: the template tag caches the manifest, including a missing one.