Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 16
configured_endpoints: 17
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/togetherai%2FTogetherAI-87bcc1e47f49a52fc31601e87d387cf7ef17f50fba0a06aa105a7fcc65644de4.yml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This library provides convenient access to the Together REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found on [docs.together.ai](https://docs.together.ai). The full API of this library can be found in [api.md](api.md).
The REST API documentation can be found on [docs.together.ai](https://docs.together.ai/). The full API of this library can be found in [api.md](api.md).

It is generated with [Stainless](https://www.stainlessapi.com/).

Expand Down
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ Methods:

- <code title="post /images/generations">client.images.<a href="./src/resources/images.ts">create</a>({ ...params }) -> ImageFile</code>

# Audio

Types:

- <code><a href="./src/resources/audio.ts">AudioFile</a></code>

Methods:

- <code title="post /audio/speech">client.audio.<a href="./src/resources/audio.ts">create</a>({ ...params }) -> Response</code>

# Models

Types:
Expand Down
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as Uploads from './uploads';
import * as API from './resources/index';
import * as TopLevelAPI from './resources/top-level';
import { RerankParams, RerankResponse } from './resources/top-level';
import { Audio, AudioCreateParams, AudioFile } from './resources/audio';
import {
Completion,
CompletionCreateParams,
Expand Down Expand Up @@ -157,6 +158,7 @@ export class Together extends Core.APIClient {
files: API.Files = new API.Files(this);
fineTune: API.FineTuneResource = new API.FineTuneResource(this);
images: API.Images = new API.Images(this);
audio: API.Audio = new API.Audio(this);
models: API.Models = new API.Models(this);

/**
Expand Down Expand Up @@ -211,6 +213,7 @@ Together.Embeddings = Embeddings;
Together.Files = Files;
Together.FineTuneResource = FineTuneResource;
Together.Images = Images;
Together.Audio = Audio;
Together.Models = Models;
export declare namespace Together {
export type RequestOptions = Core.RequestOptions;
Expand Down Expand Up @@ -256,6 +259,8 @@ export declare namespace Together {

export { Images as Images, type ImageFile as ImageFile, type ImageCreateParams as ImageCreateParams };

export { Audio as Audio, type AudioFile as AudioFile, type AudioCreateParams as AudioCreateParams };

export { Models as Models, type ModelListResponse as ModelListResponse };
}

Expand Down
110 changes: 110 additions & 0 deletions src/resources/audio.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../resource';
import * as Core from '../core';
import { type Response } from '../_shims/index';

export class Audio extends APIResource {
/**
* Generate audio from input text
*/
create(body: AudioCreateParams, options?: Core.RequestOptions): Core.APIPromise<Response> {
return this._client.post('/audio/speech', {
body,
...options,
headers: { Accept: 'application/octet-stream', ...options?.headers },
__binaryResponse: true,
});
}
}

export type AudioFile = AudioFile.AudioSpeechStreamEvent | AudioFile.StreamSentinel;

export namespace AudioFile {
export interface AudioSpeechStreamEvent {
data: AudioSpeechStreamEvent.Data;
}

export namespace AudioSpeechStreamEvent {
export interface Data {
/**
* base64 encoded audio stream
*/
b64: string;

model: string;

object: 'audio.tts.chunk';
}
}

export interface StreamSentinel {
data: '[DONE]';
}
}

export interface AudioCreateParams {
/**
* Input text to generate the audio for
*/
input: string;

/**
* The name of the model to query.
*
* [See all of Together AI's chat models](https://docs.together.ai/docs/serverless-models#audio-models)
*/
model: 'cartesia/sonic' | (string & {});

/**
* The voice to use for generating the audio.
* [View all supported voices here](https://docs.together.ai/docs/text-to-speech#voices-available).
*/
voice: 'laidback woman' | 'polite man' | 'storyteller lady' | 'friendly sidekick' | (string & {});

/**
* Language of input text
*/
language?:
| 'en'
| 'de'
| 'fr'
| 'es'
| 'hi'
| 'it'
| 'ja'
| 'ko'
| 'nl'
| 'pl'
| 'pt'
| 'ru'
| 'sv'
| 'tr'
| 'zh';

/**
* Audio encoding of response
*/
response_encoding?: 'pcm_f32le' | 'pcm_s16le' | 'pcm_mulaw' | 'pcm_alaw';

/**
* The format of audio output
*/
response_format?: 'mp3' | 'wav' | 'raw';

/**
* Sampling rate to use for the output audio
*/
sample_rate?: number;

/**
* If true, output is streamed for several characters at a time instead of waiting
* for the full response. The stream terminates with `data: [DONE]`. If false,
* return the encoded audio as octet stream
*/
stream?: boolean;
}

export declare namespace Audio {
export { type AudioFile as AudioFile, type AudioCreateParams as AudioCreateParams };
}
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { Audio, type AudioFile, type AudioCreateParams } from './audio';
export { Chat } from './chat/chat';
export {
Completions,
Expand Down
23 changes: 23 additions & 0 deletions tests/api-resources/audio.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import Together from 'together-ai';

const client = new Together({
apiKey: 'My API Key',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource audio', () => {
test('create: required and optional params', async () => {
const response = await client.audio.create({
input: 'input',
model: 'cartesia/sonic',
voice: 'laidback woman',
language: 'en',
response_encoding: 'pcm_f32le',
response_format: 'mp3',
sample_rate: 0,
stream: true,
});
});
});