Skip to content

Commit 6d30cc5

Browse files
committed
Fixes+additions in docs
1 parent 569bf47 commit 6d30cc5

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

docs/hub/advanced/function_arguments.md

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Extracting arguments of function or method
22

3-
Instructor offers Call class to extract arguments of a function or method from content.
4-
This is useful when you want to build tool usage capability, e.g. for AI chatbots or agents.
3+
Instructor offers FunctionCall class to extract arguments of a function
4+
or method from content.
5+
6+
This is useful when you want to build tool use capability, e.g. for AI
7+
chatbots or agents.
58

69
```php
710
<?php
@@ -11,20 +14,23 @@ $loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');
1114
use Cognesy\Instructor\Extras\FunctionCall\FunctionCall;
1215
use Cognesy\Instructor\Instructor;
1316

14-
/** Save user data to storage */
15-
function saveUser(string $name, int $age, string $country) {
16-
// Save user to database
17-
echo "Saving user ... saveUser('$name', $age, '$country')\n";
17+
class DataStore
18+
{
19+
/** Save user data to storage */
20+
public function saveUser(string $name, int $age, string $country) : void {
21+
// Save user to database
22+
echo "Saving user ... saveUser('$name', $age, '$country')\n";
23+
}
1824
}
1925

2026
$text = "His name is Jason, he is 28 years old and he lives in Germany.";
2127
$args = (new Instructor)->respond(
2228
messages: $text,
23-
responseModel: FunctionCall::fromCallable(saveUser(...)),
29+
responseModel: FunctionCall::fromMethodName(DataStore::class, 'saveUser'),
2430
);
2531

2632
echo "\nCalling the function with the extracted arguments:\n";
27-
saveUser(...$args);
33+
(new DataStore)->saveUser(...$args);
2834

2935
echo "\nExtracted arguments:\n";
3036
dump($args);

docs/hub/advanced/language_programs.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@ $getStats = new GetStats($instructor, $directoryContents);
172172
$emailStats = $getStats->with(EmailStats::for('inbox'));
173173

174174
echo "Results:\n";
175-
dump($emailStats->get());
175+
dump($emailStats->get());
176+
?>
177+
```
178+

docs/hub/api_support/llm_support_anthropic.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ $user = $instructor->respond(
4545
messages: "Jason (@jxnlco) is 25 years old and is the admin of this project. He likes playing football and reading books.",
4646
responseModel: User::class,
4747
model: 'claude-3-haiku-20240307',
48-
mode: Mode::Json,
48+
mode: Mode::Tools,
4949
//options: ['stream' => true ]
5050
);
5151

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Support for Cohere API
2+
3+
Instructor supports Cohere API - you can find the details on how to configure
4+
the client in the example below.
5+
6+
Mode compatibility:
7+
- Mode::MdJson - supported, recommended
8+
- Mode::Json - not supported by Cohere
9+
- Mode::Tools - partially supported, not recommended
10+
11+
Reasons Mode::Tools is not recommended:
12+
13+
- Cohere does not support JSON Schema, which only allows to extract very simple data schemas.
14+
- Performance of the currently available versions of Cohere models in tools mode for Instructor use case (data extraction) is extremely poor.
15+
16+
```php
17+
<?php
18+
$loader = require 'vendor/autoload.php';
19+
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/');
20+
21+
use Cognesy\Instructor\Clients\Cohere\CohereClient;
22+
use Cognesy\Instructor\Enums\Mode;
23+
use Cognesy\Instructor\Instructor;
24+
use Cognesy\Instructor\Utils\Env;
25+
26+
enum UserType : string {
27+
case Guest = 'guest';
28+
case User = 'user';
29+
case Admin = 'admin';
30+
}
31+
32+
class User {
33+
public int $age;
34+
public string $name;
35+
public string $username;
36+
public UserType $role;
37+
/** @var string[] */
38+
public array $hobbies;
39+
}
40+
41+
// Create instance of client initialized with custom parameters
42+
$client = new CohereClient(
43+
apiKey: Env::get('COHERE_API_KEY'),
44+
);
45+
46+
/// Get Instructor with the default client component overridden with your own
47+
$instructor = (new Instructor)->withClient($client);//->withDebug();
48+
49+
$user = $instructor->respond(
50+
messages: "Jason (@jxnlco) is 25 years old and is the admin of this project. He likes playing football and reading books.",
51+
responseModel: User::class,
52+
model: 'command-r-plus',
53+
mode: Mode::MdJson,
54+
//options: ['stream' => true ]
55+
);
56+
57+
print("Completed response model:\n\n");
58+
dump($user);
59+
60+
assert(isset($user->name));
61+
assert(isset($user->age));
62+
?>
63+
```

0 commit comments

Comments
 (0)