|
313 | 313 | expect($response->text)->toBe('Simple transcription without usage data.'); |
314 | 314 | expect($response->usage)->toBeNull(); |
315 | 315 | }); |
| 316 | + |
| 317 | + it('can transcribe with chunking_strategy option for diarization', function (): void { |
| 318 | + Http::fake([ |
| 319 | + 'api.openai.com/v1/audio/transcriptions' => Http::response([ |
| 320 | + 'text' => 'Speaker A: Hello. Speaker B: Hi there.', |
| 321 | + 'segments' => [ |
| 322 | + ['text' => 'Hello.', 'speaker' => 'A', 'start' => 0.0, 'end' => 1.0], |
| 323 | + ['text' => 'Hi there.', 'speaker' => 'B', 'start' => 1.0, 'end' => 2.0], |
| 324 | + ], |
| 325 | + ], 200), |
| 326 | + ]); |
| 327 | + |
| 328 | + $audioFile = Audio::fromBase64(base64_encode('diarized-audio-content'), 'audio/mp3'); |
| 329 | + |
| 330 | + $response = Prism::audio() |
| 331 | + ->using('openai', 'gpt-4o-transcribe-diarize') |
| 332 | + ->withInput($audioFile) |
| 333 | + ->withProviderOptions([ |
| 334 | + 'response_format' => 'diarized_json', |
| 335 | + 'chunking_strategy' => 'auto', |
| 336 | + ]) |
| 337 | + ->asText(); |
| 338 | + |
| 339 | + expect($response->text)->toBe('Speaker A: Hello. Speaker B: Hi there.'); |
| 340 | + |
| 341 | + Http::assertSent(function (Request $request): bool { |
| 342 | + $data = $request->data(); |
| 343 | + |
| 344 | + $hasChunkingStrategy = collect($data)->contains( |
| 345 | + fn ($item): bool => ($item['name'] ?? null) === 'chunking_strategy' && ($item['contents'] ?? null) === 'auto' |
| 346 | + ); |
| 347 | + |
| 348 | + $hasResponseFormat = collect($data)->contains( |
| 349 | + fn ($item): bool => ($item['name'] ?? null) === 'response_format' && ($item['contents'] ?? null) === 'diarized_json' |
| 350 | + ); |
| 351 | + |
| 352 | + return $request->url() === 'https://api.openai.com/v1/audio/transcriptions' |
| 353 | + && $hasChunkingStrategy |
| 354 | + && $hasResponseFormat; |
| 355 | + }); |
| 356 | + }); |
316 | 357 | }); |
317 | 358 |
|
318 | 359 | describe('Audio Value Object', function (): void { |
|
0 commit comments