Download the PHP package ai-agent/ai-agent without Composer
On this page you can find all versions of the php package ai-agent/ai-agent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package ai-agent
AI Agent Provider
A Laravel package for integrating with various AI providers including OpenAI, Anthropic and Google's Gemini.
Features
- 🤖 Simple, unified API for different AI providers
- 🔄 Support for text generation, chat completions, and embeddings
- 📊 Built-in logging of AI interactions
- 🚦 Rate limiting for API requests
- 🔌 Easy to extend with new AI providers
- 🔧 Blade directives for simple template integration
- 🚀 HTTP API endpoints for integration with frontend frameworks
- 🧠 Memory caching with configurable TTL
- 📝 Comprehensive logging for auditing and debugging
Table of Contents
- AI Agent Provider
- Features
- Table of Contents
- Installation
- Configuration
- Basic Usage
- Text Generation
- Chat Completions
- Embeddings
- Blade Directives
- Advanced Usage
- Custom Options
- Error Handling
- Logging
- Rate Limiting
- Caching Responses
- HTTP API Endpoints
- Get all providers
- Generate text
- Chat completion
- Generate embeddings
- Extending with Custom Providers
- Artisan Commands
- Troubleshooting
- Common Issues
- Debugging
- API Reference
- AiAgent Facade
- AiLoggerService
- Testing
- License
- Issues
- Author
Installation
You can install the package via composer:
Publish the configuration file:
Publish migrations (optional):
Run migrations to create the AI interactions table:
Configuration
Configure your AI providers in the config/ai-agent.php file:
Basic Usage
Text Generation
Chat Completions
Embeddings
Blade Directives
The package provides several Blade directives for easy template integration:
The directives now include a loading indicator that shows while the AI is processing your request, providing better UX for users.
Advanced Usage
Custom Options
Each AI provider supports different options that can be passed to customize the request:
Error Handling
Handle potential errors when working with AI providers:
Logging
Enable or disable logging at runtime:
Rate Limiting
The package includes built-in rate limiting to prevent excessive API usage. You can configure this in the config/ai-agent.php file:
Caching Responses
Cache AI responses to reduce API costs and improve performance:
HTTP API Endpoints
The package provides API endpoints for integration with frontend frameworks:
Get all providers
Response:
Generate text
Request:
Response:
Chat completion
Request:
Generate embeddings
Request:
Extending with Custom Providers
You can create your own adapters to integrate additional AI providers:
-
Create a new adapter class that extends the BaseAdapter:
-
Register your custom adapter in the config file:
- Use your custom provider:
Artisan Commands
The package provides helpful Artisan commands:
Troubleshooting
Common Issues
-
API Key Not Found
Make sure you've set the appropriate API keys in your
.envfile: -
Rate Limiting Errors
If you're hitting rate limits, consider:
- Increasing the rate limit in the configuration
- Implementing better caching strategies
- Optimizing your prompt to reduce token usage
-
Provider Not Found Error
Ensure the provider is correctly configured in
config/ai-agent.phpand that theenabledflag is set totrue.
Debugging
Enable more detailed logging to troubleshoot issues:
API Reference
The package provides the following core API:
AiAgent Facade
AiAgent::provider(string $name): Get a specific AI providerAiAgent::generate(string $prompt, array $options = [], string $provider = null): Generate textAiAgent::chat(array $messages, array $options = [], string $provider = null): Get chat completionAiAgent::embeddings(string|array $input, array $options = [], string $provider = null): Generate embeddingsAiAgent::getProviderNames(): Get all available provider names
AiLoggerService
log(string $provider, string $type, $input, $output, array $options = [], int $tokensUsed = 0, float $duration = 0, bool $success = true, string $error = null, ?int $userId = null): Log an AI interactionisEnabled(): Check if logging is enabledsetEnabled(bool $enabled): Enable or disable logging
Testing
License
This package is open-sourced software licensed under the MIT license.
Issues
If you encounter any issues or have suggestions, please submit them through our GitHub Issues page.
Author
Created by Arseno25
All versions of ai-agent with dependencies
guzzlehttp/guzzle Version ^7.5
illuminate/support Version ^8.0|^9.0|^10.0|^12.0
illuminate/console Version ^8.0|^9.0|^10.0|^12.0
illuminate/contracts Version ^8.0|^9.0|^10.0|^12.0