zacps nsarrazin HF staff commited on
Commit
7c4d92a
1 Parent(s): 8d2d653

Allow customising defaultQuery for native Azure OpenAI support (#822)

Browse files

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 <[email protected]>

README.md CHANGED
@@ -353,9 +353,12 @@ MODELS=`[{
353
  "endpoints": [
354
  {
355
  "type": "openai",
356
- "baseURL": "https://gateway.example.com/v1",
357
  "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"}'
 
 
 
359
  }
360
  }
361
  ]
 
353
  "endpoints": [
354
  {
355
  "type": "openai",
356
+ "baseURL": "https://{resource-name}.openai.azure.com/openai/deployments/{deployment-id}",
357
  "defaultHeaders": {
358
+ "api-key": "{api-key}"
359
+ },
360
+ "defaultQuery": {
361
+ "api-version": "2023-05-15"
362
  }
363
  }
364
  ]
src/lib/server/endpoints/openai/endpointOai.ts CHANGED
@@ -15,12 +15,13 @@ export const endpointOAIParametersSchema = z.object({
15
  .union([z.literal("completions"), z.literal("chat_completions")])
16
  .default("chat_completions"),
17
  defaultHeaders: z.record(z.string()).optional(),
 
18
  });
19
 
20
  export async function endpointOai(
21
  input: z.input<typeof endpointOAIParametersSchema>
22
  ): Promise<Endpoint> {
23
- const { baseURL, apiKey, completion, model, defaultHeaders } =
24
  endpointOAIParametersSchema.parse(input);
25
  let OpenAI;
26
  try {
@@ -33,6 +34,7 @@ export async function endpointOai(
33
  apiKey: apiKey ?? "sk-",
34
  baseURL,
35
  defaultHeaders,
 
36
  });
37
 
38
  if (completion === "completions") {
 
15
  .union([z.literal("completions"), z.literal("chat_completions")])
16
  .default("chat_completions"),
17
  defaultHeaders: z.record(z.string()).optional(),
18
+ defaultQuery: z.record(z.string()).optional(),
19
  });
20
 
21
  export async function endpointOai(
22
  input: z.input<typeof endpointOAIParametersSchema>
23
  ): Promise<Endpoint> {
24
+ const { baseURL, apiKey, completion, model, defaultHeaders, defaultQuery } =
25
  endpointOAIParametersSchema.parse(input);
26
  let OpenAI;
27
  try {
 
34
  apiKey: apiKey ?? "sk-",
35
  baseURL,
36
  defaultHeaders,
37
+ defaultQuery,
38
  });
39
 
40
  if (completion === "completions") {