The ChatStep
opens up the possibility to display / hide intermediate steps prior to the final result.
Check out the panel-chat-examples docs to see applicable examples related to LangChain, OpenAI, Mistral, Llama, etc. If you have an example to demo, we'd love to add it to the panel-chat-examples gallery!
Parameters:
Core
collapsed_on_success
(bool
): Whether to collapse the card on completion. Defaults toTrue
.context_exception
(str
): How to handle exceptions raised upon exiting the context manager. If "raise", the exception will be raised. If "summary", a summary will be sent to the chat step. If "verbose", the full traceback will be sent to the chat step. If "ignore", the exception will be ignored.success_title
(str
): Title to display when status is success; if not provided andcollapsed_on_success
uses the last object's string. Defaults toNone
.default_title
(str
): The default title to display if the other title params are unset. Defaults to an empty string""
.failed_title
(str
): Title to display when status is failed. Defaults toNone
.margin
(tuple
): Allows creating additional space around the component. May be specified as a two-tuple of the form (vertical, horizontal) or a four-tuple (top, right, bottom, left). Defaults to(5, 5, 5, 10)
.objects
(list): The list of objects to display in theChatStep
, which will be formatted like aColumn
. Should not generally be modified directly except when replaced in its entirety.pending_title
(str
): Title to display when status is pending. Defaults toNone
.running_title
(str
): Title to display when status is running. Defaults toNone
.status
(str
): The status of the chat step. Must be one of ["pending", "running", "success", "failed"]. Defaults to"pending"
.
Styling
collapsed
(bool
): Whether the contents of theChatStep
are collapsed. Defaults toFalse
.default_badges
(dict
): Mapping from status to default status badge. Defaults toDEFAULT_STATUS_BADGES
; keys must be one of 'pending', 'running', 'success', 'failed'.
Methods
Core
stream
: Stream a token to the last available string-like object.stream_title
: Stream a token to the title header.serialize
: Format the object to a string.
Basics
ChatStep
can be initialized without any arguments.
Append Markdown
objects to the chat step by calling stream
.
Calling it again will concatenate the text to the last available Markdown
pane.
Alternatively, setting replace=True
will override the existing message.
It's possible to also append any objects, like images.
Calling stream
afterwards will append a new Markdown
pane below it.
To convert the objects into a string, call serialize
, or simply use str()
.
Badges
The default avatars are BooleanStatus
, but can be changed by providing default_badges
. The values can be emojis, images, text, or Panel objects.
Status
To show that the step is processing, you can set the status to running
and provide a running_title
.
Upon completion, set the status to success
and it'll automatically collapse the contents.
To have the title update on success, either provide the success_title
or default_title
.
To streamline this process, ChatStep
may be used as a context manager.
Upon entry, the status will be changed from the default pending
to running
.
Exiting will change the status from running
to completed
if successful.
However, if an exception occurs, the status will be set to "failed" and the error message will be displayed on the title.
The title can also be streamed.
It can be used with any status
, like setting status="pending"
.
The title can also be completely replaced--equivalent to setting chat_step.pending_title = "Nevermind!
Be sure to check out ChatFeed to see it works with a ChatFeed
or ChatInterface
!