-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.readme.yaml
More file actions
57 lines (46 loc) · 2.02 KB
/
.readme.yaml
File metadata and controls
57 lines (46 loc) · 2.02 KB
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
49
50
51
52
53
54
55
56
57
title: Mistral Adapter
description: The adapter integrates Mistral AI models into Modelflow AI.
shortDescription: The adapter for the Mistral API client.
examples: true
usage: |
First, initialize the client:
```php
use ModelflowAi\Mistral\Mistral;
$client = Mistral::client('your-api-key');
```
Then, you can use the `MistralChatModelAdapter`:
```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\Mistral\Model;
use ModelflowAi\MistralAdapter\Chat\MistralChatAdapter;
use ModelflowAi\PromptTemplate\ChatPromptTemplate;
$modelAdapter = new MistralChatAdapter($client, Model::LARGE);
/** @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);
```
And the `EmbeddingsAdapter`:
```php
use ModelflowAi\MistralAdapter\Embeddings\MistralEmbeddingAdapter;
$embeddingsAdapter = new MistralEmbeddingAdapter($client);
$vector = $embeddingsAdapter->embedText('your-input');
```