forked from openai-php/client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
10 changed files
with
145 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OpenAI\Responses\Audio; | ||
|
||
use OpenAI\Contracts\ResponseContract; | ||
use OpenAI\Responses\Concerns\ArrayAccessible; | ||
|
||
/** | ||
* @implements ResponseContract<array{word: string, start: float, end: float}> | ||
*/ | ||
final class TranscriptionResponseWord implements ResponseContract | ||
{ | ||
/** | ||
* @use ArrayAccessible<array{word: string, start: float, end: float}> | ||
*/ | ||
use ArrayAccessible; | ||
|
||
private function __construct( | ||
public readonly string $word, | ||
public readonly float $start, | ||
public readonly float $end, | ||
) { | ||
} | ||
|
||
/** | ||
* Acts as static factory, and returns a new Response instance. | ||
* | ||
* @param array{word: string, start: float, end: float} $attributes | ||
*/ | ||
public static function from(array $attributes): self | ||
{ | ||
return new self( | ||
$attributes['word'], | ||
$attributes['start'], | ||
$attributes['end'], | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'word' => $this->word, | ||
'start' => $this->start, | ||
'end' => $this->end, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
use OpenAI\Responses\Audio\TranscriptionResponseWord; | ||
|
||
test('from', function () { | ||
$result = TranscriptionResponseWord::from(audioTranscriptionVerboseJson()['words'][0]); | ||
|
||
expect($result) | ||
->toBeInstanceOf(TranscriptionResponseWord::class) | ||
->word->toBe('Hello') | ||
->start->toBe(0.31999999284744) | ||
->end->toBe(0.9200000166893); | ||
}); | ||
|
||
test('to array', function () { | ||
$result = TranscriptionResponseWord::from(audioTranscriptionVerboseJson()['words'][0]); | ||
|
||
expect($result->toArray()) | ||
->toBe(audioTranscriptionVerboseJson()['words'][0]); | ||
}); |