From 17b86532baccdca3e0adfc2276f1fe945cd48ff7 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Thu, 14 Mar 2024 13:10:11 +0530 Subject: [PATCH] feat: x-portkey headers added for new routes --- src/apis/assistants.ts | 18 +++++++++--------- src/apis/embeddings.ts | 1 + src/apis/files.ts | 10 +++++----- src/apis/images.ts | 6 +++--- src/apis/models.ts | 6 +++--- src/apis/threads.ts | 38 +++++++++++++++++++------------------- src/baseClient.ts | 2 ++ 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/apis/assistants.ts b/src/apis/assistants.ts index ec45cf6..7f1f5f1 100644 --- a/src/apis/assistants.ts +++ b/src/apis/assistants.ts @@ -72,7 +72,7 @@ export class Assistants extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.create(body, opts); @@ -96,7 +96,7 @@ export class Assistants extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.list(query, opts); @@ -119,7 +119,7 @@ export class Assistants extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.retrieve(assistantId, opts); @@ -144,7 +144,7 @@ export class Assistants extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.update(assistantId, body, opts); @@ -167,7 +167,7 @@ export class Assistants extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.del(assistantId, opts); @@ -197,7 +197,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.files.create(assistantId, body, opts); @@ -222,7 +222,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.files.list(assistantId, query, opts); @@ -246,7 +246,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.files.retrieve(assistantId, fileId, opts); @@ -270,7 +270,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.assistants.files.del(assistantId, fileId, opts); diff --git a/src/apis/embeddings.ts b/src/apis/embeddings.ts index cce7fe1..de8f5b1 100644 --- a/src/apis/embeddings.ts +++ b/src/apis/embeddings.ts @@ -27,6 +27,7 @@ export class Embeddings extends ApiResource { const config = overrideConfig(this.client.config, params.config) this.client.customHeaders = { ...this.client.customHeaders, ...createHeaders({ ...params, config }) } } + console.log(this.client.customHeaders); const response = this.post(EMBEDDINGS_API, { body, ...opts }) return response } diff --git a/src/apis/files.ts b/src/apis/files.ts index bd3d50e..5de4c55 100644 --- a/src/apis/files.ts +++ b/src/apis/files.ts @@ -25,7 +25,7 @@ export class MainFiles extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.files.create(body, opts); @@ -49,7 +49,7 @@ export class MainFiles extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.files.list(query, opts); @@ -72,7 +72,7 @@ export class MainFiles extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.files.retrieve(fileId, opts); @@ -95,7 +95,7 @@ export class MainFiles extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.files.del(fileId, opts); @@ -118,7 +118,7 @@ export class MainFiles extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.files.content(fileId, opts); diff --git a/src/apis/images.ts b/src/apis/images.ts index d73d6c1..8714d36 100644 --- a/src/apis/images.ts +++ b/src/apis/images.ts @@ -66,7 +66,7 @@ export class Images extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.images.generate(body, opts); @@ -90,7 +90,7 @@ export class Images extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.images.edit(body, opts); @@ -114,7 +114,7 @@ export class Images extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.images.createVariation(body, opts); diff --git a/src/apis/models.ts b/src/apis/models.ts index 9b3d0d0..1cc7531 100644 --- a/src/apis/models.ts +++ b/src/apis/models.ts @@ -19,7 +19,7 @@ export class Models extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.models.list(opts); @@ -42,7 +42,7 @@ export class Models extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.models.retrieve(model, opts); @@ -65,7 +65,7 @@ export class Models extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.models.del(model, opts); diff --git a/src/apis/threads.ts b/src/apis/threads.ts index 1e080c2..00f99f4 100644 --- a/src/apis/threads.ts +++ b/src/apis/threads.ts @@ -36,7 +36,7 @@ export class Threads extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.create(body, opts); @@ -59,7 +59,7 @@ export class Threads extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.retrieve(threadId, opts); @@ -84,7 +84,7 @@ export class Threads extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.update(threadId, body, opts); @@ -107,7 +107,7 @@ export class Threads extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.del(threadId, opts); @@ -131,7 +131,7 @@ export class Threads extends ApiResource { const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.createAndRun(body, opts); @@ -168,7 +168,7 @@ export class Messages extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.create(threadId, body, opts); @@ -193,7 +193,7 @@ export class Messages extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.list(threadId, query, opts); @@ -217,7 +217,7 @@ export class Messages extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.retrieve(threadId, messageId, opts); @@ -244,7 +244,7 @@ export class Messages extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.update(threadId, messageId, body, opts); @@ -275,7 +275,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.files.list(threadId, messageId, query, opts); @@ -300,7 +300,7 @@ export class Files extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.messages.files.retrieve(threadId, messageId, fileId, opts); @@ -337,7 +337,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.create(threadId, body, opts); @@ -362,7 +362,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.list(threadId, query, opts); @@ -386,7 +386,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.retrieve(threadId, runId, opts); @@ -412,7 +412,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.update(threadId, runId, body, opts); @@ -438,7 +438,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.submitToolOutputs(threadId, runId, body, opts); @@ -462,7 +462,7 @@ export class Runs extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.cancel(threadId, runId, opts); @@ -492,7 +492,7 @@ export class Steps extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.steps.list(threadId, runId, query, opts); @@ -517,7 +517,7 @@ export class Steps extends ApiResource{ const OAIclient = new OpenAI({ apiKey: OPEN_AI_API_KEY, baseURL: PORTKEY_BASE_URL, - defaultHeaders: this.client.customHeaders, + defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders}, }); const result = await OAIclient.beta.threads.runs.steps.retrieve(threadId, runId, stepId, opts); diff --git a/src/baseClient.ts b/src/baseClient.ts index 5985e6a..db692b2 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -117,12 +117,14 @@ export abstract class ApiClient { baseURL: string; customHeaders: Record responseHeaders: Record + portkeyHeaders: Record private fetch: Fetch; constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh }: ApiClientInterface) { this.apiKey = apiKey ?? ""; this.baseURL = baseURL ?? ""; this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh }) + this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} }