From 0680c8d5dba060ff4d396a45c63b9d0fad8d101c Mon Sep 17 00:00:00 2001 From: Stainless Bot Date: Fri, 27 Sep 2024 15:56:50 +0000 Subject: [PATCH 1/3] fix(client): correct types for transcriptions / translations --- .stats.yml | 2 +- api.md | 10 ++- src/resources/audio/audio.ts | 6 ++ src/resources/audio/index.ts | 18 +++- src/resources/audio/transcriptions.ts | 118 +++++++++++++++++++++++++- src/resources/audio/translations.ts | 32 ++++++- 6 files changed, 179 insertions(+), 7 deletions(-) diff --git a/.stats.yml b/.stats.yml index 0998368a4..68789976b 100644 --- a/.stats.yml +++ b/.stats.yml @@ -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 diff --git a/api.md b/api.md index 73ac38068..71027acfd 100644 --- a/api.md +++ b/api.md @@ -115,20 +115,26 @@ Types: Types: - Transcription +- TranscriptionSegment +- TranscriptionVerbose +- TranscriptionWord +- TranscriptionCreateResponse Methods: -- client.audio.transcriptions.create({ ...params }) -> Transcription +- client.audio.transcriptions.create({ ...params }) -> TranscriptionCreateResponse ## Translations Types: - Translation +- TranslationVerbose +- TranslationCreateResponse Methods: -- client.audio.translations.create({ ...params }) -> Translation +- client.audio.translations.create({ ...params }) -> TranslationCreateResponse ## Speech diff --git a/src/resources/audio/audio.ts b/src/resources/audio/audio.ts index a8b35d986..9c2c2b982 100644 --- a/src/resources/audio/audio.ts +++ b/src/resources/audio/audio.ts @@ -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; diff --git a/src/resources/audio/index.ts b/src/resources/audio/index.ts index e8836470c..952c05b03 100644 --- a/src/resources/audio/index.ts +++ b/src/resources/audio/index.ts @@ -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'; diff --git a/src/resources/audio/transcriptions.ts b/src/resources/audio/transcriptions.ts index 1ee6921cd..e68e2dba7 100644 --- a/src/resources/audio/transcriptions.ts +++ b/src/resources/audio/transcriptions.ts @@ -9,7 +9,10 @@ export class Transcriptions extends APIResource { /** * Transcribes audio into the input language. */ - create(body: TranscriptionCreateParams, options?: Core.RequestOptions): Core.APIPromise { + create( + body: TranscriptionCreateParams, + options?: Core.RequestOptions, + ): Core.APIPromise { return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ body, ...options })); } } @@ -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; +} + +/** + * 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; + + /** + * Extracted words and their corresponding timestamps. + */ + words?: Array; +} + +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: @@ -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; } diff --git a/src/resources/audio/translations.ts b/src/resources/audio/translations.ts index 6df718112..dd70df12a 100644 --- a/src/resources/audio/translations.ts +++ b/src/resources/audio/translations.ts @@ -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 { + create( + body: TranslationCreateParams, + options?: Core.RequestOptions, + ): Core.APIPromise { return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ body, ...options })); } } @@ -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; +} + +export type TranslationCreateResponse = Translation | TranslationVerbose; + export interface TranslationCreateParams { /** * The audio file object (not file name) translate, in one of these formats: flac, @@ -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; } From d5896b3de616d10e41ad9ec72238602a2d620647 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Fri, 27 Sep 2024 17:09:16 -0400 Subject: [PATCH 2/3] fix: correct types for audio responses --- src/resources/audio/transcriptions.ts | 20 +++++++++++++++++--- src/resources/audio/translations.ts | 17 ++++++++++++++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/resources/audio/transcriptions.ts b/src/resources/audio/transcriptions.ts index e68e2dba7..5c47258c5 100644 --- a/src/resources/audio/transcriptions.ts +++ b/src/resources/audio/transcriptions.ts @@ -9,10 +9,22 @@ export class Transcriptions extends APIResource { /** * Transcribes audio into the input language. */ + create( + body: TranscriptionCreateParams<'json'>, + options?: Core.RequestOptions, + ): Core.APIPromise; + create( + body: TranscriptionCreateParams<'verbose_json'>, + options?: Core.RequestOptions, + ): Core.APIPromise; + create( + body: TranscriptionCreateParams<'srt' | 'vtt' | 'text'>, + options?: Core.RequestOptions, + ): Core.APIPromise; create( body: TranscriptionCreateParams, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.APIPromise { return this._client.post('/audio/transcriptions', Core.multipartFormRequestOptions({ body, ...options })); } } @@ -137,7 +149,9 @@ export interface TranscriptionWord { */ export type TranscriptionCreateResponse = Transcription | TranscriptionVerbose; -export interface TranscriptionCreateParams { +export interface TranscriptionCreateParams< + ResponseFormat extends AudioAPI.AudioResponseFormat = AudioAPI.AudioResponseFormat, +> { /** * The audio file object (not file name) to transcribe, in one of these formats: * flac, mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. @@ -169,7 +183,7 @@ export interface TranscriptionCreateParams { * The format of the output, in one of these options: `json`, `text`, `srt`, * `verbose_json`, or `vtt`. */ - response_format?: AudioAPI.AudioResponseFormat; + response_format?: ResponseFormat; /** * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the diff --git a/src/resources/audio/translations.ts b/src/resources/audio/translations.ts index dd70df12a..d0f9fad83 100644 --- a/src/resources/audio/translations.ts +++ b/src/resources/audio/translations.ts @@ -10,10 +10,19 @@ export class Translations extends APIResource { /** * Translates audio into English. */ + create(body: TranslationCreateParams<'json'>, options?: Core.RequestOptions): Core.APIPromise; + create( + body: TranslationCreateParams<'verbose_json'>, + options?: Core.RequestOptions, + ): Core.APIPromise; + create( + body: TranslationCreateParams<'text' | 'srt' | 'vtt'>, + options?: Core.RequestOptions, + ): Core.APIPromise; create( body: TranslationCreateParams, options?: Core.RequestOptions, - ): Core.APIPromise { + ): Core.APIPromise { return this._client.post('/audio/translations', Core.multipartFormRequestOptions({ body, ...options })); } } @@ -46,7 +55,9 @@ export interface TranslationVerbose { export type TranslationCreateResponse = Translation | TranslationVerbose; -export interface TranslationCreateParams { +export interface TranslationCreateParams< + ResponseFormat extends AudioAPI.AudioResponseFormat = AudioAPI.AudioResponseFormat, +> { /** * The audio file object (not file name) translate, in one of these formats: flac, * mp3, mp4, mpeg, mpga, m4a, ogg, wav, or webm. @@ -71,7 +82,7 @@ export interface TranslationCreateParams { * The format of the output, in one of these options: `json`, `text`, `srt`, * `verbose_json`, or `vtt`. */ - response_format?: AudioAPI.AudioResponseFormat; + response_format?: ResponseFormat; /** * The sampling temperature, between 0 and 1. Higher values like 0.8 will make the From de25ac3124605840474a772522c6b7c75089a860 Mon Sep 17 00:00:00 2001 From: Robert Craigie Date: Fri, 27 Sep 2024 18:22:16 -0400 Subject: [PATCH 3/3] add undefined --- src/resources/audio/transcriptions.ts | 4 ++-- src/resources/audio/translations.ts | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/resources/audio/transcriptions.ts b/src/resources/audio/transcriptions.ts index 5c47258c5..e230bc4a4 100644 --- a/src/resources/audio/transcriptions.ts +++ b/src/resources/audio/transcriptions.ts @@ -10,7 +10,7 @@ export class Transcriptions extends APIResource { * Transcribes audio into the input language. */ create( - body: TranscriptionCreateParams<'json'>, + body: TranscriptionCreateParams<'json' | undefined>, options?: Core.RequestOptions, ): Core.APIPromise; create( @@ -150,7 +150,7 @@ export interface TranscriptionWord { export type TranscriptionCreateResponse = Transcription | TranscriptionVerbose; export interface TranscriptionCreateParams< - ResponseFormat extends AudioAPI.AudioResponseFormat = AudioAPI.AudioResponseFormat, + ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined, > { /** * The audio file object (not file name) to transcribe, in one of these formats: diff --git a/src/resources/audio/translations.ts b/src/resources/audio/translations.ts index d0f9fad83..819804332 100644 --- a/src/resources/audio/translations.ts +++ b/src/resources/audio/translations.ts @@ -10,7 +10,10 @@ export class Translations extends APIResource { /** * Translates audio into English. */ - create(body: TranslationCreateParams<'json'>, options?: Core.RequestOptions): Core.APIPromise; + create( + body: TranslationCreateParams<'json' | undefined>, + options?: Core.RequestOptions, + ): Core.APIPromise; create( body: TranslationCreateParams<'verbose_json'>, options?: Core.RequestOptions, @@ -56,7 +59,7 @@ export interface TranslationVerbose { export type TranslationCreateResponse = Translation | TranslationVerbose; export interface TranslationCreateParams< - ResponseFormat extends AudioAPI.AudioResponseFormat = AudioAPI.AudioResponseFormat, + ResponseFormat extends AudioAPI.AudioResponseFormat | undefined = AudioAPI.AudioResponseFormat | undefined, > { /** * The audio file object (not file name) translate, in one of these formats: flac,