This example shows how to process a JSON response from the OpenAI Chat API in streaming mode.
- We are looking for a JSON key named
questions
which contains an array of JSON objects with the keysquestion
andanswer
- As each question and answer pair is found we process it via the end_object block.
https://github.com/dgraham/json-stream https://github.com/alexrudall/ruby-openai
Add environment variables:
- OPENAI_API_KEY - your OpenAI Access Token
- OPENAI_API_ORG - your OpenAI Org ID
StructuredStreamExample.new.call
An example JSON response is shown but is not needed to try the code out.