Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Ai Laravel Package

laravel/ai

Laravel AI SDK offers a unified, Laravel-friendly API for OpenAI, Anthropic, Gemini, and more. Build agents with tools and structured output, generate images, transcribe/synthesize audio, and create embeddings—all through one consistent interface.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strict Input Validation: v0.7.0 introduces comprehensive input validation across all entry points (e.g., Image::of(), Embeddings::for(), SimilaritySearch::usingModel()), reducing runtime errors from malformed requests. This aligns with production-grade reliability, especially for APIs or public-facing features.
  • Provider-Specific Enhancements:
    • OpenAI Strict Mode: Now opt-in via Strict attribute, allowing granular control over API response validation (e.g., enforcing choices array structure).
    • Anthropic/DeepSeek Credit Handling: New InsufficientCreditsException for OpenRouter and DeepSeek, improving error clarity for billing-related failures.
    • Bedrock Converse Support: Added providerOptions for AWS Bedrock, enabling fine-grained control over reasoning content and parameters.
  • Conversational AI Improvements:
    • Attachment Rehydration: Conversation history now preserves attachments (e.g., files, images), critical for multi-turn workflows (e.g., document analysis, chatbots).
    • Database Connection Flexibility: Conversation and ConversationMessage models now respect configured database connections, enabling multi-database setups (e.g., read replicas, sharding).
  • Testing and Documentation:
    • PHPStan Integration: Enforces type safety at development time, reducing runtime type-related bugs.
    • Expanded @throws Documentation: Clarifies exceptions for image generation, embeddings, and transcription, improving maintainability.
    • CHANGELOG Workflow: Standardized changelog updates for better release tracking.

Integration Feasibility

  • Backward Compatibility:
    • No Breaking Changes: All updates are additive (e.g., new validations, opt-in strict mode, enhanced error handling).
    • Deprecation Reverts: The revert of "Reject blank image size and quality" (PR #603) ensures no disruption to existing image-generation workflows.
  • Input Safety:
    • Blank/Invalid Input Rejection: New validations for embeddings, reranking, documents, and URLs prevent malformed API calls, reducing provider-side errors (e.g., OpenAI 400 responses).
    • Provider Options Consistency: Unified providerOptions handling across Bedrock, OpenRouter, and OpenAI-shaped providers simplifies cross-provider logic.
  • Testing Support:
    • Unit Tests for Edge Cases: Added tests for Anthropic 529 errors, strict mode, and credit failures, easing validation of custom providers.
    • GitHub Actions Pinning: Locked dependencies to specific commit SHAs, reducing CI flakiness.
  • Database Flexibility:
    • Multi-Connection Support: Configurable database connections for conversations enable scalable architectures (e.g., separating analytics from primary DB).

Technical Risk

  • Strict Mode Adoption:
    • Opt-In Design: While Strict attribute is opt-in, teams using loose OpenAI responses (e.g., legacy code) may need to audit and update calls to avoid runtime failures.
  • Input Validation Overhead:
    • Performance Impact: Blank input checks add minimal overhead but may require benchmarking for high-throughput systems (e.g., bulk embeddings).
  • Provider-Specific Quirks:
    • Bedrock Converse: New providerOptions may require testing with AWS Bedrock’s specific parameter constraints.
    • OpenRouter Image Generation: Removal of image+text restrictions could expose teams to unexpected API behavior if not validated.
  • Attachment Handling:
    • Storage Costs: Rehydrating attachments in conversations may increase database/storage usage; monitor for large-scale deployments.
  • Type Safety:
    • PHPStan Level 1: May surface previously unnoticed type issues during migration; address warnings proactively.

Key Questions

  1. Strict Mode Strategy:
    • Should we enable Strict mode globally or opt-in selectively for critical paths (e.g., payments, compliance workflows)?
  2. Input Validation Tradeoffs:
    • How will we handle edge cases where blank/empty inputs are intentionally allowed (e.g., optional fields in forms)?
  3. Provider-Specific Adoption:
    • Will we leverage Bedrock Converse or OpenRouter’s relaxed image generation? What are the quality/latency tradeoffs?
  4. Attachment Storage:
    • How will we manage attachment storage costs at scale? Should we offload to S3 or use database BLOBs?
  5. Database Connection Strategy:
    • Should we explicitly configure database connections for conversations in ai.php or rely on Laravel’s defaults?
  6. Error Handling Customization:
    • Do we need to extend InsufficientCreditsException for domain-specific billing recovery (e.g., fallback providers)?
  7. PHPStan Integration:
    • How will we incorporate PHPStan into our CI pipeline without blocking merges for type warnings?
  8. OpenRouter Image Generation:
    • What testing is needed to validate image+text removal doesn’t break existing workflows (e.g., DALL·E prompts)?

Integration Approach

Stack Fit

  • Laravel 10+: Fully compatible; no core changes required.
  • Database:
    • Multi-Connection Support: Works with MySQL, PostgreSQL, SQLite, and custom connections (e.g., Aurora, CockroachDB).
    • Attachment Storage: Compatible with Laravel Filesystem (local, S3, etc.) for offloading binary data.
  • Tooling:
    • PHPStan: Integrates with Laravel Pint, Pest, and CI pipelines.
    • Laravel Scout: Works with Gemini context caching and similarity search.
    • Horizon/Queues: Supports queued embeddings with closure provider options for async processing.
  • Providers:
    • OpenAI/AzureOpenAI: Strict mode and credit handling improvements.
    • Anthropic/Bedrock: Enhanced reasoning content and error resilience.
    • OpenRouter/DeepSeek: Credit validation and relaxed image generation.

Migration Path

  1. Assessment Phase:
    • Audit OpenAI usage for Strict mode compatibility; identify legacy loose-response calls.
    • Review conversation attachment usage (e.g., document analysis, chatbots) for storage implications.
  2. Validation Phase:
    • Enable PHPStan Level 1 in CI; address type warnings before merging.
    • Test input validations with AI::fake() for critical paths (e.g., embeddings, image generation).
  3. Core Integration:
    • Update composer.json to v0.7.0; configure ai.php for database connections and strict mode.
    • Migrate provider options to use providerOptions consistently (e.g., Bedrock, OpenRouter).
  4. Advanced Features:
    • Enable attachment rehydration for conversations; offload binaries to S3 if needed.
    • Pilot Bedrock Converse or OpenRouter image generation in a sandbox.
  5. Error Handling:
    • Implement custom exception handlers for InsufficientCreditsException (e.g., fallback providers).
    • Set up monitoring for strict mode failures (e.g., OpenAI choices validation).
  6. Optimization:
    • Benchmark input validation overhead for high-volume endpoints.
    • Fine-tune database connections for conversation models (e.g., read replicas).

Compatibility

  • Backward Compatibility: 100% additive; existing code will not break.
  • Provider Support:
    • OpenAI/AzureOpenAI: Strict mode is opt-in; no changes required for loose responses.
    • Anthropic/Bedrock: New features are additive; existing calls remain functional.
    • OpenRouter/DeepSeek: Credit handling is automatic; image generation relaxations may require prompt adjustments.
  • Database:
    • No Schema Changes: Table names remain configurable; attachments are rehydrated dynamically.
    • Connection Flexibility: Supports custom database configs in ai.php.
  • PHP Extensions: No changes beyond PHP 8.1+ and Laravel’s defaults.

Sequencing

Phase Task Dependencies
Discovery Inventory AI calls using loose OpenAI responses; audit attachment usage. Business requirements
Setup Update composer.json to v0.7.0; configure ai.php for strict mode and DB connections. Laravel app (10+)
Validation Run PHPStan; test input validations with AI::fake(). CI pipeline, test data
Pilot Enable attachment rehydration for non-critical conversations. Sandbox environment
Core Rollout Migrate provider options to providerOptions;
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope