Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/handlers/handlerUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,7 @@ export function constructConfigFromRequestHeaders(
requestHeaders[`x-${POWERED_BY}-azure-entra-client-secret`],
azureEntraTenantId: requestHeaders[`x-${POWERED_BY}-azure-entra-tenant-id`],
azureModelName: requestHeaders[`x-${POWERED_BY}-azure-model-name`],
chatCompletionsApi: requestHeaders[`x-${POWERED_BY}-chat-completions-api`],
openaiBeta:
requestHeaders[`x-${POWERED_BY}-openai-beta`] ||
requestHeaders[`openai-beta`],
Expand Down
18 changes: 17 additions & 1 deletion src/providers/azure-openai/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import {
getAzureWorkloadIdentityToken,
} from './utils';
import { getRuntimeKey } from 'hono/adapter';
import {
getAzureResponsesChatEndpoint,
shouldUseAzureResponsesForChat,
} from './chatCompletionsResponses';

const runtime = getRuntimeKey();

Expand Down Expand Up @@ -100,7 +104,12 @@ const AzureOpenAIAPIConfig: ProviderAPIConfig = {
}
return headersObj;
},
getEndpoint: ({ providerOptions, fn, gatewayRequestURL }) => {
getEndpoint: ({
providerOptions,
fn,
gatewayRequestBodyJSON,
gatewayRequestURL,
}) => {
const { apiVersion, urlToFetch, deploymentId } = providerOptions;
let mappedFn = fn;

Expand Down Expand Up @@ -140,6 +149,13 @@ const AzureOpenAIAPIConfig: ProviderAPIConfig = {
searchParams.delete('api-version');
}

if (
mappedFn === 'chatComplete' &&
shouldUseAzureResponsesForChat(gatewayRequestBodyJSON, providerOptions)
) {
return getAzureResponsesChatEndpoint();
}

switch (mappedFn) {
case 'complete': {
return `${prefix}/completions?${searchParams.toString()}`;
Expand Down
10 changes: 10 additions & 0 deletions src/providers/azure-openai/chatComplete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
ErrorResponse,
ProviderConfig,
} from '../types';
import {
hasFunctionTools,
isAzureResponsesChatCompatibilityEnabled,
} from './chatCompletionsResponses';
import { getAzureModelValue } from './utils';

// TODOS: this configuration does not enforce the maximum token limit for the input parameter. If you want to enforce this, you might need to add a custom validation function or a max property to the ParameterConfig interface, and then use it in the input configuration. However, this might be complex because the token count is not a simple length check, but depends on the specific tokenization method used by the model.
Expand Down Expand Up @@ -102,6 +106,12 @@ export const AzureOpenAIChatCompleteConfig: ProviderConfig = {
},
reasoning_effort: {
param: 'reasoning_effort',
transform: (params, providerOptions) =>
params.reasoning_effort === 'none' &&
isAzureResponsesChatCompatibilityEnabled(providerOptions) &&
hasFunctionTools(params)
? undefined
: params.reasoning_effort,
},
stream_options: {
param: 'stream_options',
Expand Down
Loading