Download the PHP package aimatchfun/laravel-ai without Composer
On this page you can find all versions of the php package aimatchfun/laravel-ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-ai
Laravel AI
A Laravel package that provides a fluent interface for interacting with AI providers like Ollama, OpenAI, Anthropic, Novita, and ModelsLab.
Installation
You can install the package via composer:
The package will automatically register itself.
You can publish the configuration file with:
This will publish a config/ai.php
file where you can configure your AI providers.
Preview Messages
The package now supports preview messages to provide context for conversations. You can pass an array of messages in the format that AI models expect:
Or use the Message object for better type safety:
Configuration
After publishing the configuration file, you can configure your AI providers in the config/ai.php
file:
You can also set these values in your .env
file:
Timeout: You can set the timeout (in seconds) for each provider. If a request takes longer than this value, it will fail with a timeout error. The default is 30 seconds for all providers.
Usage
The package provides a fluent interface through the AI
facade:
About the AIResponse object
The run()
method returns an instance of AIResponse
:
answer
: The AI's response to your prompt(s).
Preview Messages
The previewMessages
method allows you to provide context for your AI conversations by passing an array of previous messages. This is useful for maintaining conversation context without persisting data to a database.
- Messages should be in the format
['role' => 'user|assistant|system', 'content' => 'message content']
- You can also use the
Message
object for better type safety and validation - Preview messages are merged with the current prompt before sending to the AI provider
Example:
Available Models
Novita Models
The package provides an enum with all available Novita models for easy access and type safety:
Note: The list of available models in the enum may become outdated as Novita adds or removes models. Always check the official Novita documentation for the most current list of available models.
Extending
You can add your own AI providers by extending the AIService
class in a service provider:
Your custom provider needs to implement the AIMatchFun\LaravelAI\Contracts\AIProvider
interface or extend the AIMatchFun\LaravelAI\Services\Providers\AbstractProvider
class.
Contributing
Contributions are welcome! If you would like to improve this package, please follow these steps:
- Fork the repository.
- Create a branch for your feature or bugfix (
git checkout -b my-feature
). - Make your changes and add tests if necessary.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to your branch (
git push origin my-feature
). - Open a Pull Request describing your changes.
Please follow the project's code style and write tests whenever possible.
License
This package is open-sourced software licensed under the MIT license.