modelflow-ai/anthropic-adapter

Integrates the anthropic into modelflow-ai.

0.2.x-dev 2024-05-15 20:21 UTC

This package is auto-updated.

Last update: 2024-05-15 20:21:56 UTC


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 Mistral package 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\Core\AIRequestHandler;
use ModelflowAi\Core\DecisionTree\AIModelDecisionTree;
use ModelflowAi\Core\DecisionTree\DecisionRule;
use ModelflowAi\Core\Request\Criteria\CapabilityCriteria;
use ModelflowAi\Anthropic\Model;
use ModelflowAi\AnthropicAdapter\Model\AnthropicChatModelAdapter;

$modelAdapter = new AnthropicChatModelAdapter($client, Model::LARGE);
$decisionTree = new AIModelDecisionTree([
    new DecisionRule($modelAdapter, [CapabilityCriteria::SMART]),
]]);
$handler = new AIRequestHandler($decisionTree);

/** @var AIChatResponse $response */
$response = $handler->createChatRequest(
    ...ChatPromptTemplate::create(
        new AIChatMessage(AIChatMessageRoleEnum::SYSTEM, 'You are an {feeling} bot'),
        new AIChatMessage(AIChatMessageRoleEnum::USER, 'Hello {where}!'),
    )->format(['where' => 'world', 'feeling' => 'angry']),
)
    ->addCriteria(PrivacyCriteria::MEDIUM)
    ->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/modelflow-ai.

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.