| OpenaiStreamParser {gptstudio} | R Documentation |
Stream handler for chat completions
Description
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 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.
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
Public 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)
Arguments
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).
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.
Usage
OpenaiStreamParser$append_parsed_sse(parsed_event)
Arguments
parsed_eventAn already parsed server-sent event to append to the events field.
Method clone()
The objects of this class are cloneable with this method.
Usage
OpenaiStreamParser$clone(deep = FALSE)
Arguments
deepWhether to make a deep clone.