Skip to content

Commit

Permalink
feat: finetune support added
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed May 6, 2024
1 parent d0f9e40 commit 0dd8306
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
172 changes: 172 additions & 0 deletions src/apis/fineTuning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import { JobCreateParams, JobListEventsParams, JobListParams } from "openai/resources/fine-tuning/jobs/jobs";
import { ApiClientInterface } from "../_types/generalTypes";
import { ApiResource } from "../apiResource";
import { RequestOptions } from "../baseClient";
import { OPEN_AI_API_KEY } from "../constants";
import { defaultHeadersBuilder, finalResponse, overrideConfig } from "../utils";
import { createHeaders } from "./createHeaders";
import OpenAI from "openai";
import { CheckpointListParams } from "openai/resources/fine-tuning/jobs/checkpoints";


export class FineTuning extends ApiResource{
jobs: Jobs;
constructor(client:any) {
super(client);
this.jobs = new Jobs(client);
}
}

export class Jobs extends ApiResource {
checkpoints: Checkpoints;
constructor(client:any) {
super(client);
this.checkpoints = new Checkpoints(client);
}

async create(
_body: JobCreateParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const body: JobCreateParams = _body;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.create(body, opts).withResponse();
return finalResponse(result);
}

async retrieve(
fineTuningJobId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.retrieve(fineTuningJobId, opts).withResponse();
return finalResponse(result);
}

async list(
_query?: JobListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const query: JobListParams | undefined = _query;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.list(query, opts).withResponse();
return finalResponse(result);
}

async cancel(
fineTuningJobId: string,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.cancel(fineTuningJobId, opts).withResponse();
return finalResponse(result);
}

async listEvents(
fineTuningJobId: string,
_query?: JobListEventsParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const query: JobListEventsParams | undefined = _query;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.listEvents(fineTuningJobId, query, opts).withResponse();
return finalResponse(result);
}
}

export class Checkpoints extends ApiResource {
async list(
fineTuningJobId: string,
_query?: CheckpointListParams,
params?: ApiClientInterface,
opts?: RequestOptions
): Promise<any> {
const query: CheckpointListParams | undefined = _query;
if (params) {
const config = overrideConfig(this.client.config, params.config);
this.client.customHeaders = {
...this.client.customHeaders,
...createHeaders({ ...params, config }),
};
}

const OAIclient = new OpenAI({
apiKey: OPEN_AI_API_KEY,
baseURL: this.client.baseURL,
defaultHeaders: defaultHeadersBuilder(this.client),
});

const result = await OAIclient.fineTuning.jobs.checkpoints.list(fineTuningJobId, query, opts).withResponse();
return finalResponse(result);
}
}
1 change: 1 addition & 0 deletions src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export { Threads } from "./threads";
export { MainFiles } from "./files";
export { Models } from "./models";
export { Batches } from "./batches";
export { FineTuning } from "./fineTuning"
export { VectorStores } from "./vectorStores"
export { BetaChat } from "./betaChat"
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export class Portkey extends ApiClient {
prompts = new API.Prompt(this);
feedback = new API.Feedback(this);
batches = new API.Batches(this);
fineTuning = new API.FineTuning(this);
beta = {
assistants: new API.Assistants(this),
threads: new API.Threads(this),
Expand Down

0 comments on commit 0dd8306

Please sign in to comment.