Spaces:
Paused
Paused
Fix OpenAI Embeddings Auth Issue (#1077)
Browse files* Update embeddingEndpoints.ts
Adds the `Api-Key` Parameter instead of `Authorization` since OpenAI depends on API Key
* Add `defaultHeaders` to openAI embeddings endpoint and revert auth header
---------
Co-authored-by: Nathan Sarrazin <sarrazin.nathan@gmail.com>
src/lib/server/embeddingEndpoints/openai/embeddingEndpoints.ts
CHANGED
|
@@ -9,12 +9,14 @@ export const embeddingEndpointOpenAIParametersSchema = z.object({
|
|
| 9 |
type: z.literal("openai"),
|
| 10 |
url: z.string().url().default("https://api.openai.com/v1/embeddings"),
|
| 11 |
apiKey: z.string().default(env.OPENAI_API_KEY),
|
|
|
|
| 12 |
});
|
| 13 |
|
| 14 |
export async function embeddingEndpointOpenAI(
|
| 15 |
input: z.input<typeof embeddingEndpointOpenAIParametersSchema>
|
| 16 |
): Promise<EmbeddingEndpoint> {
|
| 17 |
-
const { url, model, apiKey } =
|
|
|
|
| 18 |
|
| 19 |
const maxBatchSize = model.maxBatchSize || 100;
|
| 20 |
|
|
@@ -31,6 +33,7 @@ export async function embeddingEndpointOpenAI(
|
|
| 31 |
Accept: "application/json",
|
| 32 |
"Content-Type": "application/json",
|
| 33 |
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
|
|
|
| 34 |
},
|
| 35 |
body: JSON.stringify({ input: batchInputs, model: model.name }),
|
| 36 |
});
|
|
|
|
| 9 |
type: z.literal("openai"),
|
| 10 |
url: z.string().url().default("https://api.openai.com/v1/embeddings"),
|
| 11 |
apiKey: z.string().default(env.OPENAI_API_KEY),
|
| 12 |
+
defaultHeaders: z.record(z.string()).default({}),
|
| 13 |
});
|
| 14 |
|
| 15 |
export async function embeddingEndpointOpenAI(
|
| 16 |
input: z.input<typeof embeddingEndpointOpenAIParametersSchema>
|
| 17 |
): Promise<EmbeddingEndpoint> {
|
| 18 |
+
const { url, model, apiKey, defaultHeaders } =
|
| 19 |
+
embeddingEndpointOpenAIParametersSchema.parse(input);
|
| 20 |
|
| 21 |
const maxBatchSize = model.maxBatchSize || 100;
|
| 22 |
|
|
|
|
| 33 |
Accept: "application/json",
|
| 34 |
"Content-Type": "application/json",
|
| 35 |
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
|
| 36 |
+
...defaultHeaders,
|
| 37 |
},
|
| 38 |
body: JSON.stringify({ input: batchInputs, model: model.name }),
|
| 39 |
});
|