From 9001da2c8e2f3ce107f191626dfbc2fe4c287b4d Mon Sep 17 00:00:00 2001 From: James Malin Date: Sat, 25 Nov 2023 22:45:30 -0800 Subject: [PATCH 1/2] Update README.md Added json_object example to readme to demonstrate how to get a JSON response from OpenAI. --- README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/README.md b/README.md index 914f792..6609277 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,31 @@ $complete = $open_ai->chat([ ]); ``` +For returning JSON responses from OpenAI you need to include the phrase JSON in your requests. + +```php +$complete = $open_ai->chat([ + 'model' => 'gpt-3.5-turbo-1106', + 'messages' => 'messages' => [ + [ + 'role' => 'system', + 'content' => 'You are a zoologist.' + ], + [ + 'role' => 'system', + 'content' => 'Respond with JSON. Use this structure: [{"animal":"","description":""}]' + ], + [ + 'role' => 'user', + 'content' => 'Supply a list of the most common animals you would see in a zoo.' + ], + ], + 'temperature' => 1, + 'max_tokens' => 3500, + 'response_format' => [ 'type' => 'json_object' ] +]); +``` + ## Accessing the Element ```php From a475ae62955be06a612854943a3d9495ddab7113 Mon Sep 17 00:00:00 2001 From: James Malin Date: Sat, 11 May 2024 07:51:44 -0700 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6609277..1272c8a 100644 --- a/README.md +++ b/README.md @@ -330,7 +330,7 @@ For returning JSON responses from OpenAI you need to include the phrase JSON in ```php $complete = $open_ai->chat([ 'model' => 'gpt-3.5-turbo-1106', - 'messages' => 'messages' => [ + 'messages' => [ [ 'role' => 'system', 'content' => 'You are a zoologist.'