Skip to content

Commit 2af15c1

Browse files
authored
Merge pull request #378 from alexrudall/add-json-mode-to-readme
Add JSON mode to the README
2 parents 8fa2d37 + dcd7757 commit 2af15c1

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,28 @@ puts response.dig("choices", 0, "message", "content")
217217
# => "The image depicts a serene natural landscape featuring a long wooden boardwalk extending straight ahead"
218218
```
219219

220+
#### JSON Mode
221+
222+
You can set the response_format to ask for responses in JSON (at least for `gpt-3.5-turbo-1106`):
223+
224+
```ruby
225+
response = client.chat(
226+
parameters: {
227+
model: "gpt-3.5-turbo-1106",
228+
response_format: { type: "json_object" },
229+
messages: [{ role: "user", content: "Hello! Give me some JSON please."}],
230+
temperature: 0.7,
231+
})
232+
puts response.dig("choices", 0, "message", "content")
233+
{
234+
"name": "John",
235+
"age": 30,
236+
"city": "New York",
237+
"hobbies": ["reading", "traveling", "hiking"],
238+
"isStudent": false
239+
}
240+
```
241+
220242
### Functions
221243

222244
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)