openai-php / client

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

[Audio::transcribe] Add support for timestamp_granularities #335

Closed jplhomer closed 2 months ago

jplhomer commented 4 months ago

What:

Description:

This PR adds support for the new timestamp_granularities[] property in Audio Transcriptions.

Currently, attempting to pass in a granularity level array results in an error:

$response = OpenAI::audio()->transcribe([
  'model' => 'whisper-1',
  'file' => $file
  'response_format' => 'verbose_json',
  'timestamp_granularities' => ['word'],
]);

Exception:

First argument to "Http\Message\MultipartStream\MultipartStreamBuilder::createStream()" must be a string, resource or StreamInterface.

My solution is to parse one level of array data. I'm not sure if this is the best solution, or if we ought to support recursive array parsing.

solomonjames commented 2 months ago

This looks great overall, and worked for me once I made that small tweak to your code. Thank you for pushing this up, I hope we can get it merged into the main project, as I have it forked just to use this feature.

gehrisandro commented 2 months ago

Resolve here https://github.com/openai-php/client/pull/374

Thanks @jplhomer for your work!