Skip to content

Commit 60bea6c

Browse files
committed
Bump version to 0.0.10
- Update Groq-PHP dependency, - Add chat example with error handling and link to more examples available in GroqPHP repository.
1 parent bbdd64a commit 60bea6c

File tree

3 files changed

+66
-53
lines changed

3 files changed

+66
-53
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33

44
*🚧 Next Relesase*
5-
5+
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/8ca6b92e02d1d10a2fd43bdbc60be95d6aee365e) Bump version to 0.0.10
66

77
## v0.0.9
8+
* [06/09/2024](https://github.com/lucianotonet/groq-laravel/commits/bbdd64aabccd07d9772d880b7891405595b7f8b1) Update README.md
9+
* [05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/d4d04350d161eb3c8a09b528d8a9b85d1c4ca7de) Update image URL and translate README
10+
* [05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/b9fb852bb81ac2409385b17100e5a709a9010758) Add Vision API functionality to v0.0.9 in CHANGELOG.md.
811
* [05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/11639a559206f1d5eebd65951cec45c606f08fc4) Add Vision API functionality
912
* [03/09/2024](https://github.com/lucianotonet/groq-laravel/commits/9868df67da994a011c573f4cd037d8a2eafb52cd) Atualiza links de badge para HTTPS no README
1013
* [03/09/2024](https://github.com/lucianotonet/groq-laravel/commits/6515f555cd92cd79d2c0bdfe8c002f6b4859d933) Atualiza badges no README para incluir versões instáveis

README.md

Lines changed: 60 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,95 +32,105 @@ Need a "vanilla" PHP version? Try this out: [GroqPHP](https://github.com/luciano
3232

3333
3. Configure your Groq API credentials in the `.env` file:
3434

35-
```
35+
```config
3636
GROQ_API_KEY=your_api_key_here
37-
GROQ_API_BASE=https://api.groq.com/openai/v1
3837
```
3938

40-
4. (Optional) Configure caching by setting the following environment variables in the `.env` file:
41-
42-
```
43-
GROQ_CACHE_DRIVER=file
44-
GROQ_CACHE_TTL=3600
45-
```
39+
## Usage
4640

47-
5. Import the `Groq` facade into your classes:
41+
Here is a simple example of how to create a chat completion:
4842

4943
```php
5044
use LucianoTonet\GroqLaravel\Facades\Groq;
51-
```
5245

53-
## Usage
54-
55-
Here is a simple example of how to create a chat completion:
46+
$response = Groq::chat()->completions()->create([
47+
'model' => 'llama-3.1-70b-versatile', // Check available models at console.groq.com/docs/models
48+
'messages' => [
49+
['role' => 'user', 'content' => 'Hello, how are you?'],
50+
],
51+
]);
5652

57-
```php
58-
$response = Groq::chat()->completions()->create([
59-
'model' => 'llama-3.1-8b-instant',
60-
'messages' => [
61-
['role' => 'user', 'content' => 'Hello, how are you?'],
62-
],
63-
]);
64-
```
53+
$response['choices'][0]['message']['content']; // "Hey there! I'm doing great! How can I help you today?"
54+
```
6555

6656
## Error Handling
6757

6858
The Groq Laravel package makes it easy to handle errors that may occur when interacting with the Groq API. Use a `try-catch` block to capture and manage exceptions:
6959

70-
```php
71-
try {
72-
$response = Groq::chat()->completions()->create([
73-
'model' => 'llama-3.1-8b-instant',
74-
// ...
75-
]);
76-
} catch (GroqException $e) {
77-
Log::error('Error in Groq API: ' . $e->getMessage());
78-
abort(500, 'Error processing your request.');
79-
}
80-
```
60+
```php
61+
try {
62+
$response = Groq::chat()->completions()->create([
63+
'model' => 'llama-3.1-8b-instant',
64+
// ...
65+
]);
66+
} catch (GroqException $e) {
67+
Log::error('Error in Groq API: ' . $e->getMessage());
68+
abort(500, 'Error processing your request.');
69+
}
70+
```
71+
72+
Sometimes, the Groq API fails and returns an error message in the response with a failed generation detail. In this case, you can use the `GroqException` class to get the error message:
73+
74+
```php
75+
try {
76+
$response = Groq::chat()->completions()->create([
77+
'model' => 'llama-3.1-8b-instant',
78+
// ...
79+
]);
80+
} catch (GroqException $e) {
81+
$errorMessage = $e->getFailedGeneration();
82+
// ...
83+
}
84+
```
8185

8286
## Vision API
8387

8488
The Groq Laravel package also provides access to the Groq Vision API, allowing you to analyze images and extract information from them.
8589

8690
**Example of use with image URL:**
8791

88-
```php
89-
use LucianoTonet\GroqLaravel\Facades\Groq;
92+
```php
93+
use LucianoTonet\GroqLaravel\Facades\Groq;
9094

91-
// ...
95+
// ...
9296

93-
$imageUrl = 'https://example.com/image.jpg'; // Replace with your image URL
94-
$prompt = 'Describe the image';
97+
$imageUrl = 'https://example.com/image.jpg'; // Replace with your image URL
98+
$prompt = 'Describe the image';
9599

96-
$response = Groq::vision()->analyze($imageUrl, $prompt);
100+
$response = Groq::vision()->analyze($imageUrl, $prompt);
97101

98-
$imageDescription = $response['choices'][0]['message']['content'];
102+
$imageDescription = $response['choices'][0]['message']['content'];
99103

100-
// ... do something with the image description
101-
```
104+
// ... do something with the image description
105+
```
102106

103107
**Example of use with local image file:**
104108

105-
```php
106-
use LucianoTonet\GroqLaravel\Facades\Groq;
109+
```php
110+
use LucianoTonet\GroqLaravel\Facades\Groq;
107111

108-
// ...
112+
// ...
109113

110-
$imagePath = '/path/to/your/image.jpg'; // Replace with the actual path
111-
$prompt = 'What do you see in this image?';
114+
$imagePath = '/path/to/your/image.jpg'; // Replace with the actual path
115+
$prompt = 'What do you see in this image?';
112116

113-
$response = Groq::vision()->analyze($imagePath, $prompt);
117+
$response = Groq::vision()->analyze($imagePath, $prompt);
114118

115-
$imageAnalysis = $response['choices'][0]['message']['content'];
119+
$imageAnalysis = $response['choices'][0]['message']['content'];
116120

117-
// ... do something with the image analysis
118-
```
121+
// ... do something with the image analysis
122+
```
119123

120124
**Remember:**
121125
- The Vision API requires a model compatible with image analysis, such as `llava-v1.5-7b-4096-preview`. You can configure the default model for Vision in the `config/groq.php` configuration file.
122126
- The Vision API is an experimental feature and may not meet expectations, as well as not having long-term support.
123127

128+
129+
## More examples
130+
131+
As the GroqLaravel package is a wrapper for the GroqPHP package, you can check more examples in the [GroqPHP repository](https://github.com/lucianotonet/groq-php?tab=readme-ov-file#readme).
132+
133+
124134
## Testing
125135

126136
Testing is an essential part of quality software development. The Groq Laravel package includes a test suite that covers integration, unit, and configuration. To run the tests, follow the steps below:

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "lucianotonet/groq-laravel",
33
"description": "Laravel package to access Groq REST API",
44
"type": "library",
5-
"version": "0.0.9",
5+
"version": "0.0.10",
66
"license": "MIT",
77
"authors": [
88
{
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": "^8.1",
15-
"lucianotonet/groq-php": "^0.0.9",
15+
"lucianotonet/groq-php": "^0.0.10",
1616
"illuminate/support": "*",
1717
"illuminate/contracts": "*"
1818
},

0 commit comments

Comments
 (0)