- How do I integrate Mistral AI into a Laravel app using this Symfony bridge?
- Install the package via Composer (`composer require symfony/ai-mistral-platform`), then configure a PSR-18 HTTP client (e.g., Guzzle) in Laravel’s `AppServiceProvider`. Bind the `MistralClient` to Laravel’s container and inject it where needed, leveraging Symfony AI’s abstractions like `ChatCompletionClient` or `EmbeddingClient`.
- Does this package support dynamic provider switching (e.g., fallback to OpenAI if Mistral fails)?
- Yes, the `Provider` abstraction in Symfony AI (v0.8.0+) enables dynamic routing between Mistral and other providers. In Laravel, you can implement this via service container bindings or middleware, using Laravel’s exception handling to trigger fallbacks when Mistral errors occur.
- Can I use streaming responses (e.g., real-time chat) with this package in Laravel?
- Streaming is supported via Symfony’s `DeltaInterface`, but Laravel requires additional setup. For real-time UIs, use Laravel Echo or WebSockets to process streams. For async processing, dispatch queue jobs to handle `DeltaInterface` events incrementally, though this adds complexity.
- What Laravel versions and dependencies are required for this package?
- The package targets PHP 8.1+ and requires Symfony AI (v0.8.0+). Laravel compatibility depends on Symfony’s HTTP client (e.g., Guzzle 7.4+) and PSR-18 support. Test with Laravel 10+ for best results, as older versions may need manual container bindings or facade adjustments.
- How do I handle Mistral’s rate limits or token costs in Laravel?
- Use Laravel’s built-in rate-limiting middleware or custom logic to enforce Mistral’s API limits. For cost tracking, extend Symfony’s `AiEventDispatcher` with a Laravel event listener to log token usage, then integrate with monitoring tools like Sentry or Datadog via Laravel’s observability stack.
- Is there native Laravel configuration support (e.g., `.env` or `config/ai.php`)?
- No, but you can manually map Symfony’s YAML/PHP configs to Laravel’s `.env` or `config/ai.php`. For example, define `MISTRAL_API_KEY` in `.env` and bind it to the `MistralClient` constructor. A community-maintained config publisher could simplify this in the future.
- Can I test Mistral integrations in Laravel using Pest or PHPUnit?
- Yes, extend the package’s test fixtures (e.g., PDF examples) with Laravel-specific scenarios. Mock the `ClientInterface` in tests to simulate Mistral responses, then assert behavior using Laravel’s testing helpers. Focus on edge cases like rate limits or streaming failures.
- What are the risks of using this early-stage package in production?
- The package has minimal adoption (1 star, 0 dependents), so breaking changes from Symfony AI or Mistral’s API could require frequent updates. Mitigate risks by monitoring the [Symfony AI repo](https://github.com/symfony/ai) and implementing fallback providers. Cache responses aggressively to reduce API calls.
- Are there alternatives to this package for Laravel + Mistral integration?
- For direct Mistral integration, consider custom Laravel packages like `spatie/laravel-ai` (if extended for Mistral) or raw Guzzle clients. However, this package offers Symfony’s battle-tested abstractions (e.g., multi-provider routing) and PSR compliance, reducing boilerplate for Laravel apps already using Symfony components.
- How do I log or monitor Mistral API calls in Laravel?
- Bridge Symfony’s `AiEventDispatcher` to Laravel’s event system by creating a custom listener. Dispatch events like `AiRequestSent` or `AiResponseReceived` and log them via Monolog or forward to tools like Datadog. Use Laravel’s `Log::channel()` to route logs to different handlers.