-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.readme.yaml
48 lines (40 loc) · 1.81 KB
/
.readme.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
title: Anthropic Adapter
description: The adapter integrates Anthropic AI models into Modelflow AI.
shortDescription: The adapter for the Anthropic API client.
examples: true
usage: |
First, initialize the client:
```php
use ModelflowAi\Anthropic\Anthropic;
$client = Anthropic::client('your-api-key');
```
Then, you can use the `AnthropicChatModelAdapter`:
```php
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);
```