From 5bce85d7398e639bce2b21f16e83d19548725fc8 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 14 May 2024 07:58:42 -0400 Subject: [PATCH 01/10] feat: added support for cacheNamespace header --- src/_types/generalTypes.ts | 1 + src/baseClient.ts | 4 ++-- src/client.ts | 8 ++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index d1a785a..30a5160 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -12,6 +12,7 @@ export interface ApiClientInterface { cacheForceRefresh?: boolean | null | undefined; debug?: boolean | null | undefined; customHost?: string | null | undefined + cacheNamespace?: string | null | undefined; } export interface APIResponseType { diff --git a/src/baseClient.ts b/src/baseClient.ts index dbf6937..51f96ce 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -120,10 +120,10 @@ export abstract class ApiClient { portkeyHeaders: Record private fetch: Fetch; - constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost }: ApiClientInterface) { + constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace }: ApiClientInterface) { this.apiKey = apiKey ?? ""; this.baseURL = baseURL ?? ""; - this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost }) + this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace }) this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} diff --git a/src/client.ts b/src/client.ts index 23559d5..a9dd992 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,6 +17,7 @@ export class Portkey extends ApiClient { cacheForceRefresh?: boolean | null | undefined; debug?: boolean | null | undefined; customHost?: string | null | undefined; + cacheNamespace?: string | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, baseURL = readEnv("PORTKEY_BASE_URL") ?? null, @@ -29,6 +30,7 @@ export class Portkey extends ApiClient { cacheForceRefresh, debug, customHost, + cacheNamespace, }: ApiClientInterface) { super({ @@ -42,7 +44,8 @@ export class Portkey extends ApiClient { Authorization, cacheForceRefresh, debug, - customHost + customHost, + cacheNamespace }); this.apiKey = apiKey; @@ -57,7 +60,8 @@ export class Portkey extends ApiClient { this.metadata = metadata this.cacheForceRefresh = cacheForceRefresh; this.debug = debug; - this.customHost = customHost + this.customHost = customHost; + this.cacheNamespace = cacheNamespace; } completions: API.Completions = new API.Completions(this); From 6524a161039b68616154aaebea12f4fab9611b20 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 21 May 2024 01:14:57 -0400 Subject: [PATCH 02/10] feat: openai-project openai-organization headers added --- src/_types/generalTypes.ts | 4 +++- src/baseClient.ts | 4 ++-- src/client.ts | 12 ++++++++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index d1a785a..54f64d6 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -11,7 +11,9 @@ export interface ApiClientInterface { Authorization?: string | null | undefined; cacheForceRefresh?: boolean | null | undefined; debug?: boolean | null | undefined; - customHost?: string | null | undefined + customHost?: string | null | undefined; + openaiProject?: string | null | undefined; + openaiOrganization?: string | null | undefined; } export interface APIResponseType { diff --git a/src/baseClient.ts b/src/baseClient.ts index dbf6937..6c0a5c6 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -120,10 +120,10 @@ export abstract class ApiClient { portkeyHeaders: Record private fetch: Fetch; - constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost }: ApiClientInterface) { + constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization }: ApiClientInterface) { this.apiKey = apiKey ?? ""; this.baseURL = baseURL ?? ""; - this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost }) + this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization }) this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} diff --git a/src/client.ts b/src/client.ts index 23559d5..e6bb7b6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,6 +17,8 @@ export class Portkey extends ApiClient { cacheForceRefresh?: boolean | null | undefined; debug?: boolean | null | undefined; customHost?: string | null | undefined; + openaiProject: string | null | undefined; + openaiOrganization: string | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, baseURL = readEnv("PORTKEY_BASE_URL") ?? null, @@ -29,6 +31,8 @@ export class Portkey extends ApiClient { cacheForceRefresh, debug, customHost, + openaiProject, + openaiOrganization }: ApiClientInterface) { super({ @@ -42,7 +46,9 @@ export class Portkey extends ApiClient { Authorization, cacheForceRefresh, debug, - customHost + customHost, + openaiProject, + openaiOrganization }); this.apiKey = apiKey; @@ -57,7 +63,9 @@ export class Portkey extends ApiClient { this.metadata = metadata this.cacheForceRefresh = cacheForceRefresh; this.debug = debug; - this.customHost = customHost + this.customHost = customHost; + this.openaiProject = openaiProject; + this.openaiOrganization = openaiOrganization; } completions: API.Completions = new API.Completions(this); From 60e87e6748747b33ac9191ab59c5897291560253 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Fri, 31 May 2024 20:28:08 +0530 Subject: [PATCH 03/10] feat: vendor specific headers and forwardHeaders conversation logic --- src/_types/generalTypes.ts | 11 ++++++++ src/apis/createHeaders.ts | 6 +++++ src/baseClient.ts | 4 +-- src/client.ts | 53 +++++++++++++++++++++++++++++++++++--- 4 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index 54f64d6..488a1fe 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -14,6 +14,17 @@ export interface ApiClientInterface { customHost?: string | null | undefined; openaiProject?: string | null | undefined; openaiOrganization?: string | null | undefined; + awsSecretAccessKey?: string | null | undefined; + awsAccessKeyId?: string | null | undefined; + awsSessionToken?: string | null | undefined; + awsRegion?: string | null | undefined; + vertexProjectId?: string | null | undefined; + vertexRegion?: string | null | undefined; + workersAiAccountId?: string | null | undefined; + azureResourceName?: string | null | undefined; + azureDeploymentId?: string | null | undefined; + azureApiVersion?: string | null | undefined; + forwardHeaders?: Array | null | undefined; } export interface APIResponseType { diff --git a/src/apis/createHeaders.ts b/src/apis/createHeaders.ts index b63e4fb..54b9bc2 100644 --- a/src/apis/createHeaders.ts +++ b/src/apis/createHeaders.ts @@ -18,6 +18,12 @@ export const createHeaders = (config: Record): Record `-${letter.toLowerCase()}`) if (!isEmpty(v) && typeof v == "object") { diff --git a/src/baseClient.ts b/src/baseClient.ts index 6c0a5c6..bb88d9b 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -120,10 +120,10 @@ export abstract class ApiClient { portkeyHeaders: Record private fetch: Fetch; - constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization }: ApiClientInterface) { + constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders }: ApiClientInterface) { this.apiKey = apiKey ?? ""; this.baseURL = baseURL ?? ""; - this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization }) + this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders }) this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} diff --git a/src/client.ts b/src/client.ts index e6bb7b6..38a999f 100644 --- a/src/client.ts +++ b/src/client.ts @@ -17,8 +17,20 @@ export class Portkey extends ApiClient { cacheForceRefresh?: boolean | null | undefined; debug?: boolean | null | undefined; customHost?: string | null | undefined; - openaiProject: string | null | undefined; - openaiOrganization: string | null | undefined; + openaiProject?: string | null | undefined; + openaiOrganization?: string | null | undefined; + awsSecretAccessKey?: string | null | undefined; + awsAccessKeyId?: string | null | undefined; + awsSessionToken?: string | null | undefined; + awsRegion?: string | null | undefined; + vertexProjectId?: string | null | undefined; + vertexRegion?: string | null | undefined; + workersAiAccountId?: string | null | undefined; + azureResourceName?: string | null | undefined; + azureDeploymentId?: string | null | undefined; + azureApiVersion?: string | null | undefined; + forwardHeaders?: Array | null | undefined; + constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, baseURL = readEnv("PORTKEY_BASE_URL") ?? null, @@ -32,7 +44,18 @@ export class Portkey extends ApiClient { debug, customHost, openaiProject, - openaiOrganization + openaiOrganization, + awsSecretAccessKey, + awsAccessKeyId, + awsSessionToken, + awsRegion, + vertexProjectId, + vertexRegion, + workersAiAccountId, + azureResourceName, + azureDeploymentId, + azureApiVersion, + forwardHeaders, }: ApiClientInterface) { super({ @@ -48,7 +71,18 @@ export class Portkey extends ApiClient { debug, customHost, openaiProject, - openaiOrganization + openaiOrganization, + awsSecretAccessKey, + awsAccessKeyId, + awsSessionToken, + awsRegion, + vertexProjectId, + vertexRegion, + workersAiAccountId, + azureResourceName, + azureDeploymentId, + azureApiVersion, + forwardHeaders, }); this.apiKey = apiKey; @@ -66,6 +100,17 @@ export class Portkey extends ApiClient { this.customHost = customHost; this.openaiProject = openaiProject; this.openaiOrganization = openaiOrganization; + this.awsSecretAccessKey = awsSecretAccessKey; + this.awsAccessKeyId = awsAccessKeyId; + this.awsSessionToken = awsSessionToken; + this.awsRegion = awsRegion; + this.vertexProjectId = vertexProjectId; + this.vertexRegion = vertexRegion; + this.workersAiAccountId = workersAiAccountId; + this.azureResourceName = azureResourceName; + this.azureDeploymentId = azureDeploymentId; + this.azureApiVersion = azureApiVersion; + this.forwardHeaders = forwardHeaders; } completions: API.Completions = new API.Completions(this); From d52f0865e3ec0a8e7e15c5a4ff3f3bfffa578f36 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 18 Jun 2024 17:15:21 +0530 Subject: [PATCH 04/10] feat: request-timeout header supported --- src/_types/generalTypes.ts | 1 + src/baseClient.ts | 4 ++-- src/client.ts | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index 6e2683f..b2359bc 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -26,6 +26,7 @@ export interface ApiClientInterface { azureApiVersion?: string | null | undefined; forwardHeaders?: Array | null | undefined; cacheNamespace?: string | null | undefined; + requestTimeout?: number | null | undefined; } export interface APIResponseType { diff --git a/src/baseClient.ts b/src/baseClient.ts index ef4f0d9..bf1630d 100644 --- a/src/baseClient.ts +++ b/src/baseClient.ts @@ -120,10 +120,10 @@ export abstract class ApiClient { portkeyHeaders: Record private fetch: Fetch; - constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders, cacheNamespace }: ApiClientInterface) { + constructor({ apiKey, baseURL, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders, cacheNamespace, requestTimeout }: ApiClientInterface) { this.apiKey = apiKey ?? ""; this.baseURL = baseURL ?? ""; - this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders }) + this.customHeaders = createHeaders({ apiKey, config, virtualKey, traceID, metadata, provider, Authorization, cacheForceRefresh, debug, customHost, cacheNamespace, openaiProject, openaiOrganization, awsSecretAccessKey, awsAccessKeyId, awsSessionToken, awsRegion, vertexProjectId, vertexRegion, workersAiAccountId, azureResourceName, azureDeploymentId, azureApiVersion, forwardHeaders, requestTimeout }) this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} diff --git a/src/client.ts b/src/client.ts index b8221fa..5d8dfa6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -30,6 +30,7 @@ export class Portkey extends ApiClient { azureDeploymentId?: string | null | undefined; azureApiVersion?: string | null | undefined; forwardHeaders?: Array | null | undefined; + requestTimeout? : number | null | undefined; cacheNamespace?: string | null | undefined; constructor({ @@ -58,6 +59,7 @@ export class Portkey extends ApiClient { azureApiVersion, forwardHeaders, cacheNamespace, + requestTimeout, }: ApiClientInterface) { super({ @@ -86,6 +88,7 @@ export class Portkey extends ApiClient { azureDeploymentId, azureApiVersion, forwardHeaders, + requestTimeout, }); this.apiKey = apiKey; @@ -115,6 +118,7 @@ export class Portkey extends ApiClient { this.azureDeploymentId = azureDeploymentId; this.azureApiVersion = azureApiVersion; this.forwardHeaders = forwardHeaders; + this.requestTimeout = requestTimeout; } completions: API.Completions = new API.Completions(this); From 4deb6c1ab914d3d11bf475195acdcffe603635b8 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 18 Jun 2024 17:23:20 +0530 Subject: [PATCH 05/10] fix: formatting issue --- src/client.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 5d8dfa6..8939e71 100644 --- a/src/client.ts +++ b/src/client.ts @@ -31,7 +31,6 @@ export class Portkey extends ApiClient { azureApiVersion?: string | null | undefined; forwardHeaders?: Array | null | undefined; requestTimeout? : number | null | undefined; - cacheNamespace?: string | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, From ef965ad6ba5c8775112f1f0f0030009c9a490e77 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Tue, 18 Jun 2024 17:24:15 +0530 Subject: [PATCH 06/10] fix: formatting issue --- src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 8939e71..05a5e2b 100644 --- a/src/client.ts +++ b/src/client.ts @@ -30,7 +30,7 @@ export class Portkey extends ApiClient { azureDeploymentId?: string | null | undefined; azureApiVersion?: string | null | undefined; forwardHeaders?: Array | null | undefined; - requestTimeout? : number | null | undefined; + requestTimeout?: number | null | undefined; cacheNamespace?: string | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, From b2675117cfdedef8742d0519d910d1d0213375a6 Mon Sep 17 00:00:00 2001 From: visargD Date: Fri, 21 Jun 2024 00:24:17 +0530 Subject: [PATCH 07/10] 1.3.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 151d345..de2e609 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "portkey-ai", - "version": "1.3.0", + "version": "1.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "portkey-ai", - "version": "1.3.0", + "version": "1.3.1", "license": "MIT", "dependencies": { "agentkeepalive": "^4.5.0", diff --git a/package.json b/package.json index f29ad02..4247d3e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "portkey-ai", - "version": "1.3.0", + "version": "1.3.1", "description": "Node client library for the Portkey API", "types": "dist/src/index.d.ts", "main": "dist/src/index.js", From 8a25a9927bbfe5ba57720cd2dd0c9aa9fd66eb31 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Wed, 3 Jul 2024 13:08:08 +0530 Subject: [PATCH 08/10] fix: initializer for apiKey and baseURL --- src/client.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client.ts b/src/client.ts index 05a5e2b..37bf3aa 100644 --- a/src/client.ts +++ b/src/client.ts @@ -6,8 +6,8 @@ import { MISSING_API_KEY_ERROR_MESSAGE, PORTKEY_BASE_URL } from "./constants"; import { castToError, readEnv } from "./utils"; export class Portkey extends ApiClient { - override apiKey: string | null; - override baseURL: string; + declare apiKey: string | null; + declare baseURL: string; virtualKey: string | null; config: Record | string | null | undefined; provider: string | null | undefined; From 0c2265d0fb590cd444b3fffc03c6da8cf12e301b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:01:59 +0000 Subject: [PATCH 09/10] chore(deps-dev): bump braces from 3.0.2 to 3.0.3 Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3. - [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md) - [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3) --- updated-dependencies: - dependency-name: braces dependency-type: indirect ... Signed-off-by: dependabot[bot] --- package-lock.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index de2e609..3d29014 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3295,12 +3295,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -4141,9 +4141,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" From 44d4120999eafbd3135e24c2941095955a21fa51 Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Fri, 5 Jul 2024 18:37:34 +0530 Subject: [PATCH 10/10] fix: response_format added in chat calls --- src/apis/chatCompletions.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/apis/chatCompletions.ts b/src/apis/chatCompletions.ts index a878f92..be20a10 100644 --- a/src/apis/chatCompletions.ts +++ b/src/apis/chatCompletions.ts @@ -49,6 +49,7 @@ class ChatCompletions extends ApiResource { export interface ChatCompletionsBodyBase extends ModelParams { messages?: Array; + response_format?: object; } export interface ChatCompletionsBodyStreaming extends ChatCompletionsBodyBase {