-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
72481d9
commit 2005aca
Showing
3 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { ApiClientInterface } from "../_types/generalTypes"; | ||
import { ApiResource } from "../apiResource"; | ||
import { RequestOptions } from "../baseClient"; | ||
import { OPEN_AI_API_KEY, PORTKEY_DEV_BASE_URL } from "../constants"; | ||
import { overrideConfig } from "../utils"; | ||
import { createHeaders } from "./createHeaders"; | ||
import OpenAI from "openai"; | ||
|
||
export class MainFiles extends ApiResource { | ||
|
||
async create( | ||
_body: FileCreateParams, | ||
params?: ApiClientInterface, | ||
opts?: RequestOptions | ||
): Promise<FileObject> { | ||
const body: FileCreateParams = _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: PORTKEY_DEV_BASE_URL, | ||
defaultHeaders: this.client.customHeaders, | ||
}); | ||
|
||
const result = await OAIclient.files.create(body, opts); | ||
return result; | ||
} | ||
|
||
async list( | ||
_query: FileListParams, | ||
params?: ApiClientInterface, | ||
opts?: RequestOptions | ||
): Promise<any> { | ||
const query: FileListParams = _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: PORTKEY_DEV_BASE_URL, | ||
defaultHeaders: this.client.customHeaders, | ||
}); | ||
|
||
const result = await OAIclient.files.list(query, opts); | ||
return result; | ||
} | ||
|
||
async retrieve( | ||
fileId: 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: PORTKEY_DEV_BASE_URL, | ||
defaultHeaders: this.client.customHeaders, | ||
}); | ||
|
||
const result = await OAIclient.files.retrieve(fileId, opts); | ||
return result; | ||
} | ||
|
||
async del( | ||
fileId: 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: PORTKEY_DEV_BASE_URL, | ||
defaultHeaders: this.client.customHeaders, | ||
}); | ||
|
||
const result = await OAIclient.files.del(fileId, opts); | ||
return result; | ||
} | ||
|
||
async retrieveContent( | ||
fileId: 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: PORTKEY_DEV_BASE_URL, | ||
defaultHeaders: this.client.customHeaders, | ||
}); | ||
|
||
const result = await OAIclient.files.content(fileId, opts); | ||
return result; | ||
} | ||
|
||
} | ||
|
||
|
||
export interface FileCreateParams { | ||
file: any; | ||
purpose: 'fine-tune' | 'assistants'; | ||
} | ||
|
||
export interface FileObject { | ||
id: string; | ||
bytes: number; | ||
created_at: number; | ||
filename: string; | ||
object: 'file'; | ||
purpose: 'fine-tune' | 'fine-tune-results' | 'assistants' | 'assistants_output'; | ||
status: 'uploaded' | 'processed' | 'error'; | ||
status_details?: string; | ||
} | ||
|
||
export interface FileListParams { | ||
purpose?: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters