@ai-sdk/google 4.0.0-beta.83 → 4.0.0-beta.84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +23 -1
- package/dist/index.js +21 -3
- package/dist/index.js.map +1 -1
- package/docs/15-google.mdx +39 -0
- package/package.json +1 -1
- package/src/index.ts +4 -0
- package/src/realtime/google-realtime-event-mapper.ts +30 -2
- package/src/realtime/google-realtime-model-options.ts +21 -1
- package/src/realtime/index.ts +4 -0
package/docs/15-google.mdx
CHANGED
|
@@ -1091,6 +1091,45 @@ Google realtime models may require provider-specific audio formats, depending
|
|
|
1091
1091
|
on the model and modality. See [Realtime](/docs/ai-sdk-core/realtime) for the
|
|
1092
1092
|
complete setup and tool calling pattern.
|
|
1093
1093
|
|
|
1094
|
+
### Live Translation
|
|
1095
|
+
|
|
1096
|
+
Use `gemini-3.5-live-translate-preview` for low-latency speech-to-speech
|
|
1097
|
+
translation. Configure the target language with
|
|
1098
|
+
`providerOptions.google.translationConfig` in the realtime session config you
|
|
1099
|
+
use when creating the token:
|
|
1100
|
+
|
|
1101
|
+
```ts
|
|
1102
|
+
import {
|
|
1103
|
+
google,
|
|
1104
|
+
type Experimental_GoogleRealtimeModelOptions as GoogleRealtimeModelOptions,
|
|
1105
|
+
} from '@ai-sdk/google';
|
|
1106
|
+
|
|
1107
|
+
const token = await google.experimental_realtime.getToken({
|
|
1108
|
+
model: 'gemini-3.5-live-translate-preview',
|
|
1109
|
+
sessionConfig: {
|
|
1110
|
+
outputModalities: ['audio'],
|
|
1111
|
+
inputAudioTranscription: {},
|
|
1112
|
+
outputAudioTranscription: {},
|
|
1113
|
+
providerOptions: {
|
|
1114
|
+
google: {
|
|
1115
|
+
translationConfig: {
|
|
1116
|
+
targetLanguageCode: 'pl',
|
|
1117
|
+
echoTargetLanguage: true,
|
|
1118
|
+
},
|
|
1119
|
+
} satisfies GoogleRealtimeModelOptions,
|
|
1120
|
+
},
|
|
1121
|
+
},
|
|
1122
|
+
});
|
|
1123
|
+
```
|
|
1124
|
+
|
|
1125
|
+
Set `targetLanguageCode` to a BCP-47 language code (defaults to `en`). When
|
|
1126
|
+
`echoTargetLanguage` is `true`, input audio already in the target language is
|
|
1127
|
+
echoed instead of producing silence.
|
|
1128
|
+
|
|
1129
|
+
Gemini Live Translation accepts audio input and produces translated audio
|
|
1130
|
+
output. Text input, tools, and custom instructions are not supported by this
|
|
1131
|
+
model.
|
|
1132
|
+
|
|
1094
1133
|
## Interactions API
|
|
1095
1134
|
|
|
1096
1135
|
The [Gemini Interactions API](https://ai.google.dev/gemini-api/docs/interactions)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -56,5 +56,9 @@ export type {
|
|
|
56
56
|
} from './google-provider';
|
|
57
57
|
export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel } from './realtime/google-realtime-model';
|
|
58
58
|
export type { GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig } from './realtime/google-realtime-model';
|
|
59
|
+
export type {
|
|
60
|
+
GoogleRealtimeModelId as Experimental_GoogleRealtimeModelId,
|
|
61
|
+
GoogleRealtimeModelOptions as Experimental_GoogleRealtimeModelOptions,
|
|
62
|
+
} from './realtime/google-realtime-model-options';
|
|
59
63
|
|
|
60
64
|
export { VERSION } from './version';
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
import { safeParseJSON } from '@ai-sdk/provider-utils';
|
|
9
9
|
import { convertJSONSchemaToOpenAPISchema } from '../convert-json-schema-to-openapi-schema';
|
|
10
10
|
import { getModelPath } from '../get-model-path';
|
|
11
|
+
import type { GoogleRealtimeModelOptions } from './google-realtime-model-options';
|
|
11
12
|
|
|
12
13
|
type GoogleRealtimeFunctionCall = {
|
|
13
14
|
id: string;
|
|
@@ -38,6 +39,10 @@ type GoogleRealtimeWireEvent = {
|
|
|
38
39
|
inputTranscription?: { text?: string };
|
|
39
40
|
};
|
|
40
41
|
|
|
42
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
43
|
+
return value != null && typeof value === 'object' && !Array.isArray(value);
|
|
44
|
+
}
|
|
45
|
+
|
|
41
46
|
/**
|
|
42
47
|
* Stateful event mapper for Google's Gemini Live API.
|
|
43
48
|
*
|
|
@@ -268,6 +273,12 @@ export class GoogleRealtimeEventMapper {
|
|
|
268
273
|
};
|
|
269
274
|
|
|
270
275
|
case 'input-audio-commit':
|
|
276
|
+
return {
|
|
277
|
+
realtimeInput: {
|
|
278
|
+
audioStreamEnd: true,
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
|
|
271
282
|
case 'input-audio-clear':
|
|
272
283
|
case 'response-create':
|
|
273
284
|
case 'response-cancel':
|
|
@@ -375,8 +386,25 @@ export function buildGoogleSessionConfig(
|
|
|
375
386
|
setup.outputAudioTranscription = {};
|
|
376
387
|
}
|
|
377
388
|
|
|
378
|
-
if (config?.providerOptions
|
|
379
|
-
|
|
389
|
+
if (config?.providerOptions == null) {
|
|
390
|
+
return setup;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
const { google, ...providerOptions } = config.providerOptions;
|
|
394
|
+
Object.assign(setup, providerOptions);
|
|
395
|
+
|
|
396
|
+
const googleOptions = isRecord(google)
|
|
397
|
+
? (google as GoogleRealtimeModelOptions)
|
|
398
|
+
: undefined;
|
|
399
|
+
|
|
400
|
+
if (googleOptions?.translationConfig != null) {
|
|
401
|
+
const target = isRecord(setup.generationConfig)
|
|
402
|
+
? setup.generationConfig
|
|
403
|
+
: generationConfig;
|
|
404
|
+
setup.generationConfig = {
|
|
405
|
+
...target,
|
|
406
|
+
translationConfig: googleOptions.translationConfig,
|
|
407
|
+
};
|
|
380
408
|
}
|
|
381
409
|
|
|
382
410
|
return setup;
|
|
@@ -1,3 +1,23 @@
|
|
|
1
1
|
export type GoogleRealtimeModelId = string;
|
|
2
2
|
|
|
3
|
-
export type GoogleRealtimeModelOptions =
|
|
3
|
+
export type GoogleRealtimeModelOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Gemini Live Translation configuration.
|
|
6
|
+
*
|
|
7
|
+
* Required for `gemini-3.5-live-translate-preview` when translating speech
|
|
8
|
+
* to a target language.
|
|
9
|
+
*/
|
|
10
|
+
translationConfig?: {
|
|
11
|
+
/**
|
|
12
|
+
* BCP-47 language code of the language to translate into.
|
|
13
|
+
* Defaults to `en` in the Gemini API.
|
|
14
|
+
*/
|
|
15
|
+
targetLanguageCode?: string;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Whether input audio already in the target language should be echoed
|
|
19
|
+
* instead of producing silence.
|
|
20
|
+
*/
|
|
21
|
+
echoTargetLanguage?: boolean;
|
|
22
|
+
};
|
|
23
|
+
};
|
package/src/realtime/index.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
export { GoogleRealtimeModel as Experimental_GoogleRealtimeModel } from './google-realtime-model';
|
|
2
2
|
export type { GoogleRealtimeModelConfig as Experimental_GoogleRealtimeModelConfig } from './google-realtime-model';
|
|
3
|
+
export type {
|
|
4
|
+
GoogleRealtimeModelId as Experimental_GoogleRealtimeModelId,
|
|
5
|
+
GoogleRealtimeModelOptions as Experimental_GoogleRealtimeModelOptions,
|
|
6
|
+
} from './google-realtime-model-options';
|