From 325feffaa37617918e49e7efd8837a04c95c0d4e Mon Sep 17 00:00:00 2001 From: csgulati09 Date: Wed, 31 Jul 2024 19:59:53 +0530 Subject: [PATCH] feat: strictOpenAiCompliance header + index signature for chatCompletion response --- src/_types/generalTypes.ts | 1 + src/apis/chatCompletions.ts | 7 +++++++ src/baseClient.ts | 4 ++-- src/client.ts | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/_types/generalTypes.ts b/src/_types/generalTypes.ts index b2359bc..73ac5b5 100644 --- a/src/_types/generalTypes.ts +++ b/src/_types/generalTypes.ts @@ -27,6 +27,7 @@ export interface ApiClientInterface { forwardHeaders?: Array | null | undefined; cacheNamespace?: string | null | undefined; requestTimeout?: number | null | undefined; + strictOpenAiCompliance?: boolean | null | undefined; } export interface APIResponseType { diff --git a/src/apis/chatCompletions.ts b/src/apis/chatCompletions.ts index 9aadb14..a8ca8ae 100644 --- a/src/apis/chatCompletions.ts +++ b/src/apis/chatCompletions.ts @@ -66,11 +66,13 @@ interface Usage { prompt_tokens?: number; completion_tokens?: number; total_tokens?: number; + [key: string]: any; } interface FunctionType { arguments?: string; name?: string; + [key: string]: any; } interface ToolCall { @@ -78,11 +80,13 @@ interface ToolCall { id?: string; function?: FunctionType; type?: 'function'; + [key: string]: any; } interface FunctionCall { arguments?: string; name?: string; + [key: string]: any; } interface Message { @@ -90,6 +94,7 @@ interface Message { content: string | null; function_call?: FunctionCall; tool_calls?: Array; + [key: string]: any; } interface Choices { @@ -97,6 +102,7 @@ interface Choices { message?: Message; delta?: Message; finish_reason?: string; + [key: string]: any; } interface ChatCompletion extends APIResponseType { @@ -106,4 +112,5 @@ interface ChatCompletion extends APIResponseType { model: string; choices: Array; usage: Usage; + [key: string]: any; } \ No newline at end of file diff --git a/src/baseClient.ts b/src/baseClient.ts index bf1630d..86020f6 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, requestTimeout }: 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, strictOpenAiCompliance }: 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, requestTimeout }) + 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, strictOpenAiCompliance }) this.portkeyHeaders = this.defaultHeaders() this.fetch = fetch; this.responseHeaders = {} diff --git a/src/client.ts b/src/client.ts index 37bf3aa..cae2777 100644 --- a/src/client.ts +++ b/src/client.ts @@ -32,6 +32,7 @@ export class Portkey extends ApiClient { forwardHeaders?: Array | null | undefined; requestTimeout?: number | null | undefined; cacheNamespace?: string | null | undefined; + strictOpenAiCompliance?: boolean | null | undefined; constructor({ apiKey = readEnv("PORTKEY_API_KEY") ?? null, baseURL = readEnv("PORTKEY_BASE_URL") ?? null, @@ -59,6 +60,7 @@ export class Portkey extends ApiClient { forwardHeaders, cacheNamespace, requestTimeout, + strictOpenAiCompliance, }: ApiClientInterface) { super({ @@ -88,6 +90,7 @@ export class Portkey extends ApiClient { azureApiVersion, forwardHeaders, requestTimeout, + strictOpenAiCompliance, }); this.apiKey = apiKey; @@ -118,6 +121,7 @@ export class Portkey extends ApiClient { this.azureApiVersion = azureApiVersion; this.forwardHeaders = forwardHeaders; this.requestTimeout = requestTimeout; + this.strictOpenAiCompliance = strictOpenAiCompliance; } completions: API.Completions = new API.Completions(this);