Skip to content

Commit 6131ee8

Browse files
amirai21asafgardin
authored andcommitted
feat: add upload file object override
1 parent 329eb3e commit 6131ee8

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/APIClient.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ const validatePositiveInteger = (name: string, n: unknown): number => {
3030
const appendBodyToFormData = (formData: FormData, body: Record<string, any>): void => {
3131
for (const [key, value] of Object.entries(body)) {
3232
if (Array.isArray(value)) {
33-
value.forEach(item => formData.append(key, item));
33+
value.forEach((item) => formData.append(key, item));
3434
} else {
3535
formData.append(key, value);
3636
}
3737
}
38-
}
38+
};
3939

40-
export type FilePathOrFileObject =
41-
| string
42-
| File;
40+
export type FilePathOrFileObject = string | File;
4341

4442
function makeFormDataFromFilePath(filePath: string): FormData {
4543
const formData = new FormData();
@@ -97,7 +95,6 @@ export abstract class APIClient {
9795
upload<Req, Rsp>(path: string, file: string, opts?: RequestOptions<Req>): Promise<Rsp>;
9896
upload<Req, Rsp>(path: string, file: File, opts?: RequestOptions<Req>): Promise<Rsp>;
9997

100-
10198
upload<Req, Rsp>(path: string, file: FilePathOrFileObject, opts?: RequestOptions<Req>): Promise<Rsp> {
10299
let formData: FormData;
103100

@@ -113,10 +110,10 @@ export abstract class APIClient {
113110
// eslint-disable-next-line @typescript-eslint/no-explicit-any
114111
appendBodyToFormData(formData, opts.body as Record<string, any>);
115112
}
116-
113+
117114
const headers = {
118115
...opts?.headers,
119-
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`
116+
'Content-Type': `multipart/form-data; boundary=${formData.getBoundary()}`,
120117
};
121118

122119
const options: FinalRequestOptions = {
@@ -126,9 +123,7 @@ export abstract class APIClient {
126123
headers,
127124
};
128125

129-
return this.performRequest(options).then(
130-
(response) => this.fetch.handleResponse<Rsp>(response) as Rsp,
131-
);
126+
return this.performRequest(options).then((response) => this.fetch.handleResponse<Rsp>(response) as Rsp);
132127
}
133128

134129
protected makeFormDataRequest<Req>(
@@ -194,7 +189,7 @@ export abstract class APIClient {
194189
const options = {
195190
method,
196191
path,
197-
192+
198193
...opts,
199194
};
200195

src/resources/chat/completions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class Completions extends APIResource {
2424
{
2525
body,
2626
...options,
27-
stream: body.stream ?? false,
27+
stream: body.stream ?? false,
2828
} as Models.RequestOptions<Models.ChatCompletionCreateParams>,
2929
) as Promise<Models.ChatCompletionResponse> | Promise<Stream<Models.ChatCompletionChunk>>;
3030
}

src/resources/rag/ragEngine.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { FileResponse } from 'types/rag/FileResponse';
66
const RAG_ENGINE_PATH = '/library/files';
77

88
export class RAGEngine extends APIResource {
9-
create(filePath: string, body: UploadFileRequest, options?: Models.RequestOptions): Promise<UploadFileResponse> {
9+
create(
10+
filePath: string,
11+
body: UploadFileRequest,
12+
options?: Models.RequestOptions,
13+
): Promise<UploadFileResponse> {
1014
return this.client.upload<UploadFileRequest, UploadFileResponse>(RAG_ENGINE_PATH, filePath, {
1115
body: body,
1216
...options,

0 commit comments

Comments
 (0)