ahmadrosid/laravel-anthropic
最新稳定版本:1.0.1
Composer 安装命令:
composer require ahmadrosid/laravel-anthropic
包简介
Unofficial anthropic client library for laravel.
README 文档
README
Unofficial Anthropic AI client for laravel.
Installation
composer require ahmarosid/laravel-anthropic
Env
Add an environment variable with the key ANTHROPIC_API_KEY.
ANTHROPIC_API_KEY=sk-...
Usage
Chat without streaming.
use Ahmadrosid\Laravel\Anthropic\AnthropicAI; $response = AnthropicAI::chat()->create([ 'model' => 'claude-3-opus-20240229', 'temperature' => 0, 'max_tokens' => 1024, 'system' => 'You are a helpfull assistant', 'messages' => [ [ 'role' => 'user', 'content' => 'Hello, how are you?' ] ], ]);
Chat with streaming.
use Ahmadrosid\Laravel\Anthropic\AnthropicAI; $response = AnthropicAI::chat()->createStreamed([ 'model' => 'claude-3-opus-20240229', 'temperature' => 0, 'max_tokens' => 1024, 'system' => 'You are a helpfull assistant', 'messages' => [ [ 'role' => 'user', 'content' => 'Hello, how are you?' ] ], ]); foreach ($response as $block) { foreach ($block->choices as $choice) { if ($choice->delta) { echo($choice->delta->content); } } }
Testing
You can mock the response from anthropic.
AnthropicAI::fake([ \Ahmarosid\Laravel\Anthropic\Responses\CreateResponse::fake([ 'role' => 'assistant', 'content' => [ [ 'type' => 'text', 'text' => 'Example mock response', ] ], 'usage' => [ 'input_tokens' => 10, 'output_tokens' => 10 ] ]) ]);
统计信息
- 总下载量: 44
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-14