modelflow-ai / mistral-adapter
Integrates the mistral into modelflow-ai.
Requires
- php: ^8.2
- modelflow-ai/mistral: ^0.2
Requires (Dev)
- asapo/remove-vendor-plugin: ^0.1
- jangregor/phpstan-prophecy: ^1.0
- modelflow-ai/chat: ^0.2
- modelflow-ai/embeddings: ^0.2
- modelflow-ai/prompt-template: 0.2.x-dev
- php-cs-fixer/shim: ^3.15
- phpspec/prophecy-phpunit: ^2.1@stable
- phpstan/extension-installer: ^1.2
- phpstan/phpstan: ^1.10, <1.10.55
- phpstan/phpstan-phpunit: ^1.3@stable
- phpunit/phpunit: ^10.3
- rector/rector: ^0.18.1
- symfony/dotenv: 7.1.x-dev
Suggests
- modelflow-ai/embeddings: To use the embeddings.
README
Modelflow AI
Mistral Adapter
The adapter integrates Mistral 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 Mistral 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/mistral-adapter
Examples
Here are some examples of how you can use the Mistral Adapter in your PHP applications. You can find more detailed examples in the examples directory.
Usage
First, initialize the client:
use ModelflowAi\Mistral\Mistral; $client = Mistral::client('your-api-key');
Then, you can use the MistralChatModelAdapter
:
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
:
use ModelflowAi\MistralAdapter\Embeddings\MistralEmbeddingAdapter; $embeddingsAdapter = new MistralEmbeddingAdapter($client); $vector = $embeddingsAdapter->embedText('your-input');
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.