Skip to content

Commit

Permalink
Merge branch 'main' into hotfix/vercel-response
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Jul 10, 2024
2 parents 1f6af08 + 9d57fc5 commit 7de4fd8
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 17 deletions.
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 16 additions & 1 deletion src/_types/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,22 @@ 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;
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<string> | null | undefined;
cacheNamespace?: string | null | undefined;
requestTimeout?: number | null | undefined;
}

export interface APIResponseType {
Expand Down
1 change: 1 addition & 0 deletions src/apis/chatCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class ChatCompletions extends ApiResource {

export interface ChatCompletionsBodyBase extends ModelParams {
messages?: Array<Message>;
response_format?: object;
}

export interface ChatCompletionsBodyStreaming extends ChatCompletionsBodyBase {
Expand Down
6 changes: 6 additions & 0 deletions src/apis/createHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const createHeaders = (config: Record<string, any>): Record<string, strin
v = v.toString()
}

// logic to handle forwardHeaders into a comma separated string
if (k === "forwardHeaders") {
v = v.join(',')

}

k = k.replace('ID', 'Id')
.replace(/[A-Z]/g, letter => `-${letter.toLowerCase()}`)
if (!isEmpty(v) && typeof v == "object") {
Expand Down
4 changes: 2 additions & 2 deletions src/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ export abstract class ApiClient {
portkeyHeaders: Record<string, string>

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, 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 })
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 = {}
Expand Down
68 changes: 64 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, unknown> | string | null | undefined;
provider: string | null | undefined;
Expand All @@ -17,6 +17,21 @@ 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;
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<string> | null | undefined;
requestTimeout?: number | null | undefined;
cacheNamespace?: string | null | undefined;
constructor({
apiKey = readEnv("PORTKEY_API_KEY") ?? null,
baseURL = readEnv("PORTKEY_BASE_URL") ?? null,
Expand All @@ -29,6 +44,21 @@ export class Portkey extends ApiClient {
cacheForceRefresh,
debug,
customHost,
openaiProject,
openaiOrganization,
awsSecretAccessKey,
awsAccessKeyId,
awsSessionToken,
awsRegion,
vertexProjectId,
vertexRegion,
workersAiAccountId,
azureResourceName,
azureDeploymentId,
azureApiVersion,
forwardHeaders,
cacheNamespace,
requestTimeout,
}: ApiClientInterface) {

super({
Expand All @@ -42,7 +72,22 @@ export class Portkey extends ApiClient {
Authorization,
cacheForceRefresh,
debug,
customHost
customHost,
cacheNamespace,
openaiProject,
openaiOrganization,
awsSecretAccessKey,
awsAccessKeyId,
awsSessionToken,
awsRegion,
vertexProjectId,
vertexRegion,
workersAiAccountId,
azureResourceName,
azureDeploymentId,
azureApiVersion,
forwardHeaders,
requestTimeout,
});

this.apiKey = apiKey;
Expand All @@ -57,7 +102,22 @@ export class Portkey extends ApiClient {
this.metadata = metadata
this.cacheForceRefresh = cacheForceRefresh;
this.debug = debug;
this.customHost = customHost
this.customHost = customHost;
this.cacheNamespace = cacheNamespace;;
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;
this.requestTimeout = requestTimeout;
}

completions: API.Completions = new API.Completions(this);
Expand Down

0 comments on commit 7de4fd8

Please sign in to comment.