Skip to content

Commit 5252a40

Browse files
committed
Fix mediaChunks errors
1 parent 080342a commit 5252a40

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

packages/ai/integration/live.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
LiveServerContent,
2424
LiveServerToolCall,
2525
LiveServerToolCallCancellation,
26-
ResponseModality,
26+
ResponseModality
2727
} from '../src';
2828
import { liveTestConfigs } from './constants';
2929
import { HELLO_AUDIO_PCM_BASE64 } from './sample-data/hello-audio';
@@ -177,12 +177,6 @@ describe('Live', function () {
177177
});
178178

179179
it('should send multiple audio chunks in a single batch call', async () => {
180-
// Sending more than one mediaChunk in a message to Google AI results in the server
181-
// closing the WebSocket connection with 'Request Contains an Invalid Argument.'.
182-
// Skip this test for Google AI.
183-
if (testConfig.ai.backend.backendType === BackendType.GOOGLE_AI) {
184-
return;
185-
}
186180
const model = getLiveGenerativeModel(testConfig.ai, {
187181
model: testConfig.model,
188182
generationConfig: textLiveGenerationConfig
@@ -241,7 +235,7 @@ describe('Live', function () {
241235
* These tests are currently very unreliable. Their behavior seems to change frequently.
242236
* Skipping them for now.
243237
*/
244-
/**
238+
/*
245239
describe('function calling', () => {
246240
// When this tests runs against the Google AI backend, the first message we get back
247241
// has an `executableCode` part, and then

packages/ai/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"test:browser": "yarn testsetup && karma start",
4242
"test:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha --require ts-node/register --require src/index.node.ts 'src/**/*.test.ts' --config ../../config/mocharc.node.js",
4343
"test:integration": "karma start --integration",
44-
"test:integration:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha integration/live.test.ts --config ../../config/mocharc.node.js",
44+
"test:integration:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha integration/**/*.test.ts --config ../../config/mocharc.node.js",
4545
"api-report": "api-extractor run --local --verbose",
4646
"typings:public": "node ../../scripts/build/use_typings.js ./dist/ai-public.d.ts",
4747
"trusted-type-check": "tsec -p tsconfig.json --noEmit"

packages/ai/src/methods/live-session.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,14 @@ export class LiveSession {
101101
);
102102
}
103103

104-
const message: _LiveClientRealtimeInput = {
105-
realtimeInput: { mediaChunks }
106-
};
107-
this.webSocketHandler.send(JSON.stringify(message));
104+
// The backend does not support sending more than one mediaChunk in one message.
105+
// Work around this limitation by sending mediaChunks in separate messages.
106+
mediaChunks.forEach(mediaChunk => {
107+
const message: _LiveClientRealtimeInput = {
108+
realtimeInput: { mediaChunks: [mediaChunk] }
109+
};
110+
this.webSocketHandler.send(JSON.stringify(message));
111+
});
108112
}
109113

110114
/**

0 commit comments

Comments
 (0)