streamChatCompletion

Calls the chat completions API endpoint and streams each token 1 at a time for a faster response.

This method is technically not blocking, but the returned iterable will block until the next token is generated.

// Each iteration of the loop will block until the next token is streamed
for (chunk in openAI.streamChatCompletion(request)) {
// Do something with the chunk
}

Return

The response from the API

Parameters

request

The request to send to the API