-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a5b931
commit e6fecc0
Showing
12 changed files
with
198 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: 'Using LLM API connections from config file' | ||
docname: 'using_config' | ||
--- | ||
|
||
## Overview | ||
|
||
Instructor allows you to define multiple API connections in `instructor.php` file. | ||
This is useful when you want to use different LLMs or API providers in your application. | ||
|
||
Connecting to LLM API via predefined connection is as simple as calling `withClient` | ||
method with the connection name. | ||
|
||
### Configuration file | ||
|
||
Default configuration file is located in `/config/instructor.php` in the root directory | ||
of Instructor codebase. | ||
|
||
You can set the location of the configuration file via `INSTRUCTOR_CONFIG_PATH` environment | ||
variable. You can use a copy of the default configuration file as a starting point. | ||
|
||
Config file defines connections to LLM APIs and their parameters. It also specifies | ||
the default connection to be used when calling Instructor without specifying the client | ||
connection. | ||
|
||
## Example | ||
|
||
```php | ||
<?php | ||
$loader = require 'vendor/autoload.php'; | ||
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/'); | ||
|
||
use Cognesy\Instructor\Instructor; | ||
|
||
class User { | ||
public int $age; | ||
public string $name; | ||
} | ||
|
||
// Get Instructor object with client defined in config.php under 'connections/openai' key | ||
$instructor = (new Instructor)->withClient('openai'); | ||
|
||
// Call with custom model and execution mode | ||
$user = $instructor->respond( | ||
messages: "Our user Jason is 25 years old.", | ||
responseModel: User::class, | ||
); | ||
|
||
// Use the results of LLM inference | ||
dump($user); | ||
assert(isset($user->name)); | ||
assert(isset($user->age)); | ||
?> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- | ||
title: 'Using LLM API connections from config file' | ||
docname: 'using_config' | ||
--- | ||
|
||
## Overview | ||
|
||
Instructor allows you to define multiple API connections in `instructor.php` file. | ||
This is useful when you want to use different LLMs or API providers in your application. | ||
|
||
Connecting to LLM API via predefined connection is as simple as calling `withClient` | ||
method with the connection name. | ||
|
||
### Configuration file | ||
|
||
Default configuration file is located in `/config/instructor.php` in the root directory | ||
of Instructor codebase. | ||
|
||
You can set the location of the configuration file via `INSTRUCTOR_CONFIG_PATH` environment | ||
variable. You can use a copy of the default configuration file as a starting point. | ||
|
||
Config file defines connections to LLM APIs and their parameters. It also specifies | ||
the default connection to be used when calling Instructor without specifying the client | ||
connection. | ||
|
||
## Example | ||
|
||
```php | ||
<?php | ||
$loader = require 'vendor/autoload.php'; | ||
$loader->add('Cognesy\\Instructor\\', __DIR__ . '../../src/'); | ||
|
||
use Cognesy\Instructor\Instructor; | ||
|
||
class User { | ||
public int $age; | ||
public string $name; | ||
} | ||
|
||
// Get Instructor object with client defined in config.php under 'connections/openai' key | ||
$instructor = (new Instructor)->withClient('openai'); | ||
|
||
// Call with custom model and execution mode | ||
$user = $instructor->respond( | ||
messages: "Our user Jason is 25 years old.", | ||
responseModel: User::class, | ||
); | ||
|
||
// Use the results of LLM inference | ||
dump($user); | ||
assert(isset($user->name)); | ||
assert(isset($user->age)); | ||
?> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.