Laravel

Laravel stats

Downloads
0
Stars
8
Open Issues
0
Forks
0

View on GitHub →

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.

๐Ÿง  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.


๐Ÿ“– Table of Contents


โœจ 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:

composer require grok-php/laravel

After installation, run the setup command:

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:

GROK_API_KEY=your-api-key

๐Ÿš€ Quick Start

Basic Usage

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:

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:

$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:

$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:

composer test
or
vendor/bin/phpunit

๐Ÿ”’ Security

If you discover a security vulnerability, please report it via email: ๐Ÿ“ฉ thefeqy@gmail.com

๐Ÿค Contributing

Want to improve this package? Check out CONTRIBUTE.md for contribution guidelines.

๐Ÿ“„ License

This package is open-source software licensed under the MIT License.

grok-php photo

Bringing Grok AI to PHP with seamless, modern, and high-performance integrations.

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Grok Php Laravel Related Articles

Integrate Grok AI in Laravel image

Integrate Grok AI in Laravel

Read article
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Blastup logo

Blastup

Blastup provides social media enhancement services including buying Instagram likes, followers, and views, with features like instant delivery and a variety of packages to suit different needs.

Blastup
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
Typesense Search logo

Typesense Search

Typesense is an open source, blazing-fast search engine, optimized for helping you build delightful search experiences for your sites and apps. Natively integrated with Laravel Scout.

Typesense Search