Skip to content

Commit

Permalink
feat: getHeaders() for models, threads, images, files and assistants
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Mar 14, 2024
1 parent ebb4596 commit 5a4c375
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 86 deletions.
47 changes: 28 additions & 19 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, PORTKEY_BASE_URL } from "../constants";
import { overrideConfig } from "../utils";
import { finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand Down Expand Up @@ -75,8 +75,9 @@ export class Assistants extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.create(body, opts);
return result;
const result = await OAIclient.beta.assistants.create(body, opts).withResponse();

return finalResponse(result);
}

async list(
Expand All @@ -99,8 +100,9 @@ export class Assistants extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.list(query, opts);
return result;
const result = await OAIclient.beta.assistants.list(query, opts).withResponse();

return finalResponse(result);
}

async retrieve(
Expand All @@ -122,8 +124,9 @@ export class Assistants extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.retrieve(assistantId, opts);
return result;
const result = await OAIclient.beta.assistants.retrieve(assistantId, opts).withResponse();

return finalResponse(result);
}

async update(
Expand All @@ -147,8 +150,9 @@ export class Assistants extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.update(assistantId, body, opts);
return result;
const result = await OAIclient.beta.assistants.update(assistantId, body, opts).withResponse();

return finalResponse(result);
}

async del(
Expand All @@ -170,8 +174,9 @@ export class Assistants extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.del(assistantId, opts);
return result;
const result = await OAIclient.beta.assistants.del(assistantId, opts).withResponse();

return finalResponse(result);
}

}
Expand Down Expand Up @@ -200,8 +205,9 @@ export class Files extends ApiResource{
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.files.create(assistantId, body, opts);
return result;
const result = await OAIclient.beta.assistants.files.create(assistantId, body, opts).withResponse();

return finalResponse(result);
}

async list(
Expand All @@ -225,8 +231,9 @@ export class Files extends ApiResource{
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.files.list(assistantId, query, opts);
return result;
const result = await OAIclient.beta.assistants.files.list(assistantId, query, opts).withResponse();

return finalResponse(result);
}

async retrieve(
Expand All @@ -249,8 +256,9 @@ export class Files extends ApiResource{
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.files.retrieve(assistantId, fileId, opts);
return result;
const result = await OAIclient.beta.assistants.files.retrieve(assistantId, fileId, opts).withResponse();

return finalResponse(result);
}

async del(
Expand All @@ -273,8 +281,9 @@ export class Files extends ApiResource{
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.beta.assistants.files.del(assistantId, fileId, opts);
return result;
const result = await OAIclient.beta.assistants.files.del(assistantId, fileId, opts).withResponse();

return finalResponse(result);
}

}
27 changes: 16 additions & 11 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, PORTKEY_BASE_URL } from "../constants";
import { overrideConfig } from "../utils";
import { finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand All @@ -28,8 +28,9 @@ export class MainFiles extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.files.create(body, opts);
return result;
const result = await OAIclient.files.create(body, opts).withResponse();

return finalResponse(result);
}

async list(
Expand All @@ -52,8 +53,9 @@ export class MainFiles extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.files.list(query, opts);
return result;
const result = await OAIclient.files.list(query, opts).withResponse();

return finalResponse(result);
}

async retrieve(
Expand All @@ -75,8 +77,9 @@ export class MainFiles extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.files.retrieve(fileId, opts);
return result;
const result = await OAIclient.files.retrieve(fileId, opts).withResponse();

return finalResponse(result);
}

async del(
Expand All @@ -98,8 +101,9 @@ export class MainFiles extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.files.del(fileId, opts);
return result;
const result = await OAIclient.files.del(fileId, opts).withResponse();

return finalResponse(result);
}

async retrieveContent(
Expand All @@ -121,8 +125,9 @@ export class MainFiles extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.files.content(fileId, opts);
return result;
const result = await OAIclient.files.content(fileId, opts).withResponse();

return finalResponse(result);
}

}
Expand Down
17 changes: 10 additions & 7 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, PORTKEY_BASE_URL } from "../constants";
import { overrideConfig } from "../utils";
import { finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand Down Expand Up @@ -69,8 +69,9 @@ export class Images extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.images.generate(body, opts);
return result;
const result = await OAIclient.images.generate(body, opts).withResponse();

return finalResponse(result);
}

async edit(
Expand All @@ -93,8 +94,9 @@ export class Images extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.images.edit(body, opts);
return result;
const result = await OAIclient.images.edit(body, opts).withResponse();

return finalResponse(result);
}

async createVariation(
Expand All @@ -117,7 +119,8 @@ export class Images extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.images.createVariation(body, opts);
return result;
const result = await OAIclient.images.createVariation(body, opts).withResponse();

return finalResponse(result);
}
}
17 changes: 10 additions & 7 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, PORTKEY_BASE_URL } from "../constants";
import { overrideConfig } from "../utils";
import { finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";

Expand All @@ -22,8 +22,9 @@ export class Models extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.models.list(opts);
return result;
const result = await OAIclient.models.list(opts).withResponse();

return finalResponse(result);
}

async retrieve(
Expand All @@ -45,8 +46,9 @@ export class Models extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.models.retrieve(model, opts);
return result;
const result = await OAIclient.models.retrieve(model, opts).withResponse();

return finalResponse(result);
}

async del(
Expand All @@ -68,7 +70,8 @@ export class Models extends ApiResource {
defaultHeaders: {...this.client.customHeaders, ...this.client.portkeyHeaders},
});

const result = await OAIclient.models.del(model, opts);
return result;
const result = await OAIclient.models.del(model, opts).withResponse();

return finalResponse(result);
}
}
Loading

0 comments on commit 5a4c375

Please sign in to comment.