aisdk/mistral
Composer 安装命令:
composer require aisdk/mistral
包简介
Official Mistral provider for the PHP AI SDK.
README 文档
README
Official Mistral provider for the PHP AI SDK. Uses Mistral's OpenAI-compatible Chat Completions API and embeddings endpoint.
Installation
composer require aisdk/mistral
Basic Usage
use AiSdk\Generate; use AiSdk\Mistral; $result = Generate::text() ->model(Mistral::model('mistral-large-latest')) ->instructions('Write short, clear answers.') ->prompt('Explain closures in PHP.') ->run(); echo $result->text;
Default model shorthand:
Generate::model(Mistral::model('mistral-large-latest')); $result = Generate::text('Explain closures in PHP.')->run();
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
MISTRAL_API_KEY |
API key for authentication | Required |
MISTRAL_BASE_URL |
Base URL for API requests | https://api.mistral.ai/v1 |
Programmatic Configuration
$provider = Mistral::create([ 'apiKey' => 'mistral-...', 'baseUrl' => 'https://api.mistral.ai/v1', 'headers' => ['X-Custom-Header' => 'value'], ]);
Supported Capabilities
| Capability | Support |
|---|---|
| Text generation | Native |
| Streaming | Native |
| Tool calling | Native |
| Structured output | Adapted (json_object + instruction); exact native support can be declared at runtime |
| Embeddings | Native |
| Text input | Native |
| Image input | Supported by the adapter; the selected model is validated by Mistral |
Streaming
use AiSdk\Generate; use AiSdk\Mistral; $stream = Generate::text('Tell me a story.') ->model(Mistral::model('mistral-large-latest')) ->stream(); foreach ($stream->chunks() as $chunk) { echo $chunk; } $result = $stream->run();
Embeddings
use AiSdk\Generate; use AiSdk\Mistral; $result = Generate::embedding(['Search query', 'Document text']) ->model(Mistral::model('mistral-embed')) ->providerOptions('mistral', ['user' => 'user-123']) ->run(); $queryVector = $result->embeddings[0]->vector; $documentVector = $result->embeddings[1]->vector;
Mistral's embedding request schema does not expose a dimensions field, so this adapter rejects the portable dimensions() option before sending a request.
Structured Output
Without an exact runtime capability override, the provider adapter degrades json_schema to json_object with an injected JSON instruction:
use AiSdk\Generate; use AiSdk\Mistral; use AiSdk\Schema; $result = Generate::text() ->model(Mistral::model('mistral-large-latest')) ->prompt('Extract the city and country from: Lahore, Pakistan.') ->output(Schema::object( name: 'address', properties: [ Schema::string(name: 'city')->required(), Schema::string(name: 'country')->required(), ], )) ->run();
Models with native json_schema support (openai/gpt-oss-20b, openai/gpt-oss-120b, moonshotai/kimi*) use the native format directly.
Tools
use AiSdk\Generate; use AiSdk\Mistral; use AiSdk\Schema; use AiSdk\Tool; $weather = Tool::make('weather', 'Get current weather') ->input(Schema::string(name: 'city')->required()) ->run(fn (string $city): string => "Sunny in {$city}"); $result = Generate::text() ->model(Mistral::model('mistral-large-latest')) ->prompt('What is the weather in Lahore?') ->tool($weather) ->run();
Model IDs and Capabilities
Mistral model IDs pass through unchanged and do not need to be registered. The package does not ship a model inventory; the Mistral API remains the authority on whether a particular model accepts a requested feature.
Capabilities describe what the Mistral adapter can serialize. The Mistral API returns a normalized SDK exception if the selected model or requested feature is rejected.
Provider-Specific Options
Raw provider options can be passed as an escape hatch:
$result = Generate::text('Hello') ->model(Mistral::model('mistral-large-latest')) ->providerOptions('mistral', [ 'raw' => ['top_k' => 40], ]) ->run();
Testing
composer test
Links
aisdk/mistral 适用场景与选型建议
aisdk/mistral 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 07 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「ai」 「llm」 「mistral」 「openai-compatible」 「aisdk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 aisdk/mistral 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 aisdk/mistral 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 aisdk/mistral 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a chat abstraction for the Modelflow AI
An integration of modelflow-ai via a bundle into the Symfony Framework.
Allows to define experts for AI-Communication. Experts uses
AI-powered content generation for Kirby CMS
Provides a completion abstraction for the Modelflow AI
Client for mistral API.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-15