PHP code example of cognesy / instructor-config

1. Go to this page and download the library: Download cognesy/instructor-config library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cognesy / instructor-config example snippets


use Cognesy\Config\Config;
use Cognesy\Config\ConfigLoader;

$single = Config::fromPaths(
    __DIR__ . '/packages/polyglot/resources/config',
    __DIR__ . '/packages/http-client/resources/config',
)->load('llm/presets/openai.yaml')->toArray();

$configs = ConfigLoader::fromPaths(
    __DIR__ . '/packages/polyglot/resources/config',
    __DIR__ . '/packages/http-client/resources/config',
)->withCache(__DIR__ . '/var/cache/instructor-config.php');

$one = $configs->load('llm/presets/openai.yaml')->toArray();
$many = $configs->loadAll(
    'llm/presets/openai.yaml',
    'http/profiles/curl.yaml',
);

use Cognesy\Config\Config;
use Cognesy\Config\EnvTemplate;
use Cognesy\Config\Secrets\DotenvFileSecretSource;
use Cognesy\Config\Secrets\EnvironmentSecretSource;
use Cognesy\Config\Secrets\SecretResolver;

$secrets = new SecretResolver(
    new EnvironmentSecretSource('process-environment'),
    DotenvFileSecretSource::optional(__DIR__.'/.env', 'workspace-env'),
    DotenvFileSecretSource::optional('/app/private/credentials.env', 'app-credentials'),
);

$entry = Config::fromPaths(__DIR__.'/config')
    ->withTemplate(new EnvTemplate($secrets))
    ->load('llm.yaml');

$source = $secrets->resolve('OPENAI_API_KEY')?->source;

use Cognesy\Config\Dsn;

$raw = Dsn::fromString('driver=openai,metadata.region=us-east-1')->toArray();