alle-ai / anthropic-api-php
一个用于与Anthropic API交互的PHP库
1.3
2024-03-11 05:42 UTC
Requires
- php: ^7.4 || ^8.0
- ext-curl: *
README
一个用于与Anthropic API交互的PHP库。
简介
Alle-AI anthropic-api-php 是一个包,它为从您的PHP应用程序中方便且直接地与 Anthropic Claude 模型交互提供了一种方法。如需更多信息,请联系 dickson@alle-ai.com。
安装
安装 Alle-AI anthropic-api-php 最推荐的方式是通过 composer:
composer require alle-ai/anthropic-api-php
使用方法
将 Alle-AI anthropic-api-php 包安装到您的项目中后,
// Load your project's composer autoloader (If you aren't already doing so). require_once(__DIR__ . '/vendor/autoload.php');
身份验证
为了验证您的API请求,您需要提供来自Anthropic的有效 API密钥
$api_key = 'your-anthropic-api-key';
请参阅 Anthropic API文档 了解获取API密钥的详细信息。
示例
将 Anthropic的Claude模型 集成到您的应用程序中,现在只需几行代码即可完成
使用Claude(claude-2.1)进行聊天完成
require_once 'vendor/autoload.php'; // Include the Composer autoloader $api_key = 'your-anthropic-api-key'; $anthropic_version = "2023-06-01"; $anthropic_api = new Alle_AI\Anthropic\AnthropicAPI($api_key, $anthropic_version); $prompt = "How many toes do dogs have?"; $data = array( 'prompt' => "\n\nHuman: ".$prompt."\n\nAssistant:", // Be sure to format prompt appropriately 'model' => 'claude-2.1', 'max_tokens_to_sample' => 300, 'stop_sequences' => array("\n\nHuman:") ); $response = $anthropic_api->generateText($data); echo $response['completion']; // To display only completion // Claude's Response: // Dogs typically have 4 toes on each of their front paws and 5 toes on each of their back paws, for a total of 18 toes.
注意:Anthropic正在逐步推出Claude。请参阅 此处了解如何获取访问权限。
支持
如果您有任何问题或反馈,请使用 讨论板,或者您可以发送邮件到 dickson@alle-ai.com。
许可证
本软件版权所有(c)2023-至今 Alle-AI | 您的全功能AI平台。本软件可免费使用、复制、修改、合并、发布和分发。有关版权和许可信息,请参阅 LICENSE 文件。