Skip to content

Commit

Permalink
feat: vendor specific headers and forwardHeaders conversation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed May 31, 2024
1 parent 6524a16 commit 60e87e6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/_types/generalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | null | undefined;
}

export interface APIResponseType {
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, 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 = {}
Expand Down
53 changes: 49 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> | null | undefined;

constructor({
apiKey = readEnv("PORTKEY_API_KEY") ?? null,
baseURL = readEnv("PORTKEY_BASE_URL") ?? null,
Expand All @@ -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({
Expand All @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 60e87e6

Please sign in to comment.