Skip to content

Commit 179514d

Browse files
committed
Initial Commit
0 parents  commit 179514d

File tree

6 files changed

+378
-0
lines changed

6 files changed

+378
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
vendor
2+
.env
3+
.env.example
4+
composer.lock
5+
phpstan.neon
6+
phpunit.xml

CONTRIBUTE.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# 🛠 Contributing to Grok AI Laravel
2+
3+
First off, thanks for taking the time to contribute! 🎉
4+
This guide outlines how you can help improve **Grok AI Laravel** and collaborate effectively.
5+
6+
---
7+
8+
## 📖 Table of Contents
9+
- [🚀 Getting Started](#-getting-started)
10+
- [🐛 Reporting Bugs](#-reporting-bugs)
11+
- [✨ Feature Requests](#-feature-requests)
12+
- [🛠 Development Workflow](#-development-workflow)
13+
- [🧪 Running Tests](#-running-tests)
14+
- [🙌 Acknowledgements](#-acknowledgements)
15+
16+
---
17+
18+
## 🚀 Getting Started
19+
20+
### 1️⃣ Fork the Repository
21+
Click the **"Fork"** button at the top right of this repository to create your copy.
22+
23+
### 2️⃣ Clone Your Fork
24+
```sh
25+
git clone https://github.com/your-username/laravel-grok.git
26+
cd laravel-grok
27+
```
28+
29+
### 3️⃣ Install Dependencies
30+
31+
```sh
32+
composer install
33+
```
34+
35+
### 4️⃣ Link Your Local Package
36+
If you're testing this package inside a Laravel project, you may use:
37+
38+
```sh
39+
composer remove grok-php/laravel
40+
composer require grok-php/laravel:@dev --prefer-source
41+
```
42+
43+
---
44+
45+
## 🐛 Reporting Bugs
46+
Found a bug? Please [open an issue](https://github.com/grok-php/laravel/issues) and include:
47+
48+
- A clear description of the bug.
49+
- Steps to reproduce the issue.
50+
- The expected vs. actual behavior.
51+
- Any error messages or logs.
52+
- Your Laravel and PHP version.
53+
54+
---
55+
56+
## ✨ Feature Requests
57+
Have an idea? We'd love to hear it!
58+
Submit a [feature request](https://github.com/grok-php/laravel/issues) with:
59+
60+
- A detailed explanation of your proposed feature.
61+
- The problem it solves.
62+
- Example use cases.
63+
64+
---
65+
66+
## 🛠 Development Workflow
67+
68+
1- Create a new branch for your feature or fix:
69+
70+
```sh
71+
git checkout -b feature/your-new-feature
72+
```
73+
74+
2- Make Your Changes & Add Tests
75+
- Follow PSR-12 coding standards.
76+
- Use typed properties, enums, and traits.
77+
- Document your functions with PHPDoc.
78+
- Always write unit tests for new features.
79+
80+
3- Run tests before committing:
81+
82+
```sh
83+
composer test
84+
```
85+
4- Commit Your Changes
86+
87+
```sh
88+
git add .
89+
git commit -m "✨ Added new feature X"
90+
```
91+
92+
7- Push to Your Fork
93+
94+
```sh
95+
git push origin feature/your-new-feature
96+
```
97+
98+
6- Open a Pull Request (PR)
99+
- Go to [Grok PHP Client Repo](https://github.com/grok-php/laravel/pulls)
100+
- Click "New Pull Request", select your branch, and submit 🚀
101+
102+
---
103+
104+
## 🧪 Running Tests
105+
We use PHPUnit for testing. Before submitting your PR, run:
106+
107+
```sh
108+
composer test
109+
or
110+
vendor/bin/phpunit
111+
```
112+
113+
## 🙌 Acknowledgements
114+
A huge thank you to everyone contributing! ❤️ Your efforts help improve this package for the entire Laravel community.
115+
116+
🚀 Happy coding!

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MIT License
2+
3+
Copyright (c) 2024 **Grok PHP**
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# 🧠 Grok AI Laravel
2+
3+
![Grok AI Laravel](assets/images/grok-laravel.png)
4+
5+
**Seamlessly integrate Grok AI into Laravel applications with an elegant, developer-friendly package.**
6+
Leverage **powerful AI models** for **chat, automation, and NLP**, while maintaining Laravel's expressive simplicity.
7+
8+
[![Latest Version](https://img.shields.io/packagist/v/grok-php/laravel)](https://packagist.org/packages/grok-php/laravel)
9+
[![PHP Version](https://img.shields.io/badge/PHP-8.1%2B-blue)](https://php.net)
10+
[![Laravel Version](https://img.shields.io/badge/Laravel-10%2B-red)](https://laravel.com)
11+
[![License](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE.md)
12+
13+
---
14+
15+
## 📖 Table of Contents
16+
- [✨ Features](#-features)
17+
- [📦 Installation](#-installation)
18+
- [🚀 Quick Start](#-quick-start)
19+
- [Basic Usage](#basic-usage)
20+
- [Advanced Configuration](#advanced-configuration)
21+
- [📌 Available Grok AI Models](#-available-grok-ai-models)
22+
- [⚡ Streaming Responses](#-streaming-responses)
23+
- [🧪 Testing](#-testing)
24+
- [🔒 Security](#-security)
25+
- [🤝 Contributing](#-contributing)
26+
- [📄 License](#-license)
27+
28+
---
29+
30+
## ✨ Features
31+
32+
**Seamless Laravel Integration** – Works effortlessly with Laravel 10+
33+
**Simple API Client** – Access Grok AI models with a fluent, clean syntax
34+
**Supports All Grok AI Models** – Choose from multiple **LLM & vision models**
35+
**Streaming Capable** – Enable **real-time AI responses** for interactive experiences
36+
**Configurable Defaults** – Set your preferred model, temperature, and more
37+
38+
---
39+
40+
## 📦 Installation
41+
42+
Install via **Composer**:
43+
```sh
44+
composer require grok-php/laravel
45+
```
46+
47+
After installation, run the setup command:
48+
49+
```sh
50+
php artisan grok:install
51+
```
52+
This command will:
53+
54+
- Publish the configuration file (`config/grok.php`).
55+
- Add necessary environment variables to `.env` and `.env.example`.
56+
57+
Add your API key in `.env`:
58+
```sh
59+
GROK_API_KEY=your-api-key
60+
```
61+
62+
---
63+
64+
65+
## 🚀 Quick Start
66+
67+
### Basic Usage
68+
69+
```php
70+
use GrokPHP\Laravel\Facades\GrokAI;
71+
use GrokPHP\Client\Config\ChatOptions;
72+
use GrokPHP\Client\Enums\Model;
73+
74+
$response = GrokAI::chat(
75+
[['role' => 'user', 'content' => 'Hello Grok!']],
76+
new ChatOptions(model: Model::GROK_2)
77+
);
78+
79+
echo $response['choices'][0]['message']['content'];
80+
```
81+
82+
### 📌 Defaults Used:
83+
Model: grok-2
84+
Temperature: 0.7
85+
Streaming: false
86+
87+
### Advanced Configuration
88+
Modify your `config/grok.php` file:
89+
90+
```php
91+
return [
92+
'api_key' => env('GROK_API_KEY'),
93+
'base_uri' => env('GROK_BASE_URI', 'https://api.grok.com/v1'),
94+
'default_model' => env('GROK_DEFAULT_MODEL', 'grok-2'),
95+
'default_temperature' => env('GROK_DEFAULT_TEMPERATURE', 0.7),
96+
'enable_streaming' => env('GROK_ENABLE_STREAMING', false),
97+
'timeout' => env('GROK_API_TIMEOUT', 30),
98+
];
99+
```
100+
101+
📌 You can override any setting dynamically:
102+
103+
```php
104+
$response = GrokAI::chat(
105+
[['role' => 'user', 'content' => 'Explain black holes']],
106+
new ChatOptions(model: Model::GROK_2_LATEST, temperature: 1.2, stream: true)
107+
);
108+
```
109+
---
110+
111+
112+
113+
114+
## 📌 Available Grok AI Models
115+
Grok AI offers multiple models, each optimized for different use cases.
116+
These models are available in the Model enum inside our package:
117+
📄 `src/Enums/Model.php`
118+
119+
| Model Enum | API Model Name | Description |
120+
|-----------------------------|----------------------|-----------------------------------------------------|
121+
| `Model::GROK_VISION_BETA` | grok-vision-beta | Experimental vision-enabled model |
122+
| `Model::GROK_2_VISION` | grok-2-vision | Advanced multi-modal vision model |
123+
| `Model::GROK_2_VISION_LATEST` | grok-2-vision-latest | Latest iteration of Grok vision models |
124+
| `Model::GROK_2_VISION_1212` | grok-2-vision-1212 | Enhanced vision model with performance improvements |
125+
| `Model::GROK_2_1212` | grok-2-1212 | Optimized chat model |
126+
| `Model::GROK_2` | grok-2 | Default general-purpose Grok model |
127+
| `Model::GROK_2_LATEST` | grok-2-latest | Latest iteration of Grok-2 |
128+
| `Model::GROK_BETA` | grok-beta | Experimental beta model |
129+
130+
#### 📌 Default model used: `Model::GROK_2`
131+
---
132+
133+
134+
## ⚡ Streaming Responses
135+
Enable real-time AI responses by setting `stream: true`:
136+
137+
```php
138+
$response = GrokAI::chat(
139+
[['role' => 'user', 'content' => 'Tell me a story']],
140+
new ChatOptions(model: Model::GROK_2, stream: true)
141+
);
142+
```
143+
Streaming is useful for chatbots, assistants, and real-time applications.
144+
---
145+
146+
## 🧪 Testing
147+
Run tests using Pest PHP:
148+
149+
```sh
150+
composer test
151+
or
152+
vendor/bin/phpunit
153+
```
154+
155+
## 🔒 Security
156+
If you discover a security vulnerability, please report it via email:
157+
📩 [thefeqy@gmail.com](mailto:thefeqy@gmail.com)
158+
159+
## 🤝 Contributing
160+
161+
Want to improve this package? Check out [CONTRIBUTE.md](CONTRIBUTE.md) for contribution guidelines.
162+
163+
## 📄 License
164+
165+
This package is open-source software licensed under the [MIT License](LICENSE).

assets/images/grok-laravel.png

434 KB
Loading

composer.json

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
{
2+
"name": "grok-php/laravel",
3+
"description": "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.",
4+
"type": "library",
5+
"license": "MIT",
6+
"version": "1.0.0",
7+
"homepage": "https://github.com/grok-php/laravel",
8+
"support": {
9+
"issues": "https://github.com/grok-php/laravel/issues",
10+
"source": "https://github.com/grok-php/laravel"
11+
},
12+
"authors": [
13+
{
14+
"name": "Grok PHP",
15+
"email": "thefeqy@gmail.com",
16+
"role": "organization"
17+
},
18+
{
19+
"name": "Muhammed Elfeqy",
20+
"email": "thefeqy@gmail.com",
21+
"homepage": "https://github.com/thefeqy",
22+
"role": "creator"
23+
}
24+
],
25+
"keywords": [
26+
"Grok AI",
27+
"AI API",
28+
"PHP AI SDK",
29+
"Generative AI",
30+
"Machine Learning",
31+
"Natural Language Processing",
32+
"Large Language Model",
33+
"NLP",
34+
"AI Integration",
35+
"AI Client",
36+
"AI SDK",
37+
"REST API",
38+
"AI Text Generation",
39+
"Deep Learning",
40+
"Artificial Intelligence",
41+
"API Wrapper",
42+
"Text Processing",
43+
"AI-powered Applications",
44+
"AI Chatbot",
45+
"Language Model",
46+
"AI Research",
47+
"AI Developer Tools"
48+
],
49+
"require": {
50+
"php": ">=8.1",
51+
"laravel/framework": "^10.0|^11.0",
52+
"grok-php/client": "^1.0"
53+
},
54+
"autoload": {
55+
"psr-4": {
56+
"GrokPHP\\Laravel\\": "src/",
57+
"Tests\\": "tests/"
58+
}
59+
},
60+
"extra": {
61+
"laravel": {
62+
"providers": [
63+
"GrokPHP\\Laravel\\Providers\\GrokServiceProvider"
64+
],
65+
"aliases": {
66+
"GrokAI": "GrokPHP\\Laravel\\Facades\\GrokAI"
67+
}
68+
}
69+
},
70+
"require-dev": {
71+
"orchestra/testbench": "^8.0",
72+
"phpunit/phpunit": "^10.0",
73+
"mockery/mockery": "^1.6.12",
74+
"phpstan/phpstan": "^1.12"
75+
},
76+
"minimum-stability": "stable",
77+
"prefer-stable": true,
78+
"scripts": {
79+
"test": "vendor/bin/phpunit",
80+
"test:types": "phpstan analyse src --ansi"
81+
}
82+
}

0 commit comments

Comments
 (0)