nuodonato / anthropic-php
Anthropic API 的 PHP 客户端
0.1.5
2024-07-19 11:07 UTC
Requires
- php: ^8.1
- ext-fileinfo: *
- illuminate/http: ^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.1
Requires (Dev)
- env/dotenv: @stable
- phpstan/phpstan: ^1.10
README
一个简单的 PHP 库,用于连接到 Anthropic API(Claude)。
我创建这个包是为了满足我在 AI 项目中的个人需求。我知道还有其他类似的包,但它们要么没有所有必需的功能,要么我不喜欢它们的实现和使用。
特性
- 消息 API
- 支持多内容消息(视觉)
- 工具使用(测试版)
- 完成 API(旧版)
- 帮助您在发送到 API 之前构建和验证消息/工具数据结构
路线图
- 流式传输
安装
composer require nunodonato/anthropic-php
使用
更多信息即将到来。
实例化客户端
use NunoDonato\AnthropicAPIPHP\Client; // ... $client = new Client($yourApiKey);
消息 API 使用
use NunoDonato\AnthropicAPIPHP\Client; use NunoDonato\AnthropicAPIPHP\Messages; // ... $client = new Client($yourApiKey); $messages = new Messages(); $messages->addUserTextMessage('Hello AI!'); $response = $this->client->messages(Client::MODEL_SONNET, $messages); // you can chain messages $messages->addUserTextMessage('Hello AI!') ->addAssistantTextMessage('Hello human!') ->addUserImageMessage('https://example.com/image.jpg', 'What do you see here?');
可用模型
const MODEL_OPUS = 'claude-3-opus-20240229'; const MODEL_SONNET = 'claude-3-sonnet-20240229'; const MODEL_HAIKU = 'claude-3-haiku-20240307'; const MODEL_3_5_SONNET = 'claude-3-5-sonnet-20240620'; const MODEL_CLAUDE_2 = 'claude-2.1';