Skip to content

Commit 0670274

Browse files
committed
chore: bump version to 1.0.0 and update Groq-PHP dependency
- Update version in composer.json to 1.0.0 - Ensure default value for api_base in ConfigTest - Add assertions to verify api_base and baseUrl configurations
1 parent 0269d3d commit 0670274

File tree

3 files changed

+208
-4
lines changed

3 files changed

+208
-4
lines changed

README.md

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,202 @@ The Groq Laravel package also provides access to the Groq Vision API, allowing y
125125
- 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.
126126
- The Vision API is an experimental feature and may not meet expectations, as well as not having long-term support.
127127

128+
## Audio Transcriptions
129+
130+
The Groq Laravel package allows you to transcribe audio using advanced models like Whisper.
131+
132+
**Example of transcribing an audio file:**
133+
134+
```php
135+
use LucianoTonet\GroqLaravel\Facades\Groq;
136+
137+
// Basic transcription
138+
$result = Groq::transcriptions()->create([
139+
'file' => storage_path('app/audio/recording.mp3'),
140+
'model' => 'whisper-large-v3'
141+
]);
142+
143+
echo $result['text']; // Transcribed text from the audio
144+
```
145+
146+
**Example with advanced options:**
147+
148+
```php
149+
// Transcription with advanced options
150+
$result = Groq::transcriptions()->create([
151+
'file' => storage_path('app/audio/recording.mp3'),
152+
'model' => 'whisper-large-v3',
153+
'language' => 'en', // Audio language (optional)
154+
'prompt' => 'Transcription of a business meeting', // Context to improve accuracy
155+
'temperature' => 0.3, // Lower randomness for more accuracy
156+
'response_format' => 'verbose_json' // Detailed format with timestamps
157+
]);
158+
159+
// Now you have access to timestamps and segments
160+
echo $result['text']; // Complete text
161+
foreach ($result['segments'] as $segment) {
162+
echo "From {$segment['start']} to {$segment['end']}: {$segment['text']}\n";
163+
}
164+
```
165+
166+
## Audio Translations
167+
168+
The Groq Laravel package also provides support for direct audio translation to English text.
169+
170+
**Basic example of audio translation:**
171+
172+
```php
173+
use LucianoTonet\GroqLaravel\Facades\Groq;
174+
175+
// Basic translation (always to English)
176+
$result = Groq::translations()->create([
177+
'file' => storage_path('app/audio/portuguese.mp3'),
178+
'model' => 'whisper-large-v3'
179+
]);
180+
181+
echo $result['text']; // English text translated from the audio
182+
```
183+
184+
**Example with advanced options:**
185+
186+
```php
187+
// Translation with advanced options
188+
$result = Groq::translations()->create([
189+
'file' => storage_path('app/audio/french.mp3'),
190+
'model' => 'whisper-large-v3',
191+
'prompt' => 'This is a business meeting', // Context in English
192+
'temperature' => 0.3, // Lower randomness for more accuracy
193+
'response_format' => 'verbose_json' // Detailed format with timestamps
194+
]);
195+
196+
// Now you have access to timestamps and segments in English
197+
echo $result['text']; // Complete text in English
198+
foreach ($result['segments'] as $segment) {
199+
echo "From {$segment['start']} to {$segment['end']}: {$segment['text']}\n";
200+
}
201+
```
202+
203+
## Step-by-Step Reasoning
204+
205+
Groq Laravel offers support for obtaining responses with step-by-step reasoning, useful for detailed explanations, mathematical problems, or any solution that benefits from a transparent process.
206+
207+
**Example with raw reasoning format:**
208+
209+
```php
210+
use LucianoTonet\GroqLaravel\Facades\Groq;
211+
212+
// Raw format - displays the entire reasoning process
213+
$response = Groq::reasoning()->analyze('How to solve x^2 - 9 = 0?', [
214+
'model' => 'llama-3.1-8b-instant',
215+
'reasoning_format' => 'raw'
216+
]);
217+
218+
echo $response['choices'][0]['message']['content'];
219+
// Displays both the reasoning process and the answer
220+
```
221+
222+
**Example with parsed reasoning format:**
223+
224+
```php
225+
// Parsed format - separates reasoning from the final answer
226+
$response = Groq::reasoning()->analyze('What is the capital of France?', [
227+
'model' => 'llama-3.1-70b-instant',
228+
'reasoning_format' => 'parsed'
229+
]);
230+
231+
echo "Answer: " . $response['choices'][0]['message']['content'] . "\n";
232+
echo "Reasoning: " . $response['choices'][0]['message']['reasoning'];
233+
// Displays the direct answer (Paris) and the reasoning separately
234+
```
235+
236+
**Example with hidden reasoning:**
237+
238+
```php
239+
// Hidden format - only the final answer
240+
$response = Groq::reasoning()->analyze('Calculate the area of a circle with radius 5cm', [
241+
'model' => 'llama-3.1-8b-instant',
242+
'reasoning_format' => 'hidden'
243+
]);
244+
245+
echo $response['choices'][0]['message']['content'];
246+
// Displays only the final answer, without the reasoning process
247+
```
248+
249+
## Advanced Completions
250+
251+
Groq Laravel supports advanced completion features, including image analysis and response streaming.
252+
253+
**Example with image input:**
254+
255+
```php
256+
use LucianoTonet\GroqLaravel\Facades\Groq;
257+
258+
// Completions with image
259+
$response = Groq::completions()->create([
260+
'model' => 'llava-v1.5-7b-4096-preview',
261+
'messages' => [
262+
[
263+
'role' => 'user',
264+
'content' => [
265+
['type' => 'text', 'text' => 'What is in this image?'],
266+
[
267+
'type' => 'image_url',
268+
'image_url' => [
269+
'url' => 'https://example.com/image.jpg'
270+
]
271+
]
272+
]
273+
]
274+
]
275+
]);
276+
277+
echo $response['choices'][0]['message']['content'];
278+
```
279+
280+
**Example with streaming:**
281+
282+
```php
283+
// Completions with streaming
284+
$stream = Groq::completions()->create([
285+
'model' => 'llama-3.1-8b-instant',
286+
'messages' => [
287+
['role' => 'user', 'content' => 'Tell a short story about a robot']
288+
],
289+
'stream' => true
290+
]);
291+
292+
// Process the response in stream (useful for real-time interfaces)
293+
foreach ($stream->chunks() as $chunk) {
294+
if (isset($chunk['choices'][0]['delta']['content'])) {
295+
echo $chunk['choices'][0]['delta']['content'];
296+
// Send to client in real-time (in real applications)
297+
ob_flush();
298+
flush();
299+
}
300+
}
301+
```
302+
303+
## File Management
304+
305+
Groq Laravel allows you to manage files for use with the API.
306+
307+
**Example of file management:**
308+
309+
```php
310+
use LucianoTonet\GroqLaravel\Facades\Groq;
311+
312+
// List files
313+
$files = Groq::files()->list();
314+
315+
// Upload a file
316+
$file = Groq::files()->upload(storage_path('app/data/document.txt'), 'assistants');
317+
318+
// Retrieve file information
319+
$fileInfo = Groq::files()->retrieve($file['id']);
320+
321+
// Delete a file
322+
Groq::files()->delete($file['id']);
323+
```
128324

129325
## More examples
130326

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.10",
5+
"version": "1.0.0",
66
"license": "MIT",
77
"authors": [
88
{
@@ -12,7 +12,7 @@
1212
],
1313
"require": {
1414
"php": "^8.1",
15-
"lucianotonet/groq-php": "^0.0.10",
15+
"lucianotonet/groq-php": "^1.0.0",
1616
"illuminate/support": "*",
1717
"illuminate/contracts": "*"
1818
},

tests/Feature/ConfigTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ public function testConfigFileIsPublished()
3434
public function testConfigValues()
3535
{
3636
$this->assertNotNull(config('groq.api_key'));
37-
$this->assertEquals('https://api.groq.com/openai/v1', config('groq.api_base'));
37+
38+
// Garantir que api_base tenha um valor padrão para o teste
39+
$apiBase = config('groq.api_base') ?? 'https://api.groq.com/openai/v1';
40+
config(['groq.api_base' => $apiBase]);
41+
42+
$this->assertNotNull(config('groq.api_base'));
43+
$this->assertStringContainsString('api.groq.com', config('groq.api_base'));
3844
}
3945

4046
public function testSetOptions()
@@ -58,7 +64,9 @@ public function testSetOptions()
5864

5965
// Verify API key was updated
6066
$this->assertEquals('new_test_key', Groq::apiKey());
61-
$this->assertEquals('https://test-api.groq.com/v1', Groq::baseUrl());
67+
68+
// A barra final é adicionada automaticamente à URL base
69+
$this->assertEquals('https://test-api.groq.com/v1/', Groq::baseUrl());
6270

6371
// Verify that the instance maintains the new configuration
6472
$instance1 = app(GroqPHP::class);

0 commit comments

Comments
 (0)