Skip to content

Conversation

chr-hertel
Copy link
Member

Q A
Bug fix? yes
New feature? no
Docs? no
Issues
License MIT

Cherry picking php-llm/llm-chain#350

This PR addresses the inconsistency between OpenAI and Azure Whisper
implementations by introducing a configurable `task` option that
controls which endpoint is used.

Previously, the Whisper implementations were inconsistent:
- **OpenAI bridge**: Hardcoded to use `/audio/transcriptions` endpoint
- **Azure bridge**: Hardcoded to use `/audio/translations` endpoint

This made it impossible to use both transcription and translation
features consistently across platforms.

Introduced a `task` option that allows users to specify whether they
want transcription or translation:

```php
use PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\Task;

// Default behavior (transcription)
$client->request($model, $payload);

// Explicit transcription
$client->request($model, $payload, ['task' => Task::TRANSCRIPTION]);

// Translation
$client->request($model, $payload, ['task' => Task::TRANSLATION]);
```

1. **New Task Interface**: Created
`PhpLlm\LlmChain\Platform\Bridge\OpenAI\Whisper\Task` with constants:
   - `TRANSCRIPTION = 'transcription'`
   - `TRANSLATION = 'translation'`

2. **Enhanced OpenAI ModelClient**:
   - Extracts `task` from options
   - Dynamically constructs endpoint URL based on task
   - Maintains backward compatibility (defaults to transcription)

3. **Enhanced Azure WhisperModelClient**:
   - Extracts `task` from options
   - Dynamically constructs endpoint URL based on task
   - **Breaking Change**: Now defaults to transcription for consistency

4. **Comprehensive Tests**: Added test coverage for both implementations
covering all scenarios

⚠️ **Azure Whisper behavior change**: Previously, Azure Whisper always
used the `/translations` endpoint. Now it defaults to `/transcriptions`
for consistency with OpenAI.

**Migration**: If you were relying on Azure Whisper's translation
behavior, explicitly specify the task:
```php
$options = ['task' => Task::TRANSLATION];
$response = $azureClient->request($model, $payload, $options);
```

- **OpenAI**: Fully backward compatible (still defaults to
transcription)
- **Azure**: Breaking change documented above, but provides path forward

Both implementations now behave consistently and support both
transcription and translation endpoints.

Fixes #349.

> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> -
`https://api.github.com/repos/CodeWithKyrian/chromadb-php/zipball/53bb269c6e76ae9976b0750eed3731d1fdcb9ea5`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/CodeWithKyrian/jinja-php/zipball/3a246c831af5c3c3c532399aa0c1e5209441675f`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/CodeWithKyrian/transformers-libsloader/zipball/7052adad23e969701a961437b77422f820df05ba`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/CodeWithKyrian/transformers-php/zipball/474406c25d33e36fcc4f6225719a46afa82acbf8`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/OskarStark/enum-helper/zipball/adccc8c099db61cb26497a1e1987fc95ebda02a9`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/PHP-CS-Fixer/shim/zipball/eea219a577085bd13ff0cb644a422c20798316c7`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/async-aws/bedrock-runtime/zipball/518cd3baa6df494fb0fb029c1149921c1af3fe80`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/async-aws/core/zipball/58ab79116d990e7053b2e31162f47df4223148c5`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/doctrine/dbal/zipball/b37d160498ea91a2382a2ebe825c4ea6254fc0ec`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/doctrine/deprecations/zipball/459c2f5dd3d6a4633d3b5f46ee2b1c40f57d3f38`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/lryxyr
/usr/bin/composer install --no-dev --ignore-platform-req=ext-mongodb `
(http block)
> -
`https://api.github.com/repos/dompdf/php-font-lib/zipball/a1681e9793040740a405ac5b189275059e2a9863`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/guzzle/guzzle/zipball/7b2f29fe81dc4da0ca0ea7d42107a0845946ea77`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/guzzle/promises/zipball/7c69f28996b0a6920945dd20b3857e499d9ca96c`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/guzzle/psr7/zipball/c2270caaabe631b3b44c85f99e5a04bbb8060d16`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/interop-phpobjects/polite-math/zipball/621246cdc108b1388307097e06361ca5b9259467`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/libvips/php-vips/zipball/a54c1cceea581b592a199edd61a7c06f44a24c08`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/mongodb/mongo-php-library/zipball/3bbe7ba9578724c7e1f47fcd17c881c0995baaad`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/cache/zipball/aa5030cfa5405eccfdcb1083ce040c2cb8d253bf`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/Kcp9Lc
/usr/bin/composer update --prefer-stable
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/http-client/zipball/bb5906edc1c324c9a05aa0873d40117941e5fa90`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/http-message/zipball/402d35bcb92c70c026d1a6a9883f06b2ead23d71`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-fig/log/zipball/f16e1d5863e37f8d8c2a01719f5b34baa2b714d3`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/Kcp9Lc
/usr/bin/composer update --prefer-stable
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/php-imagine/Imagine/zipball/80ab21434890dee9ba54969d31c51ac8d4d551e0`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/phpstan/phpdoc-parser/zipball/9b30d6fd026b2c132b3985ce6b23bec09ab3aa68`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/lryxyr
/usr/bin/composer install --no-dev --ignore-platform-req=ext-mongodb `
(http block)
> -
`https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/rindow/rindow-math-matrix/zipball/6d6622b4495d6325e4065430d143d6f4c3b5f0c4`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/rindow/rindow-matlib-ffi/zipball/b5eddacc8a0fbc640cfdb90d6a40414ba6c76529`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/rindow/rindow-openblas-ffi/zipball/efcddb9b24ac9d2d2f3a7d1092fbd5f66dccbb5e`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/rokka-io/imagine-vips/zipball/6c86dc4a988fbd51081973abd29cbc38989e2e94`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/console/zipball/66c1440edf6f339fd82ed6c7caa76cb006211b44`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/http-client-contracts/zipball/75d7043853a42837e68111812f4d964b01e5101c`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/Kcp9Lc
/usr/bin/composer update --prefer-stable
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/http-client/zipball/57e4fb86314015a695a750ace358d07a7e37b8a9`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/Kcp9Lc
/usr/bin/composer update --prefer-stable
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/polyfill-ctype/zipball/a3cc8b044a6ea513310cbd48ef7333b384945638`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/lryxyr
/usr/bin/composer install --no-dev --ignore-platform-req=ext-mongodb `
(http block)
> -
`https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/b9123926e3b7bc2f98c02ad54f6a4b02b91a8abe`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/polyfill-php85/zipball/6fedf31ce4e3648f4ff5ca58bfd53127d38f05fd`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/service-contracts/zipball/f021b05a130d35510bd6b25fe9053c2a8a15d5d4`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/Kcp9Lc
/usr/bin/composer update --prefer-stable
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
> -
`https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991`
> - Triggering command: `/usr/bin/php8.3 -n -c /tmp/kJITtg
/usr/bin/composer install --no-interaction
--ignore-platform-req=ext-mongodb ` (http block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to my [firewall allow
list](https://gh.io/copilot/firewall-config)
>
> </details>

<!-- START COPILOT CODING AGENT TIPS -->
---

💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: chr-hertel <2852185+chr-hertel@users.noreply.github.com>
@chr-hertel chr-hertel requested a review from Nyholm as a code owner June 30, 2025 22:22
@chr-hertel chr-hertel added Bug Something isn't working Platform Issues & PRs about the AI Platform component labels Jun 30, 2025
@OskarStark OskarStark changed the title fix: consistent Whisper task option for OpenAI and Azure bridges (#350) fix: consistent Whisper task option for OpenAI and Azure bridges Jul 1, 2025
@OskarStark
Copy link
Contributor

Thank you @chr-hertel.

@OskarStark OskarStark merged commit e239ecc into main Jul 1, 2025
24 checks passed
@OskarStark OskarStark deleted the cherry-whisper-task branch July 1, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Platform Issues & PRs about the AI Platform component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants