modelflow-ai / mistral
Mistral API 客户端。
Requires
- php: ^8.2
- modelflow-ai/api-client: ^0.2
- webmozart/assert: ^1.11
Requires (Dev)
- asapo/remove-vendor-plugin: ^0.1
- jangregor/phpstan-prophecy: ^1.0
- 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: ^6.4 || ^7.0
This package is auto-updated.
Last update: 2024-08-25 18:52:46 UTC
README
Modelflow AI
Mistral
Mistral 软件包是 Mistral AI ([Mistral AI](https://mistral.ai/)) 的全面 API 客户端,使用 PHP 开发。它提供了一个强大而高效的接口,用于与 Mistral AI 模型交互,使开发者能够无缝地将 AI 功能集成到他们的 PHP 应用程序中。
此软件包的设计重点是易用性、性能和灵活性。它允许开发者充分利用 Mistral AI 模型的全部潜力,从创建聊天对话到获取聊天完成,所有这些都可以通过简单直观的 API 实现。
虽然 Mistral 软件包可以与其他软件包一起使用,但重要的是要注意,它是独立运行的,并且与任何其他软件包或系统没有直接连接。这种独立性确保了开发者可以在项目中集成 Mistral 软件包而无需任何依赖项或冲突。
注意:这是
modelflow-ai
项目的一部分,请在此 主要存储库 中创建问题。
注意:此项目正在积极开发中,任何反馈都备受赞赏。
安装
要安装 Mistral 软件包,您需要在您的机器上安装 PHP 8.2 或更高版本以及 Composer。然后,您可以通过运行以下命令将软件包添加到项目中
composer require modelflow-ai/mistral
示例
以下是一些如何在 PHP 应用程序中使用 Mistral 的示例。您可以在 示例目录 中找到更多详细示例。
使用方法
创建客户端
首先,您需要创建一个客户端。客户端是与 Mistral AI 模型交互的主要入口点。您可以使用 Mistral
类创建客户端
use ModelflowAi\Mistral\Mistral; $client = Mistral::client('your-api-key');
使用聊天资源
聊天资源允许您创建聊天对话并获取聊天完成。
$chat = $client->chat(); // Create a chat conversation $parameters = [ 'model' => 'mistral-medium', 'messages' => [ [ 'role' => 'system', 'content' => 'You are a helpful assistant.' ], [ 'role' => 'user', 'content' => 'Who won the world series in 2020?' ] ] ]; $response = $chat->create($parameters); // The response is an instance of CreateResponse echo $response->id;
使用嵌入资源
嵌入资源允许您生成和操作数据的嵌入。
$embeddings = $client->embeddings(); // Generate embeddings for your data $parameters = [ 'model' => 'mistral-medium', 'texts' => ['text1', 'text2'] ]; $response = $embeddings->create($parameters); // The response is an instance of CreateResponse echo $response->id;
API 文档
有关 Mistral API 的更多信息,请参阅 官方 API 文档。
开放点
模型 API
模型 API 是我们正在积极开发的另一个领域。一旦完成,这将使用户能够直接从 Mistral 软件包中管理和交互 AI 模型。
测试
要运行测试,请使用 PHPUnit
composer test
贡献
欢迎贡献。请在 https://github.com/modelflow-ai/.github 的主要存储库中打开问题或提交拉取请求。
许可证
此项目受 MIT 许可证的许可。有关完整的版权和许可信息,请参阅与源代码一起分发的 LICENSE 文件。