-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
index.ts
114 lines (105 loc) Β· 3.44 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { OpenAIClient, type ClientOptions } from "@langchain/openai";
import { Serializable } from "@langchain/core/load/serializable";
export type OpenAIFilesInput = {
client?: OpenAIClient;
clientOptions?: ClientOptions;
};
export class OpenAIFiles extends Serializable {
lc_namespace = ["langchain", "experimental"];
private oaiClient: OpenAIClient;
constructor(fields?: OpenAIFilesInput) {
super(fields);
this.oaiClient = fields?.client ?? new OpenAIClient(fields?.clientOptions);
}
/**
* Upload file
* Upload a file that can be used across various endpoints. The size of all the files uploaded by one organization can be up to 100 GB.
*
* @note The size of individual files can be a maximum of 512 MB. See the Assistants Tools guide to learn more about the types of files supported. The Fine-tuning API only supports .jsonl files.
*
* @link {https://platform.openai.com/docs/api-reference/files/create}
* @param {OpenAIClient.FileCreateParams['file']} file
* @param {OpenAIClient.FileCreateParams['purpose']} purpose
* @param {OpenAIClient.RequestOptions | undefined} options
* @returns {Promise<OpenAIClient.Files.FileObject>}
*/
async createFile({
file,
purpose,
options,
}: OpenAIClient.FileCreateParams & {
options?: OpenAIClient.RequestOptions;
}) {
return this.oaiClient.files.create({ file, purpose }, options);
}
/**
* Delete a file.
*
* @link {https://platform.openai.com/docs/api-reference/files/delete}
* @param {string} fileId
* @param {OpenAIClient.RequestOptions | undefined} options
* @returns {Promise<OpenAIClient.Files.FileDeleted>}
*/
async deleteFile({
fileId,
options,
}: {
fileId: string;
options?: OpenAIClient.RequestOptions;
}) {
return this.oaiClient.files.del(fileId, options);
}
/**
* List files
* Returns a list of files that belong to the user's organization.
*
* @link {https://platform.openai.com/docs/api-reference/files/list}
* @param {OpenAIClient.Files.FileListParams | undefined} query
* @param {OpenAIClient.RequestOptions | undefined} options
* @returns {Promise<OpenAIClient.Files.FileObjectsPage>}
*/
async listFiles(props?: {
query?: OpenAIClient.Files.FileListParams;
options?: OpenAIClient.RequestOptions;
}) {
return this.oaiClient.files.list(props?.query, props?.options);
}
/**
* Retrieve file
* Returns information about a specific file.
*
* @link {https://platform.openai.com/docs/api-reference/files/retrieve}
* @param {string} fileId
* @param {OpenAIClient.RequestOptions | undefined} options
* @returns {Promise<OpenAIClient.Files.FileObject>}
*/
async retrieveFile({
fileId,
options,
}: {
fileId: string;
options?: OpenAIClient.RequestOptions;
}) {
return this.oaiClient.files.retrieve(fileId, options);
}
/**
* Retrieve file content
* Returns the contents of the specified file.
*
* @note You can't retrieve the contents of a file that was uploaded with the "purpose": "assistants" API.
*
* @link {https://platform.openai.com/docs/api-reference/files/retrieve-contents}
* @param {string} fileId
* @param {OpenAIClient.RequestOptions | undefined} options
* @returns {Promise<string>}
*/
async retrieveFileContent({
fileId,
options,
}: {
fileId: string;
options?: OpenAIClient.RequestOptions;
}) {
return this.oaiClient.files.retrieveContent(fileId, options);
}
}