Skip to content

Commit

Permalink
feat: x-portkey headers added for new routes
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Mar 14, 2024
1 parent f31f62a commit 17b8653
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
18 changes: 9 additions & 9 deletions src/apis/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/apis/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmbeddingsResponse>(EMBEDDINGS_API, { body, ...opts })
return response
}
Expand Down
10 changes: 5 additions & 5 deletions src/apis/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/apis/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/apis/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
38 changes: 19 additions & 19 deletions src/apis/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,14 @@ export abstract class ApiClient {
baseURL: string;
customHeaders: Record<string, string>
responseHeaders: Record<string, string>
portkeyHeaders: Record<string, string>

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 = {}
}
Expand Down

0 comments on commit 17b8653

Please sign in to comment.