You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/d4d04350d161eb3c8a09b528d8a9b85d1c4ca7de) Update image URL and translate README
13
+
*[05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/b9fb852bb81ac2409385b17100e5a709a9010758) Add Vision API functionality to v0.0.9 in CHANGELOG.md.
8
14
*[05/09/2024](https://github.com/lucianotonet/groq-laravel/commits/11639a559206f1d5eebd65951cec45c606f08fc4) Add Vision API functionality
9
15
*[03/09/2024](https://github.com/lucianotonet/groq-laravel/commits/9868df67da994a011c573f4cd037d8a2eafb52cd) Atualiza links de badge para HTTPS no README
10
16
*[03/09/2024](https://github.com/lucianotonet/groq-laravel/commits/6515f555cd92cd79d2c0bdfe8c002f6b4859d933) Atualiza badges no README para incluir versões instáveis
Copy file name to clipboardExpand all lines: README.md
+60-50Lines changed: 60 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,95 +32,105 @@ Need a "vanilla" PHP version? Try this out: [GroqPHP](https://github.com/luciano
32
32
33
33
3. Configure your Groq API credentials in the `.env` file:
34
34
35
-
```
35
+
```config
36
36
GROQ_API_KEY=your_api_key_here
37
-
GROQ_API_BASE=https://api.groq.com/openai/v1
38
37
```
39
38
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
46
40
47
-
5. Import the `Groq` facade into your classes:
41
+
Here is a simple example of how to create a chat completion:
48
42
49
43
```php
50
44
use LucianoTonet\GroqLaravel\Facades\Groq;
51
-
```
52
45
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
+
]);
56
52
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
+
```
65
55
66
56
## Error Handling
67
57
68
58
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:
69
59
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
+
```
81
85
82
86
## Vision API
83
87
84
88
The Groq Laravel package also provides access to the Groq Vision API, allowing you to analyze images and extract information from them.
85
89
86
90
**Example of use with image URL:**
87
91
88
-
```php
89
-
use LucianoTonet\GroqLaravel\Facades\Groq;
92
+
```php
93
+
use LucianoTonet\GroqLaravel\Facades\Groq;
90
94
91
-
// ...
95
+
// ...
92
96
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
- 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.
122
126
- The Vision API is an experimental feature and may not meet expectations, as well as not having long-term support.
123
127
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
+
124
134
## Testing
125
135
126
136
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:
0 commit comments