The brainbox api requires the brainbox
permission in the manifest
enum "user", "system", "assistant"
The role indicates the source or purpose of the ChatMessage. i.e. user is a message from the user, system is a message to configure Brainbox
object { "role": ChatMessageRole, "content": "..." }
A single chat message. The role indicates the source or purpose of the message and the content is the text content contained within the message
enum "stream", "end", "error"
The type of stream message
An event that's emitted when Brainbox streams parts of the message back to the API. The stream messages indicate parts of the content that Brainbox is replying with, until the API returns end or error.
chatId [string]
the id of the chat. This can be used to tie the stream messages back to the original requesttype [ChatStreamType]
the type of message that's being returned. Typically events will emit multiplestream
types followed by a singleend
orerror
messagecontent [string]
the partial of the message content
Initiate a chat with Brainbox.
system [string]
the system message, used to configure Brainboxuser [string]
the users messagemessageHistory [ChatMessage[] Optional]
ab array of previous chat messages to include in the conversation. This can provide more context to Brainbox. Some messages may be truncated to remain within quota limits
Returns chatId [string]
. Replies are streamed back through the API. Use the provided chatId alongside the brainbox.onChatStream
event to buffer and build the complete reply.
Examples can be found in the examples folder:
- Grammar corrector Example. Adds a button to all pages, when clicked it takes the content from the last textarea/input field, asks Brainbox to correct the grammar and replaces the original content in the page
- Talk like a pirate Example. A simple example tells a pirate themed joke in the background page