View Source ExOpenAi.StreamProcessor (ex_open_ai v2.0.1)
ExOpenAi.StreamProcessor
is a module that handles streaming HTTP responses for the ExOpenAi library.
It provides functions to process and parse chunks of data as they are received from the HTTP stream. It works with the ExOpenAi.Parser
module to parse and decode the received data.
functions
Functions
close_async_response/1
: Closes the async response by stopping the hackney process.handle_async_response/2
: Handles different types of async responses, such as status, headers, chunks, and end of the stream.parse_chunk/3
: A private function that splits the received chunk, trims it, and decodes it using the provided module.decode_chunk/2
: A private function that decodes the chunk based on its content. If the chunk is "[DONE]", it returns{:done, ""}
, otherwise, it calls the Parser to parse the chunk.
usage
Usage
The primary use case for this module is to handle streaming HTTP responses from the OpenAI API in a smooth and efficient manner.
By working with the ExOpenAi.Parser
module, it allows the ExOpenAi library to process the data as it is received, rather than waiting for the entire response.