承接 modelflow-ai/anthropic-adapter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

modelflow-ai/anthropic-adapter

最新稳定版本:0.3.0

Composer 安装命令:

composer require modelflow-ai/anthropic-adapter

包简介

Integrates the anthropic into modelflow-ai.

README 文档

README


Anthropic Adapter Logo

Modelflow AI
Anthropic Adapter


The adapter integrates Anthropic AI models into Modelflow AI.

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.


Installation

To install the Anthropic Adapter 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-adapter

Examples

Here are some examples of how you can use the Anthropic Adapter in your PHP applications. You can find more detailed examples in the examples directory.

Usage

First, initialize the client:

use ModelflowAi\Anthropic\Anthropic;

$client = Anthropic::client('your-api-key');

Then, you can use the AnthropicChatModelAdapter:

use ModelflowAi\Chat\Adapter\AIChatAdapterInterface;
use ModelflowAi\Chat\AIChatRequestHandler;
use ModelflowAi\Chat\Request\AIChatRequest;
use ModelflowAi\Chat\Request\Message\AIChatMessage;
use ModelflowAi\Chat\Request\Message\AIChatMessageRoleEnum;
use ModelflowAi\DecisionTree\DecisionTree;
use ModelflowAi\DecisionTree\Criteria\CapabilityCriteria;
use ModelflowAi\DecisionTree\DecisionRule;
use ModelflowAi\Anthropic\Model;
use ModelflowAi\AnthropicAdapter\Chat\AnthropicChatAdapter;
use ModelflowAi\PromptTemplate\ChatPromptTemplate;

$modelAdapter = new AnthropicChatAdapter($client, Model::CLAUDE_3_HAIKU);

/** @var DecisionTreeInterface<AIChatRequest, AIChatAdapterInterface> $decisionTree */
$decisionTree = new DecisionTree([
    new DecisionRule($modelAdapter, [CapabilityCriteria::SMART]),
]);
$handler = new AIChatRequestHandler($decisionTree);

$response = $handler->createRequest(
    ...ChatPromptTemplate::create(
        new AIChatMessage(AIChatMessageRoleEnum::SYSTEM, 'You are an {feeling} bot'),
        new AIChatMessage(AIChatMessageRoleEnum::USER, 'Hello {where}!'),
    )->format(['where' => 'world', 'feeling' => 'angry']),
)
    ->addCriteria(CapabilityCriteria::SMART)
    ->build()
    ->execute();

echo \sprintf('%s: %s', $response->getMessage()->role->value, $response->getMessage()->content);

Contributing

Contributions are welcome. Please open an issue or submit a pull request in the main repository at https://github.com/modelflow-ai/.github.

License

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.

统计信息

  • 总下载量: 1.46k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 1

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-04