1. Go to this page and download the library: Download kargnas/instructrice 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/ */
kargnas / instructrice example snippets
use AdrienBrault\Instructrice\InstructriceFactory;
use AdrienBrault\Instructrice\LLM\Provider\Ollama;
use AdrienBrault\Instructrice\LLM\Provider\OpenAi;
use AdrienBrault\Instructrice\LLM\Provider\Anthropic;
$instructrice = InstructriceFactory::create(
defaultLlm: Ollama::HERMES2THETA_LLAMA3_8B,
apiKeys: [ // Unless you inject keys here, api keys will be fetched from environment variables
OpenAi::class => $openAiApiKey,
Anthropic::class => $anthropicApiKey,
],
);
use AdrienBrault\Instructrice\Attribute\Prompt;
class Character
{
// The prompt annotation lets you add instructions specific to a property
#[Prompt('Just the first name.')]
public string $name;
public ?string $rank = null;
}
$characters = $instructrice->getList(
Character::class,
'Colonel Jack O\'Neil walks into a bar and meets Major Samanta Carter. They call Teal\'c to join them.',
);
/*
dump($characters);
array:3 [
0 => Character^ {
+name: "Jack"
+rank: "Colonel"
}
1 => Character^ {
+name: "Samanta"
+rank: "Major"
}
2 => Character^ {
+name: "Teal'c"
+rank: null
}
]
*/
use AdrienBrault\Instructrice\InstructriceFactory;
use AdrienBrault\Instructrice\LLM\Provider\OpenAi;
$instructrice->get(
...,
llm: OpenAi::GPT_4T, // API Key will be fetched from the OPENAI_API_KEY environment variable
);
use AdrienBrault\Instructrice\LLM\LLMConfig;
use AdrienBrault\Instructrice\LLM\Cost;
use AdrienBrault\Instructrice\LLM\OpenAiJsonStrategy;
use AdrienBrault\Instructrice\LLM\Provider\Ollama;
$instructrice->get(
...,
llm: Ollama::create(
'codestral:22b-v0.1-q5_K_M', // check its license first!
32000,
),
);
use AdrienBrault\Instructrice\LLM\LLMConfig;
use AdrienBrault\Instructrice\LLM\Cost;
use AdrienBrault\Instructrice\LLM\OpenAiJsonStrategy;
$instructrice->get(
...,
llm: new LLMConfig(
uri: 'https://api.together.xyz/v1/chat/completions',
model: 'meta-llama/Llama-3-70b-chat-hf',
contextWindow: 8000,
label: 'Llama 3 70B',
provider: 'Together',
cost: Cost::create(0.9),
strategy: OpenAiJsonStrategy::JSON,
headers: [
'Authorization' => 'Bearer ' . $apiKey,
]
),
);