PHP code example of modelflow-ai / mistral-adapter
1. Go to this page and download the library: Download modelflow-ai/mistral-adapter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
modelflow-ai / mistral-adapter example snippets
use ModelflowAi\Mistral\Mistral;
$client = Mistral::client('your-api-key');
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);
use ModelflowAi\MistralAdapter\Embeddings\MistralEmbeddingAdapter;
$embeddingsAdapter = new MistralEmbeddingAdapter($client);
$vector = $embeddingsAdapter->embedText('your-input');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.