Skip to content

Commit 651e23e

Browse files
committed
Review comments
1 parent 451c7b7 commit 651e23e

File tree

12 files changed

+84
-93
lines changed

12 files changed

+84
-93
lines changed

common/api-review/ai.api.md

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -705,35 +705,6 @@ export class IntegerSchema extends Schema {
705705
constructor(schemaParams?: SchemaParams);
706706
}
707707

708-
// @internal
709-
export interface _LiveClientContent {
710-
// (undocumented)
711-
clientContent: {
712-
turns: [Content];
713-
turnComplete: boolean;
714-
};
715-
}
716-
717-
// @internal
718-
export interface _LiveClientRealtimeInput {
719-
// (undocumented)
720-
realtimeInput: {
721-
mediaChunks: GenerativeContentBlob[];
722-
};
723-
}
724-
725-
// @internal
726-
export interface _LiveClientSetup {
727-
// (undocumented)
728-
setup: {
729-
model: string;
730-
generationConfig?: LiveGenerationConfig;
731-
tools?: Tool[];
732-
toolConfig?: ToolConfig;
733-
systemInstruction?: string | Part | Content;
734-
};
735-
}
736-
737708
// @beta
738709
export interface LiveGenerationConfig {
739710
candidateCount?: number;

docs-devsite/ai.functioncall.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface FunctionCall
2323
| Property | Type | Description |
2424
| --- | --- | --- |
2525
| [args](./ai.functioncall.md#functioncallargs) | object | |
26-
| [id](./ai.functioncall.md#functioncallid) | string | The id of the function call. This must be sent back in the associated [FunctionResponse](./ai.functionresponse.md#functionresponse_interface)<!-- -->.<!-- -->This property is only supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property will be <code>undefined</code>. |
26+
| [id](./ai.functioncall.md#functioncallid) | string | The id of the function call. This must be sent back in the associated [FunctionResponse](./ai.functionresponse.md#functionresponse_interface)<!-- -->. |
2727
| [name](./ai.functioncall.md#functioncallname) | string | |
2828

2929
## FunctionCall.args

docs-devsite/ai.functionresponse.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export interface FunctionResponse
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [id](./ai.functionresponse.md#functionresponseid) | string | The id of the [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->.<!-- -->This property is only supported in the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->). When using the Gemini Developer API ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->), this property will be <code>undefined</code>. |
25+
| [id](./ai.functionresponse.md#functionresponseid) | string | The id of the [FunctionCall](./ai.functioncall.md#functioncall_interface)<!-- -->. |
2626
| [name](./ai.functionresponse.md#functionresponsename) | string | |
2727
| [response](./ai.functionresponse.md#functionresponseresponse) | object | |
2828

docs-devsite/ai.livegenerativemodel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://github.com/firebase/firebase-js-sdk
1515
1616
Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal interactions with Gemini.
1717

18-
Do not call this class' constructor directly. Instead, call [getLiveGenerativeModel()](./ai.md#getlivegenerativemodel_f2099ac)<!-- -->.
18+
This class should only be instantiated with [getLiveGenerativeModel()](./ai.md#getlivegenerativemodel_f2099ac)<!-- -->.
1919

2020
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `LiveGenerativeModel` class.
2121

docs-devsite/ai.livesession.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://github.com/firebase/firebase-js-sdk
1515
1616
Represents an active, real-time, bidirectional conversation with the model.
1717

18-
Do not call this constructor directly. Instead, call [LiveGenerativeModel.connect()](./ai.livegenerativemodel.md#livegenerativemodelconnect)<!-- -->.
18+
This class should only be instantiated by calling [LiveGenerativeModel.connect()](./ai.livegenerativemodel.md#livegenerativemodelconnect)<!-- -->.
1919

2020
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `LiveSession` class.
2121

docs-devsite/ai.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ The Firebase AI Web SDK.
3939
| [ImagenImageFormat](./ai.imagenimageformat.md#imagenimageformat_class) | <b><i>(Public Preview)</i></b> Defines the image format for images generated by Imagen.<!-- -->Use this class to specify the desired format (JPEG or PNG) and compression quality for images generated by Imagen. This is typically included as part of [ImagenModelParams](./ai.imagenmodelparams.md#imagenmodelparams_interface)<!-- -->. |
4040
| [ImagenModel](./ai.imagenmodel.md#imagenmodel_class) | <b><i>(Public Preview)</i></b> Class for Imagen model APIs.<!-- -->This class provides methods for generating images using the Imagen model. |
4141
| [IntegerSchema](./ai.integerschema.md#integerschema_class) | Schema class for "integer" types. |
42-
| [LiveGenerativeModel](./ai.livegenerativemodel.md#livegenerativemodel_class) | <b><i>(Public Preview)</i></b> Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal interactions with Gemini.<!-- -->Do not call this class' constructor directly. Instead, call [getLiveGenerativeModel()](./ai.md#getlivegenerativemodel_f2099ac)<!-- -->. |
43-
| [LiveSession](./ai.livesession.md#livesession_class) | <b><i>(Public Preview)</i></b> Represents an active, real-time, bidirectional conversation with the model.<!-- -->Do not call this constructor directly. Instead, call [LiveGenerativeModel.connect()](./ai.livegenerativemodel.md#livegenerativemodelconnect)<!-- -->. |
42+
| [LiveGenerativeModel](./ai.livegenerativemodel.md#livegenerativemodel_class) | <b><i>(Public Preview)</i></b> Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal interactions with Gemini.<!-- -->This class should only be instantiated with [getLiveGenerativeModel()](./ai.md#getlivegenerativemodel_f2099ac)<!-- -->. |
43+
| [LiveSession](./ai.livesession.md#livesession_class) | <b><i>(Public Preview)</i></b> Represents an active, real-time, bidirectional conversation with the model.<!-- -->This class should only be instantiated by calling [LiveGenerativeModel.connect()](./ai.livegenerativemodel.md#livegenerativemodelconnect)<!-- -->. |
4444
| [NumberSchema](./ai.numberschema.md#numberschema_class) | Schema class for "number" types. |
4545
| [ObjectSchema](./ai.objectschema.md#objectschema_class) | Schema class for "object" types. The <code>properties</code> param must be a map of <code>Schema</code> objects. |
4646
| [Schema](./ai.schema.md#schema_class) | Parent class encompassing all Schema types, with static methods that allow building specific Schema types. This class can be converted with <code>JSON.stringify()</code> into a JSON string accepted by Vertex AI REST endpoints. (This string conversion is automatically done when calling SDK methods.) |

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
import {
1919
AIErrorCode,
2020
GenerativeContentBlob,
21-
_LiveClientContent,
22-
_LiveClientRealtimeInput,
2321
LiveResponseType,
2422
LiveServerContent,
2523
LiveServerToolCall,
@@ -30,11 +28,15 @@ import { formatNewContent } from '../requests/request-helpers';
3028
import { AIError } from '../errors';
3129
import { WebSocketHandler } from '../platform/websocket';
3230
import { logger } from '../logger';
31+
import {
32+
_LiveClientContent,
33+
_LiveClientRealtimeInput
34+
} from '../types/live-responses';
3335

3436
/**
3537
* Represents an active, real-time, bidirectional conversation with the model.
3638
*
37-
* Do not call this constructor directly. Instead, call {@link LiveGenerativeModel.connect}.
39+
* This class should only be instantiated by calling {@link LiveGenerativeModel.connect}.
3840
*
3941
* @beta
4042
*/
@@ -173,18 +175,26 @@ export class LiveSession {
173175
if (LiveResponseType.SERVER_CONTENT in message) {
174176
yield {
175177
type: 'serverContent',
176-
...(message as { serverContent: object }).serverContent
178+
...(message as { serverContent: Omit<LiveServerContent, 'type'> })
179+
.serverContent
177180
} as LiveServerContent;
178181
} else if (LiveResponseType.TOOL_CALL in message) {
179182
yield {
180183
type: 'toolCall',
181-
...(message as { toolCall: object }).toolCall
184+
...(message as { toolCall: Omit<LiveServerToolCall, 'type'> })
185+
.toolCall
182186
} as LiveServerToolCall;
183187
} else if (LiveResponseType.TOOL_CALL_CANCELLATION in message) {
184188
yield {
185189
type: 'toolCallCancellation',
186-
...(message as { toolCallCancellation: object })
187-
.toolCallCancellation
190+
...(
191+
message as {
192+
toolCallCancellation: Omit<
193+
LiveServerToolCallCancellation,
194+
'type'
195+
>;
196+
}
197+
).toolCallCancellation
188198
} as LiveServerToolCallCancellation;
189199
} else {
190200
logger.warn(

packages/ai/src/models/live-generative-model.test.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
import { use, expect } from 'chai';
18-
import sinon, { stub } from 'sinon';
18+
import sinon, { SinonFakeTimers, stub } from 'sinon';
1919
import sinonChai from 'sinon-chai';
2020
import chaiAsPromised from 'chai-as-promised';
2121
import { AI } from '../public-types';
@@ -79,13 +79,16 @@ const fakeAI: AI = {
7979

8080
describe('LiveGenerativeModel', () => {
8181
let mockHandler: MockWebSocketHandler;
82+
let clock: SinonFakeTimers;
8283

8384
beforeEach(() => {
8485
mockHandler = new MockWebSocketHandler();
86+
clock = sinon.useFakeTimers();
8587
});
8688

8789
afterEach(() => {
8890
sinon.restore();
91+
clock.restore();
8992
});
9093

9194
it('connect() should call handler.connect and send setup message', async () => {
@@ -100,7 +103,8 @@ describe('LiveGenerativeModel', () => {
100103
expect(mockHandler.connect).to.have.been.calledOnce;
101104

102105
// Wait for the setup message to be sent
103-
await new Promise(resolve => setTimeout(resolve, 0));
106+
await clock.runAllAsync();
107+
104108
expect(mockHandler.send).to.have.been.calledOnce;
105109
const setupMessage = JSON.parse(mockHandler.send.getCall(0).args[0]);
106110
expect(setupMessage.setup.model).to.include('my-model');
@@ -121,7 +125,7 @@ describe('LiveGenerativeModel', () => {
121125
const connectPromise = model.connect();
122126

123127
// Wait for setup message
124-
await new Promise(resolve => setTimeout(resolve, 0));
128+
await clock.runAllAsync();
125129

126130
// Simulate a failed handshake
127131
mockHandler.simulateServerMessage({ error: 'handshake failed' });
@@ -152,7 +156,9 @@ describe('LiveGenerativeModel', () => {
152156
mockHandler
153157
);
154158
const connectPromise = model.connect();
155-
await new Promise(resolve => setTimeout(resolve, 0)); // Allow async operations
159+
160+
// Wait for setup message
161+
await clock.runAllAsync();
156162

157163
const sentData = JSON.parse(mockHandler.send.getCall(0).args[0]);
158164
expect(sentData.setup.generationConfig).to.deep.equal({ temperature: 0.8 });

packages/ai/src/models/live-generative-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ import {
2626
LiveGenerationConfig,
2727
LiveModelParams,
2828
Tool,
29-
ToolConfig,
30-
_LiveClientSetup
29+
ToolConfig
3130
} from '../public-types';
3231
import { WebSocketHandler } from '../platform/websocket';
3332
import { WebSocketUrl } from '../requests/request';
3433
import { formatSystemInstruction } from '../requests/request-helpers';
34+
import { _LiveClientSetup } from '../types/live-responses';
3535

3636
/**
3737
* Class for Live generative model APIs. The Live API enables low-latency, two-way multimodal
3838
* interactions with Gemini.
3939
*
40-
* Do not call this class' constructor directly. Instead, call {@link getLiveGenerativeModel}.
40+
* This class should only be instantiated with {@link getLiveGenerativeModel}.
4141
*
4242
* @beta
4343
*/

packages/ai/src/types/content.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ export interface FunctionCall {
125125
/**
126126
* The id of the function call. This must be sent back in the associated {@link FunctionResponse}.
127127
*
128-
* This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
128+
*
129+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
129130
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
130131
* `undefined`.
131132
*/
@@ -147,7 +148,7 @@ export interface FunctionResponse {
147148
/**
148149
* The id of the {@link FunctionCall}.
149150
*
150-
* This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
151+
* @remarks This property is only supported in the Gemini Developer API ({@link GoogleAIBackend}).
151152
* When using the Gemini Developer API ({@link GoogleAIBackend}), this property will be
152153
* `undefined`.
153154
*/

0 commit comments

Comments
 (0)