assist-feedback.php
10 months ago
assistant.php
2 months ago
base.php
1 week ago
dropped-file.php
3 months ago
edit-image.php
3 months ago
embed.php
3 months ago
feedback.php
10 months ago
function.php
1 month ago
image.php
1 month ago
parameter.php
1 year ago
text.php
1 week ago
transcribe.php
8 months ago
transcribe.php
72 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query_Transcribe extends Meow_MWAI_Query_Base { |
| 4 | public string $url = ''; |
| 5 | public ?string $path = null; |
| 6 | public ?string $audioData = null; |
| 7 | public ?string $mimeType = null; |
| 8 | |
| 9 | // Core Content |
| 10 | public ?Meow_MWAI_Query_DroppedFile $attachedFile = null; |
| 11 | |
| 12 | public function __construct( $message = '', $model = 'whisper-1' ) { |
| 13 | parent::__construct( $message ); |
| 14 | $this->set_model( $model ); |
| 15 | $this->feature = 'transcription'; |
| 16 | } |
| 17 | |
| 18 | public function set_url( $url ) { |
| 19 | $this->url = $url; |
| 20 | } |
| 21 | |
| 22 | public function set_path( $path ) { |
| 23 | $this->path = $path; |
| 24 | } |
| 25 | |
| 26 | public function set_audio_data( $data, $mimeType = null ) { |
| 27 | $this->audioData = $data; |
| 28 | $this->mimeType = $mimeType; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Add a file to the attachedFile property. |
| 33 | * This maintains compatibility with the unified file upload architecture. |
| 34 | */ |
| 35 | public function add_file( Meow_MWAI_Query_DroppedFile $file ): void { |
| 36 | $this->attachedFile = $file; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get all attached files as a normalized array. |
| 41 | * Transcribe queries only support single file attachment. |
| 42 | * |
| 43 | * @return Meow_MWAI_Query_DroppedFile[] Array of attached files |
| 44 | */ |
| 45 | public function getAttachments(): array { |
| 46 | if ( $this->attachedFile ) { |
| 47 | return [ $this->attachedFile ]; |
| 48 | } |
| 49 | return []; |
| 50 | } |
| 51 | |
| 52 | // Based on the params of the query, update the attributes |
| 53 | public function inject_params( array $params ): void { |
| 54 | parent::inject_params( $params ); |
| 55 | $params = $this->convert_keys( $params ); |
| 56 | |
| 57 | if ( !empty( $params['url'] ) ) { |
| 58 | $this->set_url( $params['url'] ); |
| 59 | } |
| 60 | if ( !empty( $params['path'] ) ) { |
| 61 | $this->set_path( $params['path'] ); |
| 62 | } |
| 63 | if ( !empty( $params['audioData'] ) || !empty( $params['audio_data'] ) ) { |
| 64 | $audioData = $params['audioData'] ?? $params['audio_data']; |
| 65 | $mimeType = $params['mimeType'] ?? $params['mime_type'] ?? null; |
| 66 | $this->set_audio_data( $audioData, $mimeType ); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | #endregion |
| 71 | } |
| 72 |