Skip to content

Commit 85a3a38

Browse files
committed
Release candidate for version 1.0.0
1 parent 8567461 commit 85a3a38

File tree

14 files changed

+439
-36
lines changed

14 files changed

+439
-36
lines changed

.env.example

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,35 @@
1-
# Chave API da Groq (necessária para testes de integração)
2-
GROQ_API_KEY=
3-
GROQ_API_BASE=
4-
5-
# Configurações opcionais
6-
GROQ_MODEL=llama3-8b-8192
1+
# Groq API Configuration
2+
GROQ_API_KEY=your-api-key-here
3+
GROQ_MODEL=llama-3.1-8b-instant
4+
GROQ_API_BASE=https://api.groq.com/openai/v1
75
GROQ_TIMEOUT=30
6+
7+
# Cache Configuration
88
GROQ_CACHE_ENABLED=true
9-
GROQ_CACHE_TTL=3600
9+
GROQ_CACHE_TTL=3600
10+
GROQ_CACHE_KEY_PREFIX=groq_
11+
12+
# Model Options
13+
GROQ_MAX_TOKENS=150
14+
GROQ_TEMPERATURE=0.7
15+
GROQ_TOP_P=1.0
16+
GROQ_FREQUENCY_PENALTY=0
17+
GROQ_PRESENCE_PENALTY=0
18+
GROQ_N=1
19+
20+
# Rate Limiting
21+
GROQ_RATE_LIMIT=60
22+
23+
# Vision Configuration
24+
GROQ_VISION_MODEL=meta-llama/llama-4-scout-17b-16e-instruct
25+
GROQ_VISION_MAX_TOKENS=300
26+
27+
# Batch Processing
28+
GROQ_BATCH_COMPLETION_WINDOW=5m
29+
GROQ_BATCH_MAX_SIZE=20
30+
GROQ_BATCH_AUTO_PROCESS=true
31+
32+
# Speech Configuration
33+
GROQ_SPEECH_MODEL=playai-tts
34+
GROQ_SPEECH_VOICE=Bryan-PlayAI
35+
GROQ_SPEECH_FORMAT=wav

CHANGELOG.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,36 @@
11
# Changelog
22

3+
All notable changes to this project will be documented in this file.
34

4-
*🚧 Next Relesase*
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
57

8+
## [1.1.0] - 2025-04-12
9+
10+
### Added
11+
- Suporte completo para Text-to-Speech via método `speech()`
12+
- Suporte aprimorado para processamento em lote via método `batch()`
13+
- Novas configurações para Speech API e Batch Processing
14+
- Documentação atualizada com exemplos de uso das novas funcionalidades
15+
16+
### Changed
17+
- Atualizada dependência do groq-php para ^1.2.0
18+
- Melhorada a documentação do Facade com PHPDoc atualizado
19+
- Refatorado GroqClient para melhor gerenciamento de configurações
20+
21+
### Fixed
22+
- Corrigido o método `batch()` para usar o nome correto do método no cliente groq-php
23+
24+
## [Unreleased]
25+
26+
### Changed
27+
- Updated vision model to use `meta-llama/llama-4-scout-17b-16e-instruct`, the latest recommended model by Groq
28+
- Improved file upload test to ensure proper text/plain MIME type recognition
29+
- Fixed file upload test to use correct purpose 'batch'
30+
31+
### Notes
32+
- The new vision model `meta-llama/llama-4-scout-17b-16e-instruct` offers improved multimodal performance with support for a 128K token context window and image input up to 5 images
33+
- Current performance: 607 tokens per second (TPS) as benchmarked by Groq
634

735
## v0.0.10
836
* [29/10/2024](https://github.com/lucianotonet/groq-laravel/commits/09f1be747860f9de89d5158d6370352c96b7020a) Update setting options

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,49 @@ foreach ($result['segments'] as $segment) {
311311
}
312312
```
313313

314+
## Speech API (Text-to-Speech)
315+
316+
The Groq Laravel package also supports Text-to-Speech (TTS) to convert text into spoken audio.
317+
318+
**Basic example of Text-to-Speech:**
319+
320+
```php
321+
use LucianoTonet\GroqLaravel\Facades\Groq;
322+
use Illuminate\Support\Facades\Storage;
323+
324+
// Basic Text-to-Speech
325+
// Model, voice, and response_format will be taken from your config/groq.php by default.
326+
$speechResponse = Groq::speech()->create([
327+
'input' => 'Hello from Groq Laravel! This is a text-to-speech test.',
328+
]);
329+
330+
// Save the audio file (e.g., to storage/app/speech_output.wav)
331+
Storage::disk('local')->put('speech_output.wav', $speechResponse->body());
332+
// $speechResponse->body() contains the raw audio bytes.
333+
// You can also stream the response using $speechResponse->stream() if needed.
334+
```
335+
336+
**Example with advanced options:**
337+
338+
```php
339+
use LucianoTonet\GroqLaravel\Facades\Groq;
340+
use Illuminate\Support\Facades\Storage;
341+
342+
// Text-to-Speech with advanced options
343+
$speechResponse = Groq::speech()->create([
344+
'model' => 'playht/v2/samantha-v2-120ms-lowlatency', // Specify a different model (check Groq documentation for available TTS models)
345+
'input' => 'This is a test with a different voice, format, and speed.',
346+
'voice' => 'samantha-playht', // Specify a different voice
347+
'response_format' => 'mp3', // Supported formats: mp3, ogg_vorbis, wav, flac
348+
'speed' => 0.9 // Adjust speed (0.25 to 4.0)
349+
]);
350+
351+
// Save the audio file (e.g., to storage/app/speech_output_advanced.mp3)
352+
Storage::disk('local')->put('speech_output_advanced.mp3', $speechResponse->body());
353+
```
354+
355+
**Note:** Refer to the official Groq API documentation for the latest available TTS models, voices, and supported formats. You can set default values in your `config/groq.php` file.
356+
314357
## Step-by-Step Reasoning
315358

316359
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.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "lucianotonet/groq-laravel",
33
"description": "Laravel integration for GroqCloud",
44
"type": "library",
5-
"version": "1.0.0",
65
"license": "MIT",
76
"authors": [
87
{
@@ -12,9 +11,9 @@
1211
],
1312
"require": {
1413
"php": "^8.1",
15-
"lucianotonet/groq-php": "^1.0.0",
1614
"illuminate/support": "*",
17-
"illuminate/contracts": "*"
15+
"illuminate/contracts": "*",
16+
"lucianotonet/groq-php": "^1.2"
1817
},
1918
"require-dev": {
2019
"orchestra/testbench": "^6.0|^7.0|^8.0",

config/groq.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,35 @@
8282
'rate_limit' => env('GROQ_RATE_LIMIT', 60),
8383

8484
'vision' => [
85-
'model' => env('GROQ_VISION_MODEL', 'llava-v1.5-7b-4096-preview'),
85+
'model' => env('GROQ_VISION_MODEL', 'meta-llama/llama-4-scout-17b-16e-instruct'),
8686
'max_tokens' => env('GROQ_VISION_MAX_TOKENS', 300),
8787
],
88+
89+
/*
90+
|--------------------------------------------------------------------------
91+
| Batch Processing
92+
|--------------------------------------------------------------------------
93+
|
94+
| Configurações para processamento em lote.
95+
|
96+
*/
97+
'batch' => [
98+
'completion_window' => env('GROQ_BATCH_COMPLETION_WINDOW', '5m'),
99+
'max_batch_size' => env('GROQ_BATCH_MAX_SIZE', 20),
100+
'auto_process' => env('GROQ_BATCH_AUTO_PROCESS', true),
101+
],
102+
103+
/*
104+
|--------------------------------------------------------------------------
105+
| Speech (Text-to-Speech)
106+
|--------------------------------------------------------------------------
107+
|
108+
| Configurações para o serviço de Text-to-Speech.
109+
|
110+
*/
111+
'speech' => [
112+
'model' => env('GROQ_SPEECH_MODEL', 'playai-tts'),
113+
'voice' => env('GROQ_SPEECH_VOICE', 'Bryan-PlayAI'),
114+
'response_format' => env('GROQ_SPEECH_FORMAT', 'wav'),
115+
],
88116
];

phpunit.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@
1616
</coverage>
1717
<php>
1818
<env name="APP_ENV" value="testing"/>
19+
<env name="GROQ_API_KEY_TEST" value="gsk_test_key"/>
1920
</php>
2021
</phpunit>

src/Facades/Groq.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
* @method static \LucianoTonet\GroqPHP\Models models()
1111
* @method static \LucianoTonet\GroqPHP\Vision vision()
1212
* @method static \LucianoTonet\GroqPHP\Audio audio()
13-
* @method static \LucianoTonet\GroqPHP\Files files()
14-
* @method static \LucianoTonet\GroqPHP\Batches batches()
13+
* @method static \LucianoTonet\GroqPHP\FileManager files()
14+
* @method static \LucianoTonet\GroqPHP\BatchManager batches()
1515
* @method static void setConfig(array $options)
1616
* @method static void setOptions(array $options)
1717
* @method static \LucianoTonet\GroqPHP\Groq getClient()
18+
* @method static string apiKey()
19+
* @method static string baseUrl()
1820
*
1921
* @see \LucianoTonet\GroqLaravel\GroqClient
2022
*/
@@ -84,4 +86,15 @@ public static function files(): \LucianoTonet\GroqPHP\FileManager
8486
{
8587
return app(GroqPHP::class)->files();
8688
}
89+
90+
/**
91+
* Get batch instance for processing multiple requests.
92+
*
93+
* @return \LucianoTonet\GroqPHP\BatchManager An instance of the BatchManager class.
94+
* @throws GroqException
95+
*/
96+
public static function batch(): \LucianoTonet\GroqPHP\BatchManager
97+
{
98+
return app(GroqPHP::class)->batches();
99+
}
87100
}

src/GroqClient.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,26 @@ public function batches()
127127
return $this->client->batches();
128128
}
129129

130+
/**
131+
* Get speech instance
132+
*
133+
* @return \LucianoTonet\GroqPHP\Speech
134+
*/
135+
public function speech()
136+
{
137+
return $this->client->speech();
138+
}
139+
140+
/**
141+
* Get batch instance
142+
*
143+
* @return \LucianoTonet\GroqPHP\BatchManager
144+
*/
145+
public function batch()
146+
{
147+
return $this->client->batches();
148+
}
149+
130150
/**
131151
* Set configuration options
132152
*

tests/Feature/BatchTest.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace LucianoTonet\GroqLaravel\Tests\Feature;
4+
5+
use LucianoTonet\GroqLaravel\Facades\Groq;
6+
use LucianoTonet\GroqLaravel\Tests\TestCase;
7+
8+
class BatchTest extends TestCase
9+
{
10+
protected $tempFile;
11+
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
16+
// Create temporary batch file with .jsonl extension
17+
$tempDir = sys_get_temp_dir();
18+
$this->tempFile = $tempDir . '/groq_batch_' . uniqid() . '.jsonl';
19+
20+
// Create valid JSONL content with required fields
21+
$content = [
22+
[
23+
'model' => 'llama-3.1-8b-instant',
24+
'messages' => [
25+
['role' => 'user', 'content' => 'Hello!']
26+
]
27+
],
28+
[
29+
'model' => 'llama-3.1-8b-instant',
30+
'messages' => [
31+
['role' => 'user', 'content' => 'How are you?']
32+
]
33+
]
34+
];
35+
36+
// Write each line as JSON
37+
$jsonlContent = '';
38+
foreach ($content as $item) {
39+
$jsonlContent .= json_encode($item) . "\n";
40+
}
41+
42+
file_put_contents($this->tempFile, $jsonlContent);
43+
}
44+
45+
protected function tearDown(): void
46+
{
47+
if (file_exists($this->tempFile)) {
48+
unlink($this->tempFile);
49+
}
50+
parent::tearDown();
51+
}
52+
53+
/** @test */
54+
public function it_can_create_batch_instance()
55+
{
56+
$batch = Groq::batch();
57+
$this->assertInstanceOf(\LucianoTonet\GroqPHP\BatchManager::class, $batch);
58+
}
59+
60+
/** @test */
61+
public function it_can_create_batch_with_config()
62+
{
63+
config([
64+
'groq.batch.completion_window' => '5m',
65+
'groq.batch.max_batch_size' => 20,
66+
'groq.batch.auto_process' => true,
67+
]);
68+
69+
$batch = Groq::batch();
70+
$this->assertInstanceOf(\LucianoTonet\GroqPHP\BatchManager::class, $batch);
71+
}
72+
73+
/** @test */
74+
public function it_can_create_batch_with_file()
75+
{
76+
// Upload the file first
77+
$file = Groq::files()->upload($this->tempFile, 'batch');
78+
$this->assertNotEmpty($file->id);
79+
80+
try {
81+
// Create batch with file
82+
$batch = Groq::batch()->create([
83+
'input_file_id' => $file->id,
84+
'endpoint' => '/v1/chat/completions',
85+
'completion_window' => '24h'
86+
]);
87+
88+
$this->assertInstanceOf(\LucianoTonet\GroqPHP\BatchManager::class, $batch);
89+
} finally {
90+
// Cleanup
91+
Groq::files()->delete($file->id);
92+
}
93+
}
94+
}

0 commit comments

Comments
 (0)