Smarter Prompt
Overview
Smarter Prompt manages prompt sessions and the
integration between the Smarter backend and the ReactJS chat component
used to manage sessions in the Smarter Chat HTML integration, as well as in the command-line interface (CLI).
It is chiefly responsible for storing and retrieving
prompt sessions and messages in the
database, serving the configuration object to the
ReactJS chat component, handling REST API prompt requests,
serving prompt responses, and orchestrating the
Smarter resources associated with a session, including Account,
LLMClient, and Plugin.
Each prompt of a session saves its request, its response and the conversation’s messages as a
PromptHistory row, and each tool or plugin that it used as a
PromptToolCall or
PromptPluginUsage row. Smarter keeps these rows for
SMARTER_PROMPT_HISTORY_MAX_AGE days, 90 by default
(smarter_settings.prompt_history_max_age).
Celery Beat runs purge_prompt_history() once a day, which
deletes the older rows, then the sessions that are older than that and have none left. A session
that is still in use keeps its recent prompts; one that has been idle for longer is deleted.
Note
Smarter sessions are distinct from Smarter LLMClients. An LLMClient is a resource that defines the configuration of an llmclient, including its system prompt, plugins, and other settings. A session, by contrast, is an instance of a conversation with an llmclient, comprising the complete history of messages exchanged during that conversation.
Smarter sessions originate in Smarter Prompt, are passed to the ReactJS component as part of the configuration object, and are stored as browser cookies, identified by a GUID-like string that, with a high level of certainty, uniquely identifies the session. Sessions are specific to the device and browser in which they were created; a session started on one device or browser cannot be continued on another.
Usage
# Deployed Smarter LLMClient
curl -X POST https://stackademy-sql.3141-5926-5359.api.example.com/prompt/ \
-H "Content-Type: application/json" \
-d '{"messages": [{"role": "user", "content": "hello world"}]}'
# Smarter platform api, by the LLMClient's id
curl -X POST http://localhost:9357/api/v1/llm-clients/9/prompt/ \
-H "Content-Type: application/json" \
-H "Authorization: Token <YOUR-API-KEY>" \
-d '{"session_key": "<SESSION-KEY>", "messages": [{"role": "user", "content": "hello world"}]}'