Stream handler for chat completions
Stream handler for chat completions
SSEparser::SSEparser -> OpenaiStreamParser
shinySessionHolds the session provided at initialization
user_promptThe user_prompt provided at initialization,
after being formatted with markdown.
valueThe content of the stream. It updates constantly until the stream ends.
Inherited methods
new()Start a StreamHandler. Recommended to be assigned to the stream_handler name.
OpenaiStreamParser$new(session = NULL, user_prompt = NULL)sessionThe shiny session it will send the message to (optional).
user_promptThe 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_eventAn 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)deepWhether to make a deep clone.
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.