Skip to content

Commit 90e768e

Browse files
committed
doc: Update README.md
1 parent f362eee commit 90e768e

File tree

1 file changed

+92
-74
lines changed

1 file changed

+92
-74
lines changed

README.md

Lines changed: 92 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,47 @@
1-
# 🧠 Grok AI Laravel
1+
### **Grok AI Laravel**
22

3-
![Grok AI Laravel](assets/images/grok-laravel.png)
3+
**Effortlessly integrate Grok AI into Laravel applications with a clean, developer-friendly package.**
4+
Leverage **powerful AI models** for **chat, automation, vision, and natural language processing (NLP)** while maintaining Laravel's expressive simplicity.
45

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)
6+
[![Latest Version](https://img.shields.io/packagist/v/grok-php/laravel)](https://packagist.org/packages/grok-php/laravel)
7+
[![PHP Version](https://img.shields.io/badge/PHP-8.2%2B-blue)](https://php.net)
8+
[![Laravel Version](https://img.shields.io/badge/Laravel-10%2B-red)](https://laravel.com)
9+
[![License](https://img.shields.io/badge/license-MIT-brightgreen)](LICENSE)
10+
[![Tests](https://github.com/grok-php/laravel/actions/workflows/run-tests.yml/badge.svg)](https://github.com/grok-php/laravel/actions)
1211

1312
---
1413

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)
14+
## Table of Contents
15+
16+
- [Features](#features)
17+
- [Installation](#installation)
18+
- [Quick Start](#quick-start)
19+
- [Chat API](#chat-api)
20+
- [Vision Analysis](#vision-analysis-image-recognition)
21+
- [Error Handling](#error-handling)
22+
- [Available Grok AI Models](#available-grok-ai-models)
23+
- [Streaming Responses](#streaming-responses)
24+
- [Testing](#testing)
25+
- [Security](#security)
26+
- [Contributing](#contributing)
27+
- [License](#license)
2728

2829
---
2930

30-
## Features
31+
## Features
3132

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
33+
- **Seamless Laravel Integration** – Works with Laravel 10, 11, and 12
34+
- **Simple API Client** – Access Grok AI models with a clean and intuitive API
35+
- **Supports Chat & Vision**Send both text and image-based requests
36+
- **Streaming Capable** – Enable real-time AI responses
37+
- **Configurable Defaults** – Set model, temperature, and timeout via config
3738

3839
---
3940

40-
## 📦 Installation
41+
## Installation
42+
43+
Install via Composer:
4144

42-
Install via **Composer**:
4345
```sh
4446
composer require grok-php/laravel
4547
```
@@ -49,22 +51,23 @@ After installation, run the setup command:
4951
```sh
5052
php artisan grok:install
5153
```
54+
5255
This command will:
5356

5457
- Publish the configuration file (`config/grok.php`).
55-
- Add necessary environment variables to `.env` and `.env.example`.
58+
- Add necessary environment variables to `.env`.
5659

5760
Add your API key in `.env`:
61+
5862
```sh
5963
GROK_API_KEY=your-api-key
6064
```
6165

6266
---
6367

68+
## Quick Start
6469

65-
## 🚀 Quick Start
66-
67-
### Basic Usage
70+
### Chat API
6871

6972
```php
7073
use GrokPHP\Laravel\Facades\GrokAI;
@@ -76,45 +79,40 @@ $response = GrokAI::chat(
7679
new ChatOptions(model: Model::GROK_2)
7780
);
7881

79-
echo $response['choices'][0]['message']['content'];
82+
echo $response->content();
8083
```
8184

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:
85+
### Vision Analysis (Image Recognition)
8986

9087
```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-
];
88+
$response = GrokAI::vision()->analyze(
89+
'https://example.com/sample.jpg',
90+
'Describe this image'
91+
);
92+
93+
echo $response->content();
9994
```
10095

101-
📌 You can override any setting dynamically:
96+
### Error Handling
97+
98+
All errors are wrapped in the `GrokException` class:
10299

103100
```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-
);
101+
use GrokPHP\Client\Exceptions\GrokException;
102+
103+
try {
104+
$response = GrokAI::chat(
105+
[['role' => 'user', 'content' => 'Hello!']]
106+
);
107+
echo $response->content();
108+
} catch (GrokException $e) {
109+
echo "Error: " . $e->getMessage();
110+
}
108111
```
109-
---
110-
111-
112112

113+
---
113114

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`
115+
## Available Grok AI Models
118116

119117
| Model Enum | API Model Name | Description |
120118
|-----------------------------|----------------------|-----------------------------------------------------|
@@ -127,11 +125,12 @@ These models are available in the Model enum inside our package:
127125
| `Model::GROK_2_LATEST` | grok-2-latest | Latest iteration of Grok-2 |
128126
| `Model::GROK_BETA` | grok-beta | Experimental beta model |
129127

130-
#### 📌 Default model used: `Model::GROK_2`
128+
Default model used: `Model::GROK_2`
129+
131130
---
132131

132+
## Streaming Responses
133133

134-
## ⚡ Streaming Responses
135134
Enable real-time AI responses by setting `stream: true`:
136135

137136
```php
@@ -141,26 +140,45 @@ $response = GrokAI::chat(
141140
);
142141
```
143142

144-
> Streaming is useful for chatbots, assistants, and real-time applications.
143+
Streaming is useful for chatbots, assistants, and real-time applications.
144+
145145
---
146146

147-
## 🧪 Testing
148-
Run tests using Pest PHP:
147+
## Testing
148+
149+
To run PHPUnit tests, copy the `phpunit.xml.dist` file to `phpunit.xml` and set your API key.
150+
151+
```sh
152+
cp phpunit.xml.dist phpunit.xml
153+
```
154+
155+
```xml
156+
<php>
157+
<env name="GROK_API_KEY" value="your-grok-api-key"/>
158+
</php>
159+
```
160+
161+
Now, run the tests:
149162

150163
```sh
151164
composer test
152-
or
153-
vendor/bin/phpunit
154165
```
155166

156-
## 🔒 Security
157-
If you discover a security vulnerability, please report it via email:
158-
📩 [thefeqy@gmail.com](mailto:thefeqy@gmail.com)
167+
---
168+
169+
## Security
159170

160-
## 🤝 Contributing
171+
If you discover a security vulnerability, please report it via email:
172+
[thefeqy@gmail.com](mailto:thefeqy@gmail.com)
173+
174+
---
161175

162-
Want to improve this package? Check out [CONTRIBUTING.md](CONTRIBUTING.md) for contribution guidelines.
176+
## Contributing
177+
178+
Check out [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute.
179+
180+
---
163181

164-
## 📄 License
182+
## License
165183

166184
This package is open-source software licensed under the [MIT License](LICENSE).

0 commit comments

Comments
 (0)