Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): correct types for transcriptions / translations #1105

Merged
merged 1 commit into from
Sep 27, 2024
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: 68
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-17ddd746c775ca4d4fbe64e5621ac30756ef09c061ff6313190b6ec162222d4c.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/openai-71e58a77027c67e003fdd1b1ac8ac11557d8bfabc7666d1a827c6b1ca8ab98b5.yml
10 changes: 8 additions & 2 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,26 @@ Types:
Types:

- <code><a href="./src/resources/audio/transcriptions.ts">Transcription</a></code>
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionSegment</a></code>
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionVerbose</a></code>
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionWord</a></code>
- <code><a href="./src/resources/audio/transcriptions.ts">TranscriptionCreateResponse</a></code>

Methods:

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

## Translations

Types:

- <code><a href="./src/resources/audio/translations.ts">Translation</a></code>
- <code><a href="./src/resources/audio/translations.ts">TranslationVerbose</a></code>
- <code><a href="./src/resources/audio/translations.ts">TranslationCreateResponse</a></code>

Methods:

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

## Speech

Expand Down
6 changes: 6 additions & 0 deletions src/resources/audio/audio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,15 @@ export namespace Audio {
export import AudioResponseFormat = AudioAPI.AudioResponseFormat;
export import Transcriptions = TranscriptionsAPI.Transcriptions;
export import Transcription = TranscriptionsAPI.Transcription;
export import TranscriptionSegment = TranscriptionsAPI.TranscriptionSegment;
export import TranscriptionVerbose = TranscriptionsAPI.TranscriptionVerbose;
export import TranscriptionWord = TranscriptionsAPI.TranscriptionWord;
export import TranscriptionCreateResponse = TranscriptionsAPI.TranscriptionCreateResponse;
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
export import Translations = TranslationsAPI.Translations;
export import Translation = TranslationsAPI.Translation;
export import TranslationVerbose = TranslationsAPI.TranslationVerbose;
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
export import Speech = SpeechAPI.Speech;
export import SpeechModel = SpeechAPI.SpeechModel;
Expand Down
18 changes: 16 additions & 2 deletions src/resources/audio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,19 @@

export { AudioModel, AudioResponseFormat, Audio } from './audio';
export { SpeechModel, SpeechCreateParams, Speech } from './speech';
export { Transcription, TranscriptionCreateParams, Transcriptions } from './transcriptions';
export { Translation, TranslationCreateParams, Translations } from './translations';
export {
Transcription,
TranscriptionSegment,
TranscriptionVerbose,
TranscriptionWord,
TranscriptionCreateResponse,
TranscriptionCreateParams,
Transcriptions,
} from './transcriptions';
export {
Translation,
TranslationVerbose,
TranslationCreateResponse,
TranslationCreateParams,
Translations,
} from './translations';
118 changes: 117 additions & 1 deletion src/resources/audio/transcriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ export class Transcriptions extends APIResource {
/**
* Transcribes audio into the input language.
*/
create(body: TranscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise<Transcription> {
create(
body: TranscriptionCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<TranscriptionCreateResponse> {
return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ body, ...options }));
}
}
Expand All @@ -25,6 +28,115 @@ export interface Transcription {
text: string;
}

export interface TranscriptionSegment {
/**
* Unique identifier of the segment.
*/
id: number;

/**
* Average logprob of the segment. If the value is lower than -1, consider the
* logprobs failed.
*/
avg_logprob: number;

/**
* Compression ratio of the segment. If the value is greater than 2.4, consider the
* compression failed.
*/
compression_ratio: number;

/**
* End time of the segment in seconds.
*/
end: number;

/**
* Probability of no speech in the segment. If the value is higher than 1.0 and the
* `avg_logprob` is below -1, consider this segment silent.
*/
no_speech_prob: number;

/**
* Seek offset of the segment.
*/
seek: number;

/**
* Start time of the segment in seconds.
*/
start: number;

/**
* Temperature parameter used for generating the segment.
*/
temperature: number;

/**
* Text content of the segment.
*/
text: string;

/**
* Array of token IDs for the text content.
*/
tokens: Array<number>;
}

/**
* Represents a verbose json transcription response returned by model, based on the
* provided input.
*/
export interface TranscriptionVerbose {
/**
* The duration of the input audio.
*/
duration: string;

/**
* The language of the input audio.
*/
language: string;

/**
* The transcribed text.
*/
text: string;

/**
* Segments of the transcribed text and their corresponding details.
*/
segments?: Array<TranscriptionSegment>;

/**
* Extracted words and their corresponding timestamps.
*/
words?: Array<TranscriptionWord>;
}

export interface TranscriptionWord {
/**
* End time of the word in seconds.
*/
end: number;

/**
* Start time of the word in seconds.
*/
start: number;

/**
* The text content of the word.
*/
word: string;
}

/**
* Represents a transcription response returned by model, based on the provided
* input.
*/
export type TranscriptionCreateResponse = Transcription | TranscriptionVerbose;

export interface TranscriptionCreateParams {
/**
* The audio file object (not file name) to transcribe, in one of these formats:
Expand Down Expand Up @@ -80,5 +192,9 @@ export interface TranscriptionCreateParams {

export namespace Transcriptions {
export import Transcription = TranscriptionsAPI.Transcription;
export import TranscriptionSegment = TranscriptionsAPI.TranscriptionSegment;
export import TranscriptionVerbose = TranscriptionsAPI.TranscriptionVerbose;
export import TranscriptionWord = TranscriptionsAPI.TranscriptionWord;
export import TranscriptionCreateResponse = TranscriptionsAPI.TranscriptionCreateResponse;
export import TranscriptionCreateParams = TranscriptionsAPI.TranscriptionCreateParams;
}
32 changes: 31 additions & 1 deletion src/resources/audio/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as TranslationsAPI from './translations';
import * as AudioAPI from './audio';
import * as TranscriptionsAPI from './transcriptions';

export class Translations extends APIResource {
/**
* Translates audio into English.
*/
create(body: TranslationCreateParams, options?: Core.RequestOptions): Core.APIPromise<Translation> {
create(
body: TranslationCreateParams,
options?: Core.RequestOptions,
): Core.APIPromise<TranslationCreateResponse> {
return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ body, ...options }));
}
}
Expand All @@ -18,6 +22,30 @@ export interface Translation {
text: string;
}

export interface TranslationVerbose {
/**
* The duration of the input audio.
*/
duration: string;

/**
* The language of the output translation (always `english`).
*/
language: string;

/**
* The translated text.
*/
text: string;

/**
* Segments of the translated text and their corresponding details.
*/
segments?: Array<TranscriptionsAPI.TranscriptionSegment>;
}

export type TranslationCreateResponse = Translation | TranslationVerbose;

export interface TranslationCreateParams {
/**
* The audio file object (not file name) translate, in one of these formats: flac,
Expand Down Expand Up @@ -57,5 +85,7 @@ export interface TranslationCreateParams {

export namespace Translations {
export import Translation = TranslationsAPI.Translation;
export import TranslationVerbose = TranslationsAPI.TranslationVerbose;
export import TranslationCreateResponse = TranslationsAPI.TranslationCreateResponse;
export import TranslationCreateParams = TranslationsAPI.TranslationCreateParams;
}