Skip to content

Commit 1562d7b

Browse files
authored
Merge pull request #379 from alexrudall/add-json-mode-to-readme
Add JSON mode streaming example
2 parents 2af15c1 + e14e04a commit 1562d7b

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

+29
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,35 @@ You can set the response_format to ask for responses in JSON (at least for `gpt-
239239
}
240240
```
241241

242+
You can stream it as well!
243+
244+
```ruby
245+
response = client.chat(
246+
parameters: {
247+
model: "gpt-3.5-turbo-1106",
248+
messages: [{ role: "user", content: "Can I have some JSON please?"}],
249+
response_format: { type: "json_object" },
250+
stream: proc do |chunk, _bytesize|
251+
print chunk.dig("choices", 0, "delta", "content")
252+
end
253+
})
254+
{
255+
"message": "Sure, please let me know what specific JSON data you are looking for.",
256+
"JSON_data": {
257+
"example_1": {
258+
"key_1": "value_1",
259+
"key_2": "value_2",
260+
"key_3": "value_3"
261+
},
262+
"example_2": {
263+
"key_4": "value_4",
264+
"key_5": "value_5",
265+
"key_6": "value_6"
266+
}
267+
}
268+
}
269+
```
270+
242271
### Functions
243272

244273
You can describe and pass in functions and the model will intelligently choose to output a JSON object containing arguments to call those them. For example, if you want the model to use your method `get_current_weather` to get the current weather in a given location:

0 commit comments

Comments
 (0)