Skip to content

Commit

Permalink
feat: common default header builder function
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Mar 18, 2024
1 parent c3a181f commit c3f49ca
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 53 deletions.
20 changes: 10 additions & 10 deletions src/apis/assistants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { finalResponse, overrideConfig } from "../utils";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand Down Expand Up @@ -72,7 +72,7 @@ export class Assistants extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.create(body, opts).withResponse();
Expand All @@ -97,7 +97,7 @@ export class Assistants extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});
// @ts-ignore
const result = await OAIclient.beta.assistants.list(query, opts).withResponse();
Expand All @@ -121,7 +121,7 @@ export class Assistants extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.retrieve(assistantId, opts).withResponse();
Expand All @@ -147,7 +147,7 @@ export class Assistants extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.update(assistantId, body, opts).withResponse();
Expand All @@ -171,7 +171,7 @@ export class Assistants extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.del(assistantId, opts).withResponse();
Expand Down Expand Up @@ -202,7 +202,7 @@ export class Files extends ApiResource{
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.create(assistantId, body, opts).withResponse();
Expand All @@ -228,7 +228,7 @@ export class Files extends ApiResource{
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});
// @ts-ignore
const result = await OAIclient.beta.assistants.files.list(assistantId, query, opts).withResponse();
Expand All @@ -253,7 +253,7 @@ export class Files extends ApiResource{
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.retrieve(assistantId, fileId, opts).withResponse();
Expand All @@ -278,7 +278,7 @@ export class Files extends ApiResource{
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.beta.assistants.files.del(assistantId, fileId, opts).withResponse();
Expand Down
12 changes: 6 additions & 6 deletions src/apis/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { finalResponse, overrideConfig } from "../utils";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand All @@ -25,7 +25,7 @@ export class MainFiles extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

// @ts-ignore
Expand All @@ -51,7 +51,7 @@ export class MainFiles extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.files.list(query, opts).withResponse();
Expand All @@ -75,7 +75,7 @@ export class MainFiles extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.files.retrieve(fileId, opts).withResponse();
Expand All @@ -99,7 +99,7 @@ export class MainFiles extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.files.del(fileId, opts).withResponse();
Expand All @@ -123,7 +123,7 @@ export class MainFiles extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.files.content(fileId, opts).withResponse();
Expand Down
8 changes: 4 additions & 4 deletions src/apis/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { finalResponse, overrideConfig } from "../utils";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand Down Expand Up @@ -66,7 +66,7 @@ export class Images extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});
// @ts-ignore
const result = await OAIclient.images.generate(body, opts).withResponse();
Expand All @@ -91,7 +91,7 @@ export class Images extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});

// @ts-ignore
Expand All @@ -117,7 +117,7 @@ export class Images extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
defaultHeaders: defaultHeadersBuilder(this.client),
});
// @ts-ignore
const result = await OAIclient.images.createVariation(body, opts).withResponse();
Expand Down
17 changes: 4 additions & 13 deletions src/apis/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { finalResponse, overrideConfig } from "../utils";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand All @@ -23,10 +23,7 @@ export class Models extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {
...this.client.customHeaders,
...this.client.portkeyHeaders,
},
defaultHeaders: defaultHeadersBuilder(this.client)
});

const result = await OAIclient.models.list(opts).withResponse();
Expand All @@ -50,10 +47,7 @@ export class Models extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {
...this.client.customHeaders,
...this.client.portkeyHeaders,
},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.models.retrieve(model, opts).withResponse();
Expand All @@ -77,10 +71,7 @@ export class Models extends ApiResource {
const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: {
...this.client.customHeaders,
...this.client.portkeyHeaders,
},
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.models.del(model, opts).withResponse();
Expand Down
Loading

0 comments on commit c3f49ca

Please sign in to comment.