Skip to content

Commit

Permalink
Fix OpenAI Embeddings Auth Issue (#1077)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
adhishthite and nsarrazin authored May 6, 2024
1 parent 4805941 commit 736f142
Showing 1 changed file with 4 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ export const embeddingEndpointOpenAIParametersSchema = z.object({
type: z.literal("openai"),
url: z.string().url().default("https://api.openai.com/v1/embeddings"),
apiKey: z.string().default(env.OPENAI_API_KEY),
defaultHeaders: z.record(z.string()).default({}),
});

export async function embeddingEndpointOpenAI(
input: z.input<typeof embeddingEndpointOpenAIParametersSchema>
): Promise<EmbeddingEndpoint> {
const { url, model, apiKey } = embeddingEndpointOpenAIParametersSchema.parse(input);
const { url, model, apiKey, defaultHeaders } =
embeddingEndpointOpenAIParametersSchema.parse(input);

const maxBatchSize = model.maxBatchSize || 100;

Expand All @@ -31,6 +33,7 @@ export async function embeddingEndpointOpenAI(
Accept: "application/json",
"Content-Type": "application/json",
...(apiKey ? { Authorization: `Bearer ${apiKey}` } : {}),
...defaultHeaders,
},
body: JSON.stringify({ input: batchInputs, model: model.name }),
});
Expand Down

0 comments on commit 736f142

Please sign in to comment.