Note: This is part of the
modelflow-ai
project create issues in the main repository.
Note: This project is heavily under development and any feedback is greatly appreciated.
To install the Anthropic package, you need to have PHP 8.2 or higher and Composer installed on your machine. Then, you can add the package to your project by running the following command:
composer require modelflow-ai/anthropic
Here are some examples of how you can use the Anthropic in your PHP applications. You can find more detailed examples in the examples directory.
First, you need to create a client. The client is the main entry point to interact with the Anthropic AI model. You can
create a client using the Anthropic
class:
use ModelflowAi\Anthropic\Anthropic;
$client = Anthropic::client('your-api-key');
The Chat resource allows you to create chat conversations and get chat completions.
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;
For more detailed information about the Anthropic API, please refer to the official API documentation.
Streaming of tools are not yet available in the Anthropic API. As soon as they are available, we will provide a the stream option with the tools.
The Text Completions resource is not yet in this package.
The Embeddings resource is not yet in the Anthropic API. As soon as it is available, we will provide a resource to generate and manipulate embeddings for your data.
To run the tests, use PHPUnit:
composer test
Contributions are welcome. Please open an issue or submit a pull request in the main repository at https://github.com/modelflow-ai/.github.
This project is licensed under the MIT License. For the full copyright and license information, please view the LICENSE file that was distributed with this source code.