- Can I use this package with Laravel Sail for local AI model testing?
- Yes, this package works seamlessly with Laravel Sail. Docker Model Runner integrates directly with Docker containers, so you can deploy and test models locally using Sail’s built-in Docker environment. Ensure your `docker-compose.yml` includes the Model Runner service, and configure Laravel’s `.env` with the correct Docker host and model endpoints.
- How do I dynamically route AI model requests (e.g., /chat → Ollama, /embed → BAAI) in Laravel?
- Use Laravel’s route model binding or middleware to leverage Symfony’s Provider abstraction. Bind the `ModelClient` to your container and create a middleware that resolves the correct model based on the route. For example, inject a `ModelProvider` service into your controller and let it handle model selection via `ModelClientInterface`.
- What Laravel versions and PHP requirements does this package support?
- This package requires PHP 8.2+ due to Symfony 7.x dependencies, which may necessitate upgrading your Laravel app (Laravel 10+). If you’re on an older version, consider using polyfills like `symfony/polyfill` or upgrading Laravel. Always check the [Symfony AI docs](https://symfony.com/doc/current/ai.html) for compatibility.
- How do I handle streaming responses (e.g., chatbot replies) in Laravel?
- Symfony’s `DeltaInterface` supports chunked responses, which you can stream in Laravel using `StreamedResponse`. For real-time updates, integrate with Laravel Echo and WebSockets. Example: Return a `StreamedResponse` from your controller and pipe the model’s delta events into it, then push updates to clients via Pusher or similar.
- Are there Laravel-specific alternatives to this Symfony-based package?
- Yes, alternatives like `laravel-ai` or `ai-sdk` (e.g., Mistral AI) offer tighter Laravel integration with Blade directives, Eloquent hooks, and native queue support. However, this package provides direct Docker Model Runner access, which is ideal for on-premise or custom models. Choose based on whether you prioritize Laravel ecosystem tightness or Docker flexibility.
- How do I configure Docker Model Runner environment variables in Laravel?
- Add Docker-specific variables to your `.env` (e.g., `DOCKER_HOST=unix:///var/run/docker.sock`, `MODEL_ENDPOINT=http://localhost:8080`). Validate these in your `AppServiceProvider` using `vlucas/phpdotenv` or Laravel’s validation rules. For runtime checks, use `Docker::checkConnection()` or a custom middleware to ensure Docker is available before processing requests.
- Can I use this package with Laravel Queues for async AI model inference?
- Yes, but you’ll need to wrap the `ModelClient` in a queueable job (e.g., `AiModelJob`). Ensure the client is serializable or use Laravel’s `serializable` trait. Dispatch the job from your controller or command, then handle the response in the job’s `handle()` method. For streaming, consider using Laravel’s `afterCommit()` hook to process results asynchronously.
- How do I test Docker-dependent functionality in Laravel’s CI/CD pipeline?
- Use Docker-in-Docker (DinD) or Kubernetes in your CI (e.g., GitHub Actions with `docker/docker-in-docker`). For local testing, tools like `testcontainers/php` can simulate Docker environments. Mock the `ModelClientInterface` in unit tests and use Laravel Pint or Pest to validate configurations. Avoid running full Docker containers in CI unless necessary for integration tests.
- What’s the best way to handle errors (e.g., Docker connection failures) in Laravel?
- Map Symfony’s `InvalidArgumentException` to Laravel’s problem details or form validation responses using `symfony/http-foundation`. Create a global exception handler to convert Docker-specific errors into consistent HTTP responses. For operational visibility, log errors to Laravel Telescope or a dedicated monitoring tool like Sentry.
- How do I hide Symfony’s ModelClient complexity from Laravel developers?
- Create Laravel-specific facades (e.g., `Ai::completion()`, `Ai::embed()`) that wrap Symfony’s `ModelClient`. Use service providers to bind interfaces (e.g., `ModelClientInterface`) to concrete implementations. Document Symfony-specific patterns in a team wiki or inline comments to reduce onboarding friction. This approach keeps your codebase Laravel-native while leveraging Symfony’s backend.