Learn how to handle streaming responses using the Instructor HTTP client API.
stream
option set to true
:
stream
option tells the HTTP client to treat the response as a stream, which means:
stream()
method, which returns a PHP Generator:
stream()
method reads the response in small chunks. You can control the chunk size by passing a parameter:
StreamByLineMiddleware
to simplify this task:
null
, that line will be skipped in the stream.
StreamByLineMiddleware
to process streaming responses from the OpenAI API: