Download the PHP package endritvs/laravel-ai-toolkit without Composer
On this page you can find all versions of the php package endritvs/laravel-ai-toolkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-ai-toolkit
Laravel AI Toolkit 🧠
Laravel AI Toolkit is a powerful package designed to seamlessly integrate AI models, such as OpenAI's GPT and AWS's Claude, into your Laravel application. With an easy-to-use interface, this toolkit empowers developers to effortlessly add AI-driven features to their projects.
🚀 Features
- Simple integration with OpenAI and AWS Claude.
- Configurable AI providers.
- Customizable query builder for AI models.
- Exception handling and error reporting.
- Support for multiple AI models and providers, with fallback capabilities.
📋 Requirements
- PHP 8.1 or higher
- Laravel 10.x to 11.x
openai-php/laravel
packageaws/aws-sdk-php
package
🛠️ Installation
To install the package, use Composer:
After installing the package, publish the configuration file:
This will create a configuration file at config/ai.php
.
⚙️ Configuration
Environment Variables
Ensure that you set up the following environment variables in your .env
file:
Configuration File
The config/ai.php
configuration file contains default settings for the package. You can customize these settings as needed:
💻 Usage
Basic Usage Example
You can use the package to interact with AI models as follows:
Explanation:
- addContent('What is the capital of France?'): Sets the question content for the AI model to process.
- setModel('gpt-4o-mini'): Specifies the AI model to be used.
- setMaxTokens(50): Limits the response to a maximum of 50 tokens.
- execute(): Sends the request to the AI model and retrieves the response.
Query Builder Example
The query builder allows you to build queries for AI models:
Explanation:
- Prompt::query(): Creates a new query using the AIQueryBuilder class.
- setModel('anthropic.claude-v2'): Sets the AI model to be used.
- setMaxTokens(100): Limits the response to a maximum of 100 tokens.
- addContent('Tell me a joke'): Adds content to the request.
- execute(): Executes the query and retrieves the result.
Using Different Models Example
You can use different AI models for different tasks:
Explanation:
-
Using GPT model:
- addContent('Explain quantum computing in simple terms.'): Sets the content for GPT to explain.
- setModel('gpt-4o-mini'): Specifies the GPT model to use.
- setMaxTokens(150): Limits the response to 150 tokens.
- execute(): Gets the response from GPT.
- Using Claude model:
- addContent('What are the latest trends in web development?'): Sets the content for Claude to process.
- setModel('anthropic.claude-v2'): Specifies the Claude model.
- setMaxTokens(150): Limits the response to 150 tokens.
- execute(): Gets the response from Claude.
Using Fallback Providers Example
Specify a fallback provider to use if the primary provider fails:
Explanation:
- addContent('Summarize the latest news on AI technology.'): Sets the content for the request.
- setProvider('gpt'): Sets the primary provider to GPT.
- setModel('gpt-4o-mini'): Specifies the GPT model.
- setMaxTokens(150): Limits the response to 150 tokens.
- fallback('claude'): Configures Claude as the fallback provider if GPT fails.
- execute(): Executes the request, using the fallback provider if necessary.
Set Provider Example
Manually set a different provider for the AI model:
Explanation:
- setProvider('claude'): Manually sets the AI provider to Claude.
- addContent('Describe the principles of machine learning.'): Sets the content to be processed.
- setModel('claude-v2'): Specifies the Claude model.
- setMaxTokens(150): Limits the response to 150 tokens.
- execute(): Sends the request to the specified provider and retrieves the response.
Advanced Query Builder Example
Dynamically build and execute more complex queries:
Explanation:
- setModel('gpt-4o-mini'): Sets the AI model to be used.
- addContent('What are the implications of quantum computing?'): Adds additional content to the request.
- setMaxTokens(200): Limits the response to 200 tokens.
- execute(): Executes the query and processes the response.
Complete Example (Everything Included)
Combines all features into a comprehensive example, demonstrating both GPT and Claude models:
Explanation:
GPT-4 Example:
- addContent('Give a summary of the latest advancements in technology.'): Sets the content for GPT-4.
- setModel('gpt-4'): Specifies GPT-4 as the primary model.
- setMaxTokens(300): Limits the response to 300 tokens.
- fallback('claude'): Uses Claude as the fallback provider if GPT-4 fails.
- execute(): Executes the request, retrieving the response from GPT-4 or Claude.
Claude Example:
- addContent('Discuss the impact of recent technological innovations on society.'): Sets the content for Claude.
- setModel('claude-v2'): Specifies Claude as the model.
- setMaxTokens(300): Limits the response to 300 tokens.
- execute(): Executes the request and retrieves the response from Claude.
Query Builder Example:
- Prompt::query(): Creates a new query builder instance.
- setModel('gpt-4o-mini'): Specifies GPT-4o-mini as the model for the query.
- addContent('What is the future of artificial intelligence?'): Adds additional content to the query.
- setMaxTokens(150): Limits the response to 150 tokens.
- execute(): Executes the query and retrieves the result based on the specified parameters.
🛠️ Contributing
Contributions are welcome! If you'd like to contribute to this package, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to the branch (
git push origin feature/new-feature
). - Open a pull request.
🛡️ Security Vulnerabilities
If you discover a security vulnerability within this package, please send an email to [[email protected]]. All security vulnerabilities will be promptly addressed.
📄 License
This package is licensed under the MIT License. See the LICENSE file for more information.
💡 Tips & Tricks
- Use environment-specific configuration to tweak AI model behavior depending on your deployment environment.
- Monitor the usage and response times of your AI models to optimize performance.
- Experiment with different AI models to find the one that best suits your application's needs.
📬 Support
If you have any questions or need further assistance, feel free to reach out via email or open an issue on GitHub.
All versions of laravel-ai-toolkit with dependencies
illuminate/support Version ^10.0|^11.0
openai-php/laravel Version ^0.7.0
aws/aws-sdk-php Version ^3.304