1. Go to this page and download the library: Download mozex/anthropic-laravel 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/ */
mozex / anthropic-laravel example snippets
use Anthropic\Laravel\Facades\Anthropic;
$result = Anthropic::messages()->create([
'model' => 'claude-3-opus-20240229',
'max_tokens' => 1024,
'messages' => [
['role' => 'user', 'content' => 'Hello!'],
],
]);
echo $result->content[0]->text; // Hello! How can I assist you today?
use Anthropic\Laravel\Facades\Anthropic;
use Anthropic\Responses\Completions\CreateResponse;
Anthropic::fake([
CreateResponse::fake([
'completion' => 'awesome!',
]),
]);
$completion = Anthropic::completions()->create([
'model' => 'claude-2.1',
'prompt' => '\n\nHuman: PHP is \n\nAssistant:',
'max_tokens_to_sample' => 100,
]);
expect($completion['completion'])->toBe('awesome!');
// assert completion create request was sent
Anthropic::assertSent(Completions::class, function (string $method, array $parameters): bool {
return $method === 'create' &&
$parameters['model'] === 'claude-2.1' &&
$parameters['prompt'] === 'PHP is ';
});
bash
php artisan anthropic:install
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.