Skip to content

Commit

Permalink
README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebowczyk committed Mar 4, 2024
1 parent 5dc520c commit 73a5b47
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.",
Expand All @@ -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.",
Expand All @@ -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.",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 73a5b47

Please sign in to comment.