stream_chat_completion
sends the prepared chat completion request to the
OpenAI API and retrieves the streamed response.
Usage
stream_chat_completion(
messages = list(list(role = "user", content = "Hi there!")),
element_callback = openai_handler,
model = "gpt-4o-mini",
openai_api_key = Sys.getenv("OPENAI_API_KEY")
)
Arguments
- messages
A list of messages in the conversation, including the current user prompt (optional).
- element_callback
A callback function to handle each element of the streamed response (optional).
- model
A character string specifying the model to use for chat completion. The default model is "gpt-4o-mini".
- openai_api_key
A character string of the OpenAI API key. By default, it is fetched from the "OPENAI_API_KEY" environment variable. Please note that the OpenAI API key is sensitive information and should be treated accordingly.
Value
The same as httr2::req_perform_stream