This commit is contained in:
Timothy Jaeryang Baek
2026-06-01 13:10:19 -07:00
parent d64ef1803d
commit eb4eebc3ce
2 changed files with 37 additions and 8 deletions
+33 -3
View File
@@ -687,9 +687,18 @@ async def verify_connection(
if auth_type not in ('azure_ad', 'microsoft_entra_id'): if auth_type not in ('azure_ad', 'microsoft_entra_id'):
headers['api-key'] = key headers['api-key'] = key
api_version = api_config.get('api_version', '') or '2023-03-15-preview' # Azure v1 format: base URL already ends with /openai/v1,
# use standard /models endpoint without api-version.
is_azure_v1 = bool(re.search(r'/openai/v1(?:/|$)', url))
if is_azure_v1:
verify_url = f'{url.rstrip("/")}/models'
else:
api_version = api_config.get('api_version', '') or '2023-03-15-preview'
verify_url = f'{url}/openai/models?api-version={api_version}'
async with session.get( async with session.get(
url=f'{url}/openai/models?api-version={api_version}', url=verify_url,
headers=headers, headers=headers,
cookies=cookies, cookies=cookies,
ssl=AIOHTTP_CLIENT_SESSION_SSL, ssl=AIOHTTP_CLIENT_SESSION_SSL,
@@ -1305,11 +1314,32 @@ async def embeddings(request: Request, form_data: dict, user):
streaming = False streaming = False
headers, cookies = await get_headers_and_cookies(request, url, key, api_config, user=user) headers, cookies = await get_headers_and_cookies(request, url, key, api_config, user=user)
if api_config.get('azure') or api_config.get('provider') == 'azure':
# Only set api-key header if not using Azure Entra ID authentication
auth_type = api_config.get('auth_type', 'bearer')
if auth_type not in ('azure_ad', 'microsoft_entra_id'):
headers['api-key'] = key
# Azure v1 format: base URL already ends with /openai/v1,
# model stays in the payload, no deployment URL rewriting.
is_azure_v1 = bool(re.search(r'/openai/v1(?:/|$)', url))
if is_azure_v1:
embeddings_url = f'{url.rstrip("/")}/embeddings'
else:
api_version = api_config.get('api_version', '2023-03-15-preview')
model = _sanitize_model_for_url(form_data.get('model', ''))
embeddings_url = f'{url}/openai/deployments/{model}/embeddings?api-version={api_version}'
headers['api-version'] = api_version
else:
embeddings_url = f'{url}/embeddings'
try: try:
session = await get_session() session = await get_session()
r = await session.request( r = await session.request(
method='POST', method='POST',
url=f'{url}/embeddings', url=embeddings_url,
data=body, data=body,
headers=headers, headers=headers,
cookies=cookies, cookies=cookies,
+4 -5
View File
@@ -41,7 +41,8 @@
provider === 'azure' || provider === 'azure' ||
((url.includes('azure.') || url.includes('cognitive.microsoft.com')) && ((url.includes('azure.') || url.includes('cognitive.microsoft.com')) &&
!direct && !direct &&
provider === ''); provider === '' &&
!/\/openai\/v1(\/|$)/.test(url));
let prefixId = ''; let prefixId = '';
let enable = true; let enable = true;
@@ -392,9 +393,7 @@
<option value="session">{$i18n.t('Session')}</option> <option value="session">{$i18n.t('Session')}</option>
{#if !direct} {#if !direct}
<option value="system_oauth">{$i18n.t('OAuth')}</option> <option value="system_oauth">{$i18n.t('OAuth')}</option>
{#if azure} <option value="microsoft_entra_id">{$i18n.t('Entra ID')}</option>
<option value="microsoft_entra_id">{$i18n.t('Entra ID')}</option>
{/if}
{/if} {/if}
{/if} {/if}
</select> </select>
@@ -523,7 +522,7 @@
<label <label
for="api-version-input" for="api-version-input"
class={`mb-0.5 text-xs text-gray-500 class={`mb-0.5 text-xs text-gray-500
${($settings?.highContrastMode ?? false) ? 'text-gray-800 dark:text-gray-100' : ''}`} ${($settings?.highContrastMode ?? false) ? 'text-gray-800 dark:text-gray-100' : ''}`}
>{$i18n.t('API Version')}</label >{$i18n.t('API Version')}</label
> >