Skip to content

Commit 21d4b00

Browse files
feat(api): manual updates
add /uploads endpoint
1 parent 29305a4 commit 21d4b00

File tree

7 files changed

+389
-4
lines changed

7 files changed

+389
-4
lines changed

.stats.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 4
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/meta%2Fllama-api-bfa0267b010dcc4b39e62dfbd698ac6f9421f3212c44b3408b9b154bd6c67a8b.yml
3-
openapi_spec_hash: 7f424537bc7ea7638e3934ef721b8d71
4-
config_hash: fd80f72884b7fef46327f3fb70dcb1c4
1+
configured_endpoints: 7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/meta%2Fllama-api-edf0a308dd29bea2feb29f2e7f04eec4dbfb130ffe52511641783958168f60a4.yml
3+
openapi_spec_hash: 23af966c58151516aaef00e0af602c01
4+
config_hash: 431a8aed31c3576451a36d2db8f48c25

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,35 @@ const createChatCompletionResponse: LlamaAPIClient.CreateChatCompletionResponse
7878

7979
Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
8080

81+
## File uploads
82+
83+
Request parameters that correspond to file uploads can be passed in many different forms:
84+
85+
- `File` (or an object with the same structure)
86+
- a `fetch` `Response` (or an object with the same structure)
87+
- an `fs.ReadStream`
88+
- the return value of our `toFile` helper
89+
90+
```ts
91+
import fs from 'fs';
92+
import LlamaAPIClient, { toFile } from 'llama-api-client';
93+
94+
const client = new LlamaAPIClient();
95+
96+
// If you have access to Node `fs` we recommend using `fs.createReadStream()`:
97+
await client.uploads.part('upload_id', { data: fs.createReadStream('/path/to/file') });
98+
99+
// Or if you have the web `File` API you can pass a `File` instance:
100+
await client.uploads.part('upload_id', { data: new File(['my bytes'], 'file') });
101+
102+
// You can also pass a `fetch` `Response`:
103+
await client.uploads.part('upload_id', { data: await fetch('https://somesite/file') });
104+
105+
// Finally, if none of the above are convenient, you can use our `toFile` helper:
106+
await client.uploads.part('upload_id', { data: await toFile(Buffer.from('my bytes'), 'file') });
107+
await client.uploads.part('upload_id', { data: await toFile(new Uint8Array([0, 1, 2]), 'file') });
108+
```
109+
81110
## Handling errors
82111

83112
When the library is unable to connect to the API,

api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ Methods:
3030
- <code title="get /models/{model}">client.models.<a href="./src/resources/models.ts">retrieve</a>(model) -> LlamaModel</code>
3131
- <code title="get /models">client.models.<a href="./src/resources/models.ts">list</a>() -> ModelListResponse</code>
3232

33+
# Uploads
34+
35+
Types:
36+
37+
- <code><a href="./src/resources/uploads.ts">UploadCreateResponse</a></code>
38+
- <code><a href="./src/resources/uploads.ts">UploadGetResponse</a></code>
39+
- <code><a href="./src/resources/uploads.ts">UploadPartResponse</a></code>
40+
41+
Methods:
42+
43+
- <code title="post /uploads">client.uploads.<a href="./src/resources/uploads.ts">create</a>({ ...params }) -> UploadCreateResponse</code>
44+
- <code title="get /uploads/{upload_id}">client.uploads.<a href="./src/resources/uploads.ts">get</a>(uploadID, { ...params }) -> UploadGetResponse</code>
45+
- <code title="post /uploads/{upload_id}">client.uploads.<a href="./src/resources/uploads.ts">part</a>(uploadID, { ...params }) -> UploadPartResponse</code>
46+
3347
# Moderations
3448

3549
Types:

src/client.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ import * as API from './resources/index';
1818
import { APIPromise } from './core/api-promise';
1919
import { LlamaModel, ModelListResponse, Models } from './resources/models';
2020
import { ModerationCreateParams, ModerationCreateResponse, Moderations } from './resources/moderations';
21+
import {
22+
UploadCreateParams,
23+
UploadCreateResponse,
24+
UploadGetParams,
25+
UploadGetResponse,
26+
UploadPartParams,
27+
UploadPartResponse,
28+
Uploads as UploadsAPIUploads,
29+
} from './resources/uploads';
2130
import {
2231
Chat,
2332
CompletionMessage,
@@ -729,11 +738,13 @@ export class LlamaAPIClient {
729738

730739
chat: API.Chat = new API.Chat(this);
731740
models: API.Models = new API.Models(this);
741+
uploads: API.Uploads = new API.Uploads(this);
732742
moderations: API.Moderations = new API.Moderations(this);
733743
}
734744

735745
LlamaAPIClient.Chat = Chat;
736746
LlamaAPIClient.Models = Models;
747+
LlamaAPIClient.Uploads = UploadsAPIUploads;
737748
LlamaAPIClient.Moderations = Moderations;
738749

739750
export declare namespace LlamaAPIClient {
@@ -754,6 +765,16 @@ export declare namespace LlamaAPIClient {
754765

755766
export { Models as Models, type LlamaModel as LlamaModel, type ModelListResponse as ModelListResponse };
756767

768+
export {
769+
UploadsAPIUploads as Uploads,
770+
type UploadCreateResponse as UploadCreateResponse,
771+
type UploadGetResponse as UploadGetResponse,
772+
type UploadPartResponse as UploadPartResponse,
773+
type UploadCreateParams as UploadCreateParams,
774+
type UploadGetParams as UploadGetParams,
775+
type UploadPartParams as UploadPartParams,
776+
};
777+
757778
export {
758779
Moderations as Moderations,
759780
type ModerationCreateResponse as ModerationCreateResponse,

src/resources/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,12 @@ export {
1414
} from './chat/chat';
1515
export { Models, type LlamaModel, type ModelListResponse } from './models';
1616
export { Moderations, type ModerationCreateResponse, type ModerationCreateParams } from './moderations';
17+
export {
18+
Uploads,
19+
type UploadCreateResponse,
20+
type UploadGetResponse,
21+
type UploadPartResponse,
22+
type UploadCreateParams,
23+
type UploadGetParams,
24+
type UploadPartParams,
25+
} from './uploads';

src/resources/uploads.ts

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2+
3+
import { APIResource } from '../core/resource';
4+
import { APIPromise } from '../core/api-promise';
5+
import { type Uploadable } from '../core/uploads';
6+
import { buildHeaders } from '../internal/headers';
7+
import { RequestOptions } from '../internal/request-options';
8+
import { multipartFormRequestOptions } from '../internal/uploads';
9+
import { path } from '../internal/utils/path';
10+
11+
export class Uploads extends APIResource {
12+
/**
13+
* Initiate an upload session with specified file metadata
14+
*/
15+
create(params: UploadCreateParams, options?: RequestOptions): APIPromise<UploadCreateResponse> {
16+
const { 'X-API-Version': xAPIVersion, ...body } = params;
17+
return this._client.post('/uploads', {
18+
body,
19+
...options,
20+
headers: buildHeaders([
21+
{ ...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined) },
22+
options?.headers,
23+
]),
24+
});
25+
}
26+
27+
/**
28+
* Get the status of the given upload session
29+
*/
30+
get(
31+
uploadID: string,
32+
params: UploadGetParams | null | undefined = {},
33+
options?: RequestOptions,
34+
): APIPromise<UploadGetResponse> {
35+
const { 'X-API-Version': xAPIVersion } = params ?? {};
36+
return this._client.get(path`/uploads/${uploadID}`, {
37+
...options,
38+
headers: buildHeaders([
39+
{ ...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined) },
40+
options?.headers,
41+
]),
42+
});
43+
}
44+
45+
/**
46+
* Upload a chunk of bytes to the upload session
47+
*/
48+
part(uploadID: string, params: UploadPartParams, options?: RequestOptions): APIPromise<UploadPartResponse> {
49+
const { 'X-API-Version': xAPIVersion, 'X-Upload-Offset': xUploadOffset, ...body } = params;
50+
return this._client.post(
51+
path`/uploads/${uploadID}`,
52+
multipartFormRequestOptions(
53+
{
54+
body,
55+
...options,
56+
headers: buildHeaders([
57+
{
58+
...(xAPIVersion?.toString() != null ? { 'X-API-Version': xAPIVersion?.toString() } : undefined),
59+
...(xUploadOffset?.toString() != null ?
60+
{ 'X-Upload-Offset': xUploadOffset?.toString() }
61+
: undefined),
62+
},
63+
options?.headers,
64+
]),
65+
},
66+
this._client,
67+
),
68+
);
69+
}
70+
}
71+
72+
export interface UploadCreateResponse {
73+
/**
74+
* The unique upload session identifier to use for uploading the file
75+
*/
76+
id: string;
77+
78+
/**
79+
* The number of bytes in the file you are uploading
80+
*/
81+
bytes: number;
82+
83+
/**
84+
* The name of the file to upload
85+
*/
86+
filename: string;
87+
88+
/**
89+
* The MIME type of the file. Must be one of the supported MIME type for the given
90+
* purpose.
91+
*/
92+
mime_type:
93+
| 'image/jpeg'
94+
| 'image/jpg'
95+
| 'image/png'
96+
| 'image/gif'
97+
| 'image/webp'
98+
| 'image/x-icon'
99+
| 'audio/mp3'
100+
| 'audio/mpeg'
101+
| 'audio/wav'
102+
| 'audio/x-wav'
103+
| 'application/jsonl'
104+
| 'application/json'
105+
| 'text/plain'
106+
| 'video/mp4'
107+
| 'application/pdf';
108+
109+
/**
110+
* Intended purpose of the uploaded file.
111+
*/
112+
purpose:
113+
| 'attachment'
114+
| 'ephemeral_attachment'
115+
| 'image_generation_result'
116+
| 'messages_finetune'
117+
| 'messages_eval'
118+
| 'metadata';
119+
}
120+
121+
export interface UploadGetResponse {
122+
/**
123+
* The unique upload session identifier to use for uploading the file
124+
*/
125+
upload_id: string;
126+
127+
/**
128+
* This is a zero-based numeric index of byte number in which the current upload
129+
* session to be resuming upload from
130+
*/
131+
offset?: number;
132+
}
133+
134+
export interface UploadPartResponse {
135+
/**
136+
* The unique upload session identifier to use for uploading the file
137+
*/
138+
upload_id: string;
139+
140+
/**
141+
* The ready file identifier after the upload is complete
142+
*/
143+
file_id?: string;
144+
145+
/**
146+
* This is a zero-based numeric index of byte number in which the current upload
147+
* session to be resuming upload from
148+
*/
149+
offset?: number;
150+
}
151+
152+
export interface UploadCreateParams {
153+
/**
154+
* Body param: The number of bytes in the file you are uploading
155+
*/
156+
bytes: number;
157+
158+
/**
159+
* Body param: The name of the file to upload
160+
*/
161+
filename: string;
162+
163+
/**
164+
* Body param: The MIME type of the file. Must be one of the supported MIME type
165+
* for the given purpose.
166+
*/
167+
mime_type:
168+
| 'image/jpeg'
169+
| 'image/jpg'
170+
| 'image/png'
171+
| 'image/gif'
172+
| 'image/webp'
173+
| 'image/x-icon'
174+
| 'audio/mp3'
175+
| 'audio/mpeg'
176+
| 'audio/wav'
177+
| 'audio/x-wav'
178+
| 'application/jsonl'
179+
| 'application/json'
180+
| 'text/plain'
181+
| 'video/mp4'
182+
| 'application/pdf';
183+
184+
/**
185+
* Body param: Intended purpose of the uploaded file.
186+
*/
187+
purpose:
188+
| 'attachment'
189+
| 'ephemeral_attachment'
190+
| 'image_generation_result'
191+
| 'messages_finetune'
192+
| 'messages_eval'
193+
| 'metadata';
194+
195+
/**
196+
* Header param:
197+
*/
198+
'X-API-Version'?: '1.0.0';
199+
}
200+
201+
export interface UploadGetParams {
202+
'X-API-Version'?: '1.0.0';
203+
}
204+
205+
export interface UploadPartParams {
206+
/**
207+
* Body param: The chunk of bytes to upload
208+
*/
209+
data: Uploadable;
210+
211+
/**
212+
* Header param:
213+
*/
214+
'X-API-Version'?: '1.0.0';
215+
216+
/**
217+
* Header param: The offset of the chunk of bytes to upload for the upload session
218+
*/
219+
'X-Upload-Offset'?: number;
220+
}
221+
222+
export declare namespace Uploads {
223+
export {
224+
type UploadCreateResponse as UploadCreateResponse,
225+
type UploadGetResponse as UploadGetResponse,
226+
type UploadPartResponse as UploadPartResponse,
227+
type UploadCreateParams as UploadCreateParams,
228+
type UploadGetParams as UploadGetParams,
229+
type UploadPartParams as UploadPartParams,
230+
};
231+
}

0 commit comments

Comments
 (0)