Download the PHP package avocet-shores/laravel-conduit without Composer
On this page you can find all versions of the php package avocet-shores/laravel-conduit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download avocet-shores/laravel-conduit
More information about avocet-shores/laravel-conduit
Files in avocet-shores/laravel-conduit
Package laravel-conduit
Short Description Laravel Conduit offers a clean, unified API for working with multiple AI providers.
License MIT
Homepage https://github.com/avocet-shores/laravel-conduit
Informations about the package laravel-conduit
Laravel Conduit
Why Conduit?
Most AI packages today are tightly coupled with a single AI provider, locking you into their ecosystem (and their outages). Conduit offers a flexible, provider-agnostic solution that allows you to switch between providers without changing your code. You can even create custom drivers for your own AI services, all while maintaining a consistent API. Want to add OpenAI as a backup to your on-prem model in case of an outage? Just add a fallback:
Key Features
- Unified API for various AI providers (Supports OpenAI and Amazon Bedrock out of the box, with more on the way)
- Automatic fallback to secondary drivers and/or models for improved reliability
- Easy extensibility: implement a simple interface to add custom drivers
- Pipeline-based middleware support
- Structured output and automatic JSON decoding
Installation
-
You can install the package via composer:
- Optionally publish the configuration file:
Basic Usage
Below is a typical usage example with the Conduit facade:
- Call the Conduit facade with
make('driver', 'model')
. - Provide optional instructions and messages.
- Optionally enable jsonOutput to automatically decode the response.
- Call
run()
to obtain aConversationResponse
.
Setting a Fallback
To ensure your application remains online if your primary provider fails, you can set a fallback driver and model:
When a server or rate limit error occurs, Conduit will automatically switch to the specified fallback provider and model, keeping your AI-driven features running.
Configuration
Conduit's configuration file allows you to set up your provider-specific authentication variables.
OpenAI
To use OpenAI, you must provide your API key in the .env
file:
Amazon Bedrock
To use Amazon Bedrock, you'll need to provide your AWS credentials in the .env
file. By default, Conduit
references the same .env
variables as the AWS SDK and other AWS services, but you can always point them to your own
custom variables by updating the config/conduit.php
file.
Advanced Usage
Structured Outputs
Currently only supported by some of OpenAI's models.
Read more about structured outputs in OpenAI's documentation.
Certain drivers and models support specifying a complete schema that the model is then forced to adhere to. If your
chosen driver/model supports it, you can enable structured output by passing a Schema
into enableStructuredOutput()
:
Conduit ensures that the schema request is formatted exactly how OpenAI expects, so your simple Schema definition:
...is automatically converted into the JSON format OpenAI requires:
What if my model doesn't support structured outputs?
You can still enjoy automatic json decoding by adding withJsonOutput()
and defining your own schema
somewhere within your prompt. It's important to note, however, that this will not enforce the schema on the AI
model. You will need to validate the response yourself in a subsequent step:
Middleware and Pipelines
Conduit uses Laravel’s Pipelines to provide you with a powerful extension system via middleware. You can add
middleware by providing either a class that implements MiddlewareInterface
or a closure:
This can be useful for inspecting or modifying the AI request/response on its way through the pipeline. Or, for example, adding your own logging:
The AIRequestContext
Object
The AIRequestContext
object is passed through the pipeline to the designated driver, and contains all the data
required for Conduit to handle the request. This includes the model, instructions, messages, responseFormat, and more.
It also includes a blank slate metadata
array for any additional data you wish to pass through the pipeline. You can access
and modify this data as needed via its getter and setter methods.
If you're planning on creating your own driver, you'll need to familiarize yourself with the AIRequestContext
object, as it's how you'll receive the data you need to make the AI request. Speaking of which...
Adding Your Own Driver
Laravel Conduit is fully extensible to new or custom drivers. You only need to implement the
DriverInterface
and provide:
- A
run()
method to handle the AI request context. - A return value of type
ConversationResponse
, ensuring a normalized data shape across drivers.
Finally, add your driver to the drivers
array in the configuration file.
Example:
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- Jared Cannon
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-conduit with dependencies
aws/aws-sdk-php Version ^3.337
illuminate/contracts Version ^10.0||^11.0
spatie/laravel-package-tools Version ^1.16