22
33![ Grok PHP Client] ( assets/images/grok-client.png )
44
5- ** A lightweight, framework-agnostic PHP client for interacting with Grok AI APIs.**
5+ ** A lightweight, framework-agnostic PHP client for interacting with Grok AI APIs.**
66Supports ** PHP 8.2+** , built with ** OOP best practices** , and ** fully type-safe** .
77
88[ ![ Latest Version] ( https://img.shields.io/packagist/v/grok-php/client )] ( https://packagist.org/packages/grok-php/client )
@@ -22,6 +22,7 @@ Supports **PHP 8.2+**, built with **OOP best practices**, and **fully type-safe*
2222 - [ Advanced Configuration] ( #advanced-configuration )
2323- [ Available Grok AI Models] ( #available-grok-ai-models )
2424- [ Streaming Responses] ( #streaming-responses )
25+ - [ Response format] ( #response-format )
2526- [ Error Handling] ( #error-handling )
2627- [ Testing] ( #testing )
2728- [ Security] ( #security )
@@ -34,10 +35,10 @@ Supports **PHP 8.2+**, built with **OOP best practices**, and **fully type-safe*
3435
3536![ Grok PHP Client Demo] ( assets/images/demo.gif )
3637
37- - ** Easy Integration** – Seamlessly connects with Grok AI APIs.
38- - ** Modern PHP Features** – Utilizes PHP 8.2+ features like enums and traits.
39- - ** Framework Agnostic** – Works with any PHP project, CLI scripts, or web applications.
40- - ** Streaming Support** – Built-in support for real-time responses.
38+ - ** Easy Integration** – Seamlessly connects with Grok AI APIs.
39+ - ** Modern PHP Features** – Utilizes PHP 8.2+ features like enums and traits.
40+ - ** Framework Agnostic** – Works with any PHP project, CLI scripts, or web applications.
41+ - ** Streaming Support** – Built-in support for real-time responses.
4142- ** Lightweight & Efficient** – Optimized with PSR-4 autoloading and minimal dependencies.
4243
4344---
@@ -139,7 +140,7 @@ $messages = [
139140// Custom API settings
140141$options = new ChatOptions(
141142 model: Model::GROK_2_LATEST,
142- temperature: 1.2,
143+ temperature: 1.2,
143144 stream: false
144145);
145146
@@ -151,8 +152,8 @@ echo "AI Says: " . $response['choices'][0]['message']['content'];
151152
152153## ** Available Grok AI Models**
153154
154- Grok AI offers multiple models optimized for different use cases.
155- These models are available in the ` Model ` enum inside our package:
155+ Grok AI offers multiple models optimized for different use cases.
156+ These models are available in the ` Model ` enum inside our package:
156157📄 ` src/Enums/Model.php `
157158
158159| Model Enum | API Model Name | Description |
@@ -172,7 +173,7 @@ These models are available in the `Model` enum inside our package:
172173
173174## ** Streaming Responses**
174175
175- The Grok API supports streaming responses for real-time interaction.
176+ The Grok API supports streaming responses for real-time interaction.
176177Enable it by setting ` stream: true ` :
177178
178179``` php
@@ -183,9 +184,20 @@ Streaming can be useful for chatbots, real-time applications, and CLI assistants
183184
184185---
185186
187+ ## ** Response format**
188+
189+ The Grok API supports setting a response format, also refered to structured outputs, for the ` grok-2-1212 ` model.
190+
191+ ``` php
192+ $options = new ChatOptions(model: Model::GROK_2_1212, temperature: 0.7, stream: false, responseFormat: ['type' => 'json_object']);
193+ $response = $client->chat($messages, $options);
194+ ```
195+
196+ ---
197+
186198## ** Error Handling**
187199
188- This package includes built-in error handling with a dedicated exception class.
200+ This package includes built-in error handling with a dedicated exception class.
189201Common errors and their messages:
190202
191203| Error Type | HTTP Code | Message |
@@ -221,7 +233,7 @@ vendor/bin/phpunit
221233
222234## ** Security**
223235
224- If you discover a security vulnerability, please report it via email:
236+ If you discover a security vulnerability, please report it via email:
225237📩 [ thefeqy@gmail.com ] ( mailto:thefeqy@gmail.com )
226238
227239---
0 commit comments