Stream handler for chat completions
Stream handler for chat completions
Details
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 httr2::req_perform_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.
Super class
SSEparser::SSEparser -> OpenaiStreamParser
Public fields
shinySessionHolds the
sessionprovided at initializationuser_promptThe
user_promptprovided at initialization, after being formatted with markdown.valueThe content of the stream. It updates constantly until the stream ends.
Methods
Inherited methods
Method new()
Start a StreamHandler. Recommended to be assigned to the stream_handler name.
Usage
OpenaiStreamParser$new(session = NULL, user_prompt = NULL)Method append_parsed_sse()
Overwrites SSEparser$append_parsed_sse() to be able to
send a custom message to a shiny session, escaping shiny's reactivity.
