Skip to content

Commit 9cdfe7a

Browse files
authored
migrate to /v5/transcription (#1358)
## Description migrate to /v5/transcription * no functionality or UI changes ## Reviewer Instructions test with allenai/olmo-api#505 api version ## Testing Plan Ran existing tests and manually tested for regressions
1 parent bdbe09a commit 9cdfe7a

6 files changed

Lines changed: 135 additions & 35 deletions

File tree

src/api/playgroundApi/v5playgroundApiSchema.ts

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ export type paths = {
211211
patch?: never;
212212
trace?: never;
213213
};
214+
'/v5/transcription/': {
215+
parameters: {
216+
query?: never;
217+
header?: never;
218+
path?: never;
219+
cookie?: never;
220+
};
221+
get?: never;
222+
put?: never;
223+
/** Transcribe */
224+
post: operations['transcribe_v5_transcription__post'];
225+
delete?: never;
226+
options?: never;
227+
head?: never;
228+
patch?: never;
229+
trace?: never;
230+
};
214231
'/v5/admin/models/': {
215232
parameters: {
216233
query?: never;
@@ -327,6 +344,14 @@ export type components = {
327344
/** Description */
328345
description?: string | null;
329346
};
347+
/** Body_transcribe_v5_transcription__post */
348+
Body_transcribe_v5_transcription__post: {
349+
/**
350+
* Audio
351+
* Format: binary
352+
*/
353+
audio: string;
354+
};
330355
/** CreateMultiModalModelConfigRequest */
331356
CreateMultiModalModelConfigRequest: {
332357
/** Name */
@@ -1228,6 +1253,11 @@ export type components = {
12281253
/** Nestedspans */
12291254
nestedSpans?: components['schemas']['ResponseAttributionSpan'][];
12301255
};
1256+
/** TranscriptionSingleResponse */
1257+
TranscriptionSingleResponse: {
1258+
/** Text */
1259+
text: string;
1260+
};
12311261
/** UpdateMultiModalModelConfigRequest */
12321262
UpdateMultiModalModelConfigRequest: {
12331263
/** Name */
@@ -1479,6 +1509,8 @@ export type SchemaAttributionResponse = components['schemas']['AttributionRespon
14791509
export type SchemaAuthenticatedClient = components['schemas']['AuthenticatedClient'];
14801510
export type SchemaAvailableInfiniGramIndexId = components['schemas']['AvailableInfiniGramIndexId'];
14811511
export type SchemaAvailableTool = components['schemas']['AvailableTool'];
1512+
export type SchemaBodyTranscribeV5TranscriptionPost =
1513+
components['schemas']['Body_transcribe_v5_transcription__post'];
14821514
export type SchemaCreateMultiModalModelConfigRequest =
14831515
components['schemas']['CreateMultiModalModelConfigRequest'];
14841516
export type SchemaCreateTextOnlyModelConfigRequest =
@@ -1530,6 +1562,8 @@ export type SchemaToolCall = components['schemas']['ToolCall'];
15301562
export type SchemaToolDefinition = components['schemas']['ToolDefinition'];
15311563
export type SchemaToolSource = components['schemas']['ToolSource'];
15321564
export type SchemaTopLevelAttributionSpan = components['schemas']['TopLevelAttributionSpan'];
1565+
export type SchemaTranscriptionSingleResponse =
1566+
components['schemas']['TranscriptionSingleResponse'];
15331567
export type SchemaUpdateMultiModalModelConfigRequest =
15341568
components['schemas']['UpdateMultiModalModelConfigRequest'];
15351569
export type SchemaUpdateTextOnlyModelConfigRequest =
@@ -2162,6 +2196,57 @@ export interface operations {
21622196
};
21632197
};
21642198
};
2199+
transcribe_v5_transcription__post: {
2200+
parameters: {
2201+
query?: never;
2202+
header?: never;
2203+
path?: never;
2204+
cookie?: never;
2205+
};
2206+
requestBody: {
2207+
content: {
2208+
'multipart/form-data': components['schemas']['Body_transcribe_v5_transcription__post'];
2209+
};
2210+
};
2211+
responses: {
2212+
/** @description Successful Response */
2213+
200: {
2214+
headers: {
2215+
[name: string]: unknown;
2216+
};
2217+
content: {
2218+
'application/json': components['schemas']['TranscriptionSingleResponse'];
2219+
};
2220+
};
2221+
/** @description Validation Error */
2222+
422: {
2223+
headers: {
2224+
[name: string]: unknown;
2225+
};
2226+
content: {
2227+
'application/problem+json': components['schemas']['HTTPValidationError'];
2228+
};
2229+
};
2230+
/** @description Client Error */
2231+
'4XX': {
2232+
headers: {
2233+
[name: string]: unknown;
2234+
};
2235+
content: {
2236+
'application/problem+json': components['schemas']['Problem'];
2237+
};
2238+
};
2239+
/** @description Server Error */
2240+
'5XX': {
2241+
headers: {
2242+
[name: string]: unknown;
2243+
};
2244+
content: {
2245+
'application/problem+json': components['schemas']['Problem'];
2246+
};
2247+
};
2248+
};
2249+
};
21652250
get_admin_models_v5_admin_models__get: {
21662251
parameters: {
21672252
query?: never;

src/components/thread/QueryForm/AudioTranscription/AudioInputButton.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { AlertMessageSeverity, errorToAlert, SnackMessageType } from '@/slices/S
88
import { PromptButton } from '../PromptButton';
99
import { AcceptOrCancelButtons } from './AcceptOrCancelButtons';
1010
import { DotIndicator } from './DotIndicator';
11-
import { handleTranscribe } from './handleTranscribe';
1211
import { useAudioRecording } from './useAudioRecording';
12+
import { usePostTranscription } from './usePostTranscription';
1313

1414
const iconClassName = css({
1515
transform: 'translateY(1px)', // Microphone looks odd sitting higher than the camera icon
@@ -37,6 +37,7 @@ export const AudioInputButton = ({
3737
const { isTranscribing, addSnackMessage, isProcessingAudio, setIsProcessingAudio } =
3838
useAppContext();
3939
const { startRecording, stopRecording } = useAudioRecording();
40+
const transcribe = usePostTranscription();
4041

4142
const cancelRecording = () => {
4243
stopRecording('userCancel');
@@ -77,7 +78,7 @@ export const AudioInputButton = ({
7778
try {
7879
onRecordingEnd?.();
7980
onTranscriptionBegin?.();
80-
const { text } = await handleTranscribe(data);
81+
const { text } = await transcribe(data);
8182
onTranscriptionComplete?.(text);
8283
onComplete?.(text);
8384
} catch (error: unknown) {

src/components/thread/QueryForm/AudioTranscription/handleTranscribe.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { apiQueryClient } from '@/api/playgroundApi/v5';
2+
3+
export const usePostTranscription = () => {
4+
const { mutateAsync } = apiQueryClient.useMutation('post', '/v5/transcription/');
5+
6+
return async (audioData: Blob) => {
7+
const fileName = `recording.${new Date().toISOString()}.${audioData.type.split('/')[1]}`;
8+
const file = new File([audioData], fileName);
9+
10+
const data = await mutateAsync(
11+
{
12+
body: {
13+
audio: fileName, // this prop is required here, but ignored/replaced by bodySerializer()
14+
},
15+
bodySerializer: () => {
16+
const fd = new FormData();
17+
fd.append('audio', file);
18+
return fd;
19+
},
20+
},
21+
{
22+
onError: (error) => {
23+
console.error('Transcription error', error);
24+
},
25+
}
26+
);
27+
28+
return data;
29+
};
30+
};

src/mocks/handlers/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,20 @@ import { messageHandlers } from './messageHandlers';
66
import { messageStreamHandlers } from './messageStreamHandlers';
77
import { datasetDocumentResponse } from './responses/datasetDocumentResponse';
88
import { datasetSearchResponse } from './responses/datasetSearchResponse';
9-
import { v4ModelsHandlers } from './v4ModelsHandlers';
10-
import { v4PromptTemplatesHandlers } from './v4PromptTemplatesHandlers';
11-
import { v4TranscriptionHandlers } from './v4TranscriptionHandlers';
129
import { v5AttributionHandlers } from './v5AttributionHandlers';
1310
import { v5ModelsHandlers } from './v5ModelsHandlers';
1411
import { v5PromptTemplatesHandlers } from './v5PromptTemplatesHandlers';
1512
import { v5ThreadHandlers } from './v5ThreadHandlers';
13+
import { v5TranscriptionHandlers } from './v5TranscriptionHandlers';
1614

1715
export const handlers = [
1816
...messageStreamHandlers,
19-
...v5AttributionHandlers,
2017
...messageHandlers,
18+
19+
...v5AttributionHandlers,
2120
...v5ThreadHandlers,
22-
...v4ModelsHandlers,
23-
...v4TranscriptionHandlers,
24-
...v4PromptTemplatesHandlers,
2521
...v5ModelsHandlers,
22+
...v5TranscriptionHandlers,
2623
...v5PromptTemplatesHandlers,
2724

2825
http.get(`${process.env.VITE_API_URL}${WhoamiApiUrl}`, () => {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { SchemaTranscriptionSingleResponse } from '@/api/playgroundApi/v5playgroundApiSchema';
2+
3+
import { v5TypedHttp } from './v5TypedHttp';
4+
5+
const fakeTranscriptionResponse = {
6+
text: 'Hello world',
7+
} satisfies SchemaTranscriptionSingleResponse;
8+
9+
const v5TranscriptionHandler = v5TypedHttp.post('/v5/transcription/', ({ response }) => {
10+
return response(200).json(fakeTranscriptionResponse);
11+
});
12+
13+
export const v5TranscriptionHandlers = [v5TranscriptionHandler];

0 commit comments

Comments
 (0)