https://github.com/grok-php/laravel
Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package. Leverage powerful AI models for chat, automation, and NLP, while maintaining Laravel's expressive simplicity.
https://github.com/grok-php/laravel
ai-api ai-assistant ai-powered-applications ai-sdk chatbot laravel laravel-ai machine-learning php-ai-sdk rest-api x-ai x-ai-grok x-ai-grok-2
Last synced: 2 months ago
JSON representation
Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package. Leverage powerful AI models for chat, automation, and NLP, while maintaining Laravel's expressive simplicity.
- Host: GitHub
- URL: https://github.com/grok-php/laravel
- Owner: grok-php
- License: mit
- Created: 2025-02-07T02:02:18.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-02-07T02:14:22.000Z (3 months ago)
- Last Synced: 2025-02-07T03:16:34.228Z (3 months ago)
- Topics: ai-api, ai-assistant, ai-powered-applications, ai-sdk, chatbot, laravel, laravel-ai, machine-learning, php-ai-sdk, rest-api, x-ai, x-ai-grok, x-ai-grok-2
- Language: PHP
- Homepage:
- Size: 434 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ง Grok AI Laravel

**Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package.**
Leverage **powerful AI models** for **chat, automation, and NLP**, while maintaining Laravel's expressive simplicity.[](https://packagist.org/packages/grok-php/laravel)
[](https://php.net)
[](https://laravel.com)
[](LICENSE.md)---
## ๐ Table of Contents
- [โจ Features](#-features)
- [๐ฆ Installation](#-installation)
- [๐ Quick Start](#-quick-start)
- [Basic Usage](#basic-usage)
- [Advanced Configuration](#advanced-configuration)
- [๐ Available Grok AI Models](#-available-grok-ai-models)
- [โก Streaming Responses](#-streaming-responses)
- [๐งช Testing](#-testing)
- [๐ Security](#-security)
- [๐ค Contributing](#-contributing)
- [๐ License](#-license)---
## โจ Features
โ **Seamless Laravel Integration** โ Works effortlessly with Laravel 10+
โ **Simple API Client** โ Access Grok AI models with a fluent, clean syntax
โ **Supports All Grok AI Models** โ Choose from multiple **LLM & vision models**
โ **Streaming Capable** โ Enable **real-time AI responses** for interactive experiences
โ **Configurable Defaults** โ Set your preferred model, temperature, and more---
## ๐ฆ Installation
Install via **Composer**:
```sh
composer require grok-php/laravel
```After installation, run the setup command:
```sh
php artisan grok:install
```
This command will:- Publish the configuration file (`config/grok.php`).
- Add necessary environment variables to `.env` and `.env.example`.Add your API key in `.env`:
```sh
GROK_API_KEY=your-api-key
```---
## ๐ Quick Start
### Basic Usage
```php
use GrokPHP\Laravel\Facades\GrokAI;
use GrokPHP\Client\Config\ChatOptions;
use GrokPHP\Client\Enums\Model;$response = GrokAI::chat(
[['role' => 'user', 'content' => 'Hello Grok!']],
new ChatOptions(model: Model::GROK_2)
);echo $response['choices'][0]['message']['content'];
```### ๐ Defaults Used:
Model: grok-2
Temperature: 0.7
Streaming: false### Advanced Configuration
Modify your `config/grok.php` file:```php
return [
'api_key' => env('GROK_API_KEY'),
'base_uri' => env('GROK_BASE_URI', 'https://api.grok.com/v1'),
'default_model' => env('GROK_DEFAULT_MODEL', 'grok-2'),
'default_temperature' => env('GROK_DEFAULT_TEMPERATURE', 0.7),
'enable_streaming' => env('GROK_ENABLE_STREAMING', false),
'timeout' => env('GROK_API_TIMEOUT', 30),
];
```๐ You can override any setting dynamically:
```php
$response = GrokAI::chat(
[['role' => 'user', 'content' => 'Explain black holes']],
new ChatOptions(model: Model::GROK_2_LATEST, temperature: 1.2, stream: true)
);
```
---## ๐ Available Grok AI Models
Grok AI offers multiple models, each optimized for different use cases.
These models are available in the Model enum inside our package:
๐ `src/Enums/Model.php`| Model Enum | API Model Name | Description |
|-----------------------------|----------------------|-----------------------------------------------------|
| `Model::GROK_VISION_BETA` | grok-vision-beta | Experimental vision-enabled model |
| `Model::GROK_2_VISION` | grok-2-vision | Advanced multi-modal vision model |
| `Model::GROK_2_VISION_LATEST` | grok-2-vision-latest | Latest iteration of Grok vision models |
| `Model::GROK_2_VISION_1212` | grok-2-vision-1212 | Enhanced vision model with performance improvements |
| `Model::GROK_2_1212` | grok-2-1212 | Optimized chat model |
| `Model::GROK_2` | grok-2 | Default general-purpose Grok model |
| `Model::GROK_2_LATEST` | grok-2-latest | Latest iteration of Grok-2 |
| `Model::GROK_BETA` | grok-beta | Experimental beta model |#### ๐ Default model used: `Model::GROK_2`
---## โก Streaming Responses
Enable real-time AI responses by setting `stream: true`:```php
$response = GrokAI::chat(
[['role' => 'user', 'content' => 'Tell me a story']],
new ChatOptions(model: Model::GROK_2, stream: true)
);
```
Streaming is useful for chatbots, assistants, and real-time applications.
---## ๐งช Testing
Run tests using Pest PHP:```sh
composer test
or
vendor/bin/phpunit
```## ๐ Security
If you discover a security vulnerability, please report it via email:
๐ฉ [[email protected]](mailto:[email protected])## ๐ค Contributing
Want to improve this package? Check out [CONTRIBUTE.md](CONTRIBUTE.md) for contribution guidelines.
## ๐ License
This package is open-source software licensed under the [MIT License](LICENSE).