Skip to content

Commit 7c4d92a

Browse files
zacpsnsarrazin
andauthored
Allow customising defaultQuery for native Azure OpenAI support (#822)
The api-version is a required query parameter for Azure OpenAI, by supporting this we can support it without a gateway like portkey. Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
1 parent 8d2d653 commit 7c4d92a

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,12 @@ MODELS=`[{
353353
"endpoints": [
354354
{
355355
"type": "openai",
356-
"baseURL": "https://gateway.example.com/v1",
356+
"baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
357357
"defaultHeaders": {
358-
"x-portkey-config": '{"provider":"azure-openai","resource_name":"abc-fr","deployment_id":"gpt-4-1106-preview","api_version":"2023-03-15-preview","api_key":"abc...xyz"}'
358+
"api-key": "{api-key}"
359+
},
360+
"defaultQuery": {
361+
"api-version": "2023-05-15"
359362
}
360363
}
361364
]

src/lib/server/endpoints/openai/endpointOai.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@ export const endpointOAIParametersSchema = z.object({
1515
.union([z.literal("completions"), z.literal("chat_completions")])
1616
.default("chat_completions"),
1717
defaultHeaders: z.record(z.string()).optional(),
18+
defaultQuery: z.record(z.string()).optional(),
1819
});
1920

2021
export async function endpointOai(
2122
input: z.input<typeof endpointOAIParametersSchema>
2223
): Promise<Endpoint> {
23-
const { baseURL, apiKey, completion, model, defaultHeaders } =
24+
const { baseURL, apiKey, completion, model, defaultHeaders, defaultQuery } =
2425
endpointOAIParametersSchema.parse(input);
2526
let OpenAI;
2627
try {
@@ -33,6 +34,7 @@ export async function endpointOai(
3334
apiKey: apiKey ?? "sk-",
3435
baseURL,
3536
defaultHeaders,
37+
defaultQuery,
3638
});
3739

3840
if (completion === "completions") {

0 commit comments

Comments
 (0)