Skip to content

Commit e3bdd28

Browse files
docs: add examples to tsdocs
1 parent 328ac07 commit e3bdd28

File tree

11 files changed

+137
-0
lines changed

11 files changed

+137
-0
lines changed

src/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ export class Together extends Core.APIClient {
184184

185185
/**
186186
* Query a reranker model
187+
*
188+
* @example
189+
* ```ts
190+
* const response = await client.rerank({
191+
* documents: [
192+
* { title: 'bar', text: 'bar' },
193+
* { title: 'bar', text: 'bar' },
194+
* { title: 'bar', text: 'bar' },
195+
* { title: 'bar', text: 'bar' },
196+
* ],
197+
* model: 'Salesforce/Llama-Rank-V1',
198+
* query: 'What animals can I find near Peru?',
199+
* });
200+
* ```
187201
*/
188202
rerank(
189203
body: TopLevelAPI.RerankParams,

src/resources/audio.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ import { type Response } from '../_shims/index';
77
export class Audio extends APIResource {
88
/**
99
* Generate audio from input text
10+
*
11+
* @example
12+
* ```ts
13+
* const audio = await client.audio.create({
14+
* input: 'input',
15+
* model: 'cartesia/sonic',
16+
* voice: 'laidback woman',
17+
* });
18+
*
19+
* const content = await audio.blob();
20+
* console.log(content);
21+
* ```
1022
*/
1123
create(body: AudioCreateParams, options?: Core.RequestOptions): Core.APIPromise<Response> {
1224
return this._client.post('/audio/speech', {

src/resources/chat/completions.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ import { ChatCompletionStream, ChatCompletionStreamParams } from 'together-ai/li
1111
export class Completions extends APIResource {
1212
/**
1313
* Query a chat model.
14+
*
15+
* @example
16+
* ```ts
17+
* const chatCompletion = await client.chat.completions.create(
18+
* {
19+
* messages: [{ content: 'string', role: 'system' }],
20+
* model: 'meta-llama/Meta-Llama-3.1-8B-Instruct-Turbo',
21+
* },
22+
* );
23+
* ```
1424
*/
1525
create(body: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<ChatCompletion>;
1626
create(

src/resources/code-interpreter/code-interpreter.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ export class CodeInterpreter extends APIResource {
1414
* session_id, the code will be run in that session. This is useful for running
1515
* multiple code snippets in the same environment, because dependencies and similar
1616
* things are persisted between calls to the same session.
17+
*
18+
* @example
19+
* ```ts
20+
* const executeResponse =
21+
* await client.codeInterpreter.execute({
22+
* code: "print('Hello, world!')",
23+
* language: 'python',
24+
* });
25+
* ```
1726
*/
1827
execute(
1928
body: CodeInterpreterExecuteParams,

src/resources/code-interpreter/sessions.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import * as Core from '../../core';
66
export class Sessions extends APIResource {
77
/**
88
* Lists all your currently active sessions.
9+
*
10+
* @example
11+
* ```ts
12+
* const sessionListResponse =
13+
* await client.codeInterpreter.sessions.list();
14+
* ```
915
*/
1016
list(options?: Core.RequestOptions): Core.APIPromise<SessionListResponse> {
1117
return this._client.get('/tci/sessions', options);

src/resources/completions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import { Stream } from '../streaming';
1010
export class Completions extends APIResource {
1111
/**
1212
* Query a language, code, or image model.
13+
*
14+
* @example
15+
* ```ts
16+
* const completion = await client.completions.create({
17+
* model: 'mistralai/Mixtral-8x7B-Instruct-v0.1',
18+
* prompt:
19+
* '<s>[INST] What is the capital of France? [/INST]',
20+
* });
21+
* ```
1322
*/
1423
create(body: CompletionCreateParamsNonStreaming, options?: Core.RequestOptions): APIPromise<Completion>;
1524
create(

src/resources/embeddings.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,15 @@ import * as Core from '../core';
66
export class Embeddings extends APIResource {
77
/**
88
* Query an embedding model for a given string of text.
9+
*
10+
* @example
11+
* ```ts
12+
* const embedding = await client.embeddings.create({
13+
* input:
14+
* 'Our solar system orbits the Milky Way galaxy at about 515,000 mph',
15+
* model: 'togethercomputer/m2-bert-80M-8k-retrieval',
16+
* });
17+
* ```
918
*/
1019
create(body: EmbeddingCreateParams, options?: Core.RequestOptions): Core.APIPromise<Embedding> {
1120
return this._client.post('/embeddings', { body, ...options });

src/resources/endpoints.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ export class Endpoints extends APIResource {
99
* Creates a new dedicated endpoint for serving models. The endpoint will
1010
* automatically start after creation. You can deploy any supported model on
1111
* hardware configurations that meet the model's requirements.
12+
*
13+
* @example
14+
* ```ts
15+
* const endpoint = await client.endpoints.create({
16+
* autoscaling: { max_replicas: 5, min_replicas: 2 },
17+
* hardware: '1x_nvidia_a100_80gb_sxm',
18+
* model: 'meta-llama/Llama-3-8b-chat-hf',
19+
* });
20+
* ```
1221
*/
1322
create(body: EndpointCreateParams, options?: Core.RequestOptions): Core.APIPromise<EndpointCreateResponse> {
1423
return this._client.post('/endpoints', { body, ...options });
@@ -17,6 +26,13 @@ export class Endpoints extends APIResource {
1726
/**
1827
* Retrieves details about a specific endpoint, including its current state,
1928
* configuration, and scaling settings.
29+
*
30+
* @example
31+
* ```ts
32+
* const endpoint = await client.endpoints.retrieve(
33+
* 'endpoint-d23901de-ef8f-44bf-b3e7-de9c1ca8f2d7',
34+
* );
35+
* ```
2036
*/
2137
retrieve(endpointId: string, options?: Core.RequestOptions): Core.APIPromise<EndpointRetrieveResponse> {
2238
return this._client.get(`/endpoints/${endpointId}`, options);
@@ -25,6 +41,13 @@ export class Endpoints extends APIResource {
2541
/**
2642
* Updates an existing endpoint's configuration. You can modify the display name,
2743
* autoscaling settings, or change the endpoint's state (start/stop).
44+
*
45+
* @example
46+
* ```ts
47+
* const endpoint = await client.endpoints.update(
48+
* 'endpoint-d23901de-ef8f-44bf-b3e7-de9c1ca8f2d7',
49+
* );
50+
* ```
2851
*/
2952
update(
3053
endpointId: string,
@@ -37,6 +60,11 @@ export class Endpoints extends APIResource {
3760
/**
3861
* Returns a list of all endpoints associated with your account. You can filter the
3962
* results by type (dedicated or serverless).
63+
*
64+
* @example
65+
* ```ts
66+
* const endpoints = await client.endpoints.list();
67+
* ```
4068
*/
4169
list(query?: EndpointListParams, options?: Core.RequestOptions): Core.APIPromise<EndpointListResponse>;
4270
list(options?: Core.RequestOptions): Core.APIPromise<EndpointListResponse>;
@@ -52,6 +80,13 @@ export class Endpoints extends APIResource {
5280

5381
/**
5482
* Permanently deletes an endpoint. This action cannot be undone.
83+
*
84+
* @example
85+
* ```ts
86+
* await client.endpoints.delete(
87+
* 'endpoint-d23901de-ef8f-44bf-b3e7-de9c1ca8f2d7',
88+
* );
89+
* ```
5590
*/
5691
delete(endpointId: string, options?: Core.RequestOptions): Core.APIPromise<void> {
5792
return this._client.delete(`/endpoints/${endpointId}`, {

src/resources/images.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ import * as Core from '../core';
66
export class Images extends APIResource {
77
/**
88
* Use an image model to generate an image for a given prompt.
9+
*
10+
* @example
11+
* ```ts
12+
* const imageFile = await client.images.create({
13+
* model: 'black-forest-labs/FLUX.1-schnell',
14+
* prompt: 'cat floating in space, cinematic',
15+
* });
16+
* ```
917
*/
1018
create(body: ImageCreateParams, options?: Core.RequestOptions): Core.APIPromise<ImageFile> {
1119
return this._client.post('/images/generations', { body, ...options });

src/resources/jobs.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,25 @@ import * as Core from '../core';
66
export class Jobs extends APIResource {
77
/**
88
* Get the status of a specific job
9+
*
10+
* @example
11+
* ```ts
12+
* const job = await client.jobs.retrieve(
13+
* 'job-a15dad11-8d8e-4007-97c5-a211304de284',
14+
* );
15+
* ```
916
*/
1017
retrieve(jobId: string, options?: Core.RequestOptions): Core.APIPromise<JobRetrieveResponse> {
1118
return this._client.get(`/jobs/${jobId}`, options);
1219
}
1320

1421
/**
1522
* List all jobs and their statuses
23+
*
24+
* @example
25+
* ```ts
26+
* const jobs = await client.jobs.list();
27+
* ```
1628
*/
1729
list(options?: Core.RequestOptions): Core.APIPromise<JobListResponse> {
1830
return this._client.get('/jobs', options);

src/resources/models.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,26 @@ import * as Core from '../core';
66
export class Models extends APIResource {
77
/**
88
* Lists all of Together's open-source models
9+
*
10+
* @example
11+
* ```ts
12+
* const models = await client.models.list();
13+
* ```
914
*/
1015
list(options?: Core.RequestOptions): Core.APIPromise<ModelListResponse> {
1116
return this._client.get('/models', options);
1217
}
1318

1419
/**
1520
* Upload a custom model from Hugging Face or S3
21+
*
22+
* @example
23+
* ```ts
24+
* const response = await client.models.upload({
25+
* model_name: 'Qwen2.5-72B-Instruct',
26+
* model_source: 'unsloth/Qwen2.5-72B-Instruct',
27+
* });
28+
* ```
1629
*/
1730
upload(body: ModelUploadParams, options?: Core.RequestOptions): Core.APIPromise<ModelUploadResponse> {
1831
return this._client.post('/models', { body, ...options });

0 commit comments

Comments
 (0)