openai-php / client

⚡️ OpenAI PHP is a supercharged community-maintained PHP API client that allows you to interact with OpenAI API.
MIT License
4.6k stars 468 forks source link

$client->audio()->transcribe Exception: transient parameter is NULL #215

Closed cyrilbele closed 9 months ago

cyrilbele commented 9 months ago

With the test.mp3.zip uncompressed file in attachment (github doesn t support mp3), when I call the audio transcribe with the following parameters:

$response = $client->audio()->transcribe([
      'model' => 'whisper-1',
      'file' => fopen($filePath, 'r'),
      'response_format' => 'verbose_json',
      'language' => 'fr',
    ]);

I get an exception:

/vendor/openai-php/client/src/Responses/Audio/TranscriptionResponseSegment.php:23
OpenAI\Responses\Audio\TranscriptionResponseSegment::__construct(): Argument #11 ($transient) must be of type bool, null given, called in /vendor/openai-php/client/src/Responses/Audio/TranscriptionResponseSegment.php on line 45
#0 /vendor/openai-php/client/src/Responses/Audio/TranscriptionResponseSegment.php(45): OpenAI\Responses\Audio\TranscriptionResponseSegment->__construct(0, 0, 0.0, 3.0, ' pour finir par...', Array, 0.0, -0.27817614006274, 1.6928104575163, 0.59283715486526, NULL

And this is what the openAI response looks like for the first segment, no transient parameter returned:

Array
(
    [task] => transcribe
    [language] => french
    [duration] => 119.3
    [text] => pour finir par le faire de manière propre. Alors, il faut bien voir, là...
    [segments] => Array
        (
            [0] => Array
                (
                    [id] => 0
                    [seek] => 0
                    [start] => 0
                    [end] => 3
                    [text] =>  pour finir par le faire de manière propre.
                    [tokens] => Array
                        (
                            [0] => 50364
                            [1] => 2016
                            [2] => 962
                            [3] => 347
                            [4] => 971
                            [5] => 476
                            [6] => 4865
                            [7] => 368
                            [8] => 587
                            [9] => 72
                            [10] => 127
                            [11] => 101
                            [12] => 265
                            [13] => 35221
                            [14] => 13
                            [15] => 50514
                        )

                    [temperature] => 0
                    [avg_logprob] => -0.27817614006274
                    [compression_ratio] => 1.6928104575163
                    [no_speech_prob] => 0.59283715486526
                )
cyrilbele commented 9 months ago

It could be fixed by changing line 34 of client/src/Responses/Audio/TranscriptionResponseSegment.php line 34

public readonly bool|null $transient

gehrisandro commented 9 months ago

Hi @cyrilbele

Are you using the latest version? (0.7.3) Because in this version this should already been fixed.

cyrilbele commented 9 months ago

You are right, I checked the code on my version and I don t have the line $attributes['transient'] ?? false, just $attributes['transient']

Probably some composer issue when I installed.

Sorry for not checking that