OpenaiStreamParser | R Documentation |
Stream handler for chat completions
Stream handler for chat completions
R6 class that allows to handle chat completions chunk by chunk. It also adds methods to retrieve relevant data. This class DOES NOT make the request.
Because curl::curl_fetch_stream
blocks the R console until the stream finishes,
this class can take a shiny session object to handle communication with JS
without recurring to a shiny::observe
inside a module server.
SSEparser::SSEparser
-> OpenaiStreamParser
shinySession
Holds the session
provided at initialization
user_prompt
The user_prompt
provided at initialization,
after being formatted with markdown.
value
The content of the stream. It updates constantly until the stream ends.
new()
Start a StreamHandler. Recommended to be assigned to the stream_handler
name.
OpenaiStreamParser$new(session = NULL, user_prompt = NULL)
session
The shiny session it will send the message to (optional).
user_prompt
The prompt for the chat completion. Only to be displayed in an HTML tag containing the prompt. (Optional).
append_parsed_sse()
Overwrites SSEparser$append_parsed_sse()
to be able to send a custom message
to a shiny session, escaping shiny's reactivity.
OpenaiStreamParser$append_parsed_sse(parsed_event)
parsed_event
An already parsed server-sent event to append to the events field.
clone()
The objects of this class are cloneable with this method.
OpenaiStreamParser$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.