PHP code example of modelflow-ai / anthropic
1. Go to this page and download the library: Download modelflow-ai/anthropic 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/ */
modelflow-ai / anthropic example snippets
use ModelflowAi\Anthropic\Anthropic;
$client = Anthropic::client('your-api-key');
use ModelflowAi\Anthropic\Model;
$chat = $client->chat();
// Create a chat conversation
$parameters = [
'model' => Model::CLAUDE_3_OPUS->value,
'messages' => [
[
'role' => 'system',
'content' => 'You are a helpful assistant.'
],
[
'role' => 'user',
'content' => 'Who won the world series in 2020?'
]
]
];
$response = $chat->create($parameters);
// The response is an instance of CreateResponse
echo $response->content[0]->text;