From 73a5b47cd49fc59fd6916bf1a2a119a2c6d6780c Mon Sep 17 00:00:00 2001 From: ddebowczyk Date: Mon, 4 Mar 2024 01:42:31 +0100 Subject: [PATCH] README.md --- README.md | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1b7ebc43..377b9b3f 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,7 @@ This is a simple example demonstrating how Instructor retrieves structured infor Response model class is a plain PHP class with typehints specifying the types of fields of the object. ```php -use Cognesy/Instructor/Instructor; +use Cognesy\Instructor\Instructor; use OpenAI; // Step 1: Define target data structure(s) @@ -159,7 +159,14 @@ $person = (new Instructor)->respond( You can provide a string instead of an array of messages. This is useful when you want to extract data from a single block of text and want to keep your code simple. ```php -use Cognesy/Instructor/Instructor; +// Usually, you work with sequences of messages: + +$value = (new Instructor)->respond( + messages: [['role' => 'user', 'content' => "His name is Jason, he is 28 years old."]], + responseModel: Person::class, +); + +// But if you want to keep it simple and just analyze a piece of text: $value = (new Instructor)->respond( messages: "His name is Jason, he is 28 years old.", @@ -173,7 +180,8 @@ $value = (new Instructor)->respond( Sometimes we just want to get quick results without defining a class for the response model, especially if we're trying to get a straight, simple answer in a form of string, integer, boolean or float. Instructor provides a simplified API for such cases. ```php -use Cognesy/Instructor/Instructor; +use Cognesy\Instructor\Instructor; +use Cognesy\Instructor\Extras\ScalarAdapter\Scalar; $value = (new Instructor)->respond( messages: "His name is Jason, he is 28 years old.", @@ -189,7 +197,8 @@ In this example, we're extracting a single integer value from the text. You can Additionally, you can use Scalar adapter to extract one of the provided options. ```php -use Cognesy/Instructor/Instructor; +use Cognesy\Instructor\Instructor; +use Cognesy\Instructor\Extras\ScalarAdapter\Scalar; $value = (new Instructor)->respond( messages: "His name is Jason, he currently plays Doom Eternal.", @@ -266,7 +275,7 @@ class Event { Instructor can retrieve complex data structures from text. Your response model can contain nested objects, arrays, and enums. ```php -use Cognesy/Instructor/Instructor; +use Cognesy\Instructor\Instructor; use OpenAI; // define a data structures to extract data into @@ -294,7 +303,7 @@ $person = (new Instructor)->respond( messages: [['role' => 'user', 'content' => $text]], responseModel: Person::class, client: OpenAI::client($yourApiKey), -); // client is passed explicitly, can specify eg. different base URL +); // client is passed explicitly, can specify e.g. different base URL // data is extracted into an object of given class assert($person instanceof Person); // true