Skip to content

Commit 4c14257

Browse files
committed
Update docs
1 parent 1c9602e commit 4c14257

File tree

9 files changed

+148
-96
lines changed

9 files changed

+148
-96
lines changed

common/api-review/vertexai.api.md

+13-2
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,7 @@ export enum HarmSeverity {
553553
export interface HybridParams {
554554
inCloudParams?: ModelParams;
555555
mode: InferenceMode;
556-
// Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
557-
onDeviceParams?: LanguageModelCreateOptions;
556+
onDeviceParams?: OnDeviceParams;
558557
}
559558

560559
// @beta
@@ -718,6 +717,18 @@ export interface ObjectSchemaInterface extends SchemaInterface {
718717
type: SchemaType.OBJECT;
719718
}
720719

720+
// @public
721+
export interface OnDeviceParams {
722+
// Warning: (ae-forgotten-export) The symbol "LanguageModelCreateOptions" needs to be exported by the entry point index.d.ts
723+
//
724+
// (undocumented)
725+
createOptions?: LanguageModelCreateOptions;
726+
// Warning: (ae-forgotten-export) The symbol "LanguageModelPromptOptions" needs to be exported by the entry point index.d.ts
727+
//
728+
// (undocumented)
729+
promptOptions?: LanguageModelPromptOptions;
730+
}
731+
721732
// @public
722733
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
723734

docs-devsite/_toc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,8 @@ toc:
562562
path: /docs/reference/js/vertexai.objectschema.md
563563
- title: ObjectSchemaInterface
564564
path: /docs/reference/js/vertexai.objectschemainterface.md
565+
- title: OnDeviceParams
566+
path: /docs/reference/js/vertexai.ondeviceparams.md
565567
- title: PromptFeedback
566568
path: /docs/reference/js/vertexai.promptfeedback.md
567569
- title: RequestOptions

docs-devsite/vertexai.hybridparams.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface HybridParams
2424
| --- | --- | --- |
2525
| [inCloudParams](./vertexai.hybridparams.md#hybridparamsincloudparams) | [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Optional. Specifies advanced params for in-cloud inference. |
2626
| [mode](./vertexai.hybridparams.md#hybridparamsmode) | [InferenceMode](./vertexai.md#inferencemode) | Specifies on-device or in-cloud inference. Defaults to prefer on-device. |
27-
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | LanguageModelCreateOptions | Optional. Specifies advanced params for on-device inference. |
27+
| [onDeviceParams](./vertexai.hybridparams.md#hybridparamsondeviceparams) | [OnDeviceParams](./vertexai.ondeviceparams.md#ondeviceparams_interface) | Optional. Specifies advanced params for on-device inference. |
2828

2929
## HybridParams.inCloudParams
3030

@@ -53,5 +53,5 @@ Optional. Specifies advanced params for on-device inference.
5353
<b>Signature:</b>
5454

5555
```typescript
56-
onDeviceParams?: LanguageModelCreateOptions;
56+
onDeviceParams?: OnDeviceParams;
5757
```

docs-devsite/vertexai.md

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ The Firebase AI Web SDK.
108108
| [ModalityTokenCount](./vertexai.modalitytokencount.md#modalitytokencount_interface) | Represents token counting info for a single modality. |
109109
| [ModelParams](./vertexai.modelparams.md#modelparams_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_c63f46a)<!-- -->. |
110110
| [ObjectSchemaInterface](./vertexai.objectschemainterface.md#objectschemainterface_interface) | Interface for [ObjectSchema](./vertexai.objectschema.md#objectschema_class) class. |
111+
| [OnDeviceParams](./vertexai.ondeviceparams.md#ondeviceparams_interface) | Encapsulates configuration for on-device inference. |
111112
| [PromptFeedback](./vertexai.promptfeedback.md#promptfeedback_interface) | If the prompt was blocked, this will be populated with <code>blockReason</code> and the relevant <code>safetyRatings</code>. |
112113
| [RequestOptions](./vertexai.requestoptions.md#requestoptions_interface) | Params passed to [getGenerativeModel()](./vertexai.md#getgenerativemodel_c63f46a)<!-- -->. |
113114
| [RetrievedContextAttribution](./vertexai.retrievedcontextattribution.md#retrievedcontextattribution_interface) | |
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Project: /docs/reference/js/_project.yaml
2+
Book: /docs/reference/_book.yaml
3+
page_type: reference
4+
5+
{% comment %}
6+
DO NOT EDIT THIS FILE!
7+
This is generated by the JS SDK team, and any local changes will be
8+
overwritten. Changes should be made in the source code at
9+
https://github.com/firebase/firebase-js-sdk
10+
{% endcomment %}
11+
12+
# OnDeviceParams interface
13+
Encapsulates configuration for on-device inference.
14+
15+
<b>Signature:</b>
16+
17+
```typescript
18+
export interface OnDeviceParams
19+
```
20+
21+
## Properties
22+
23+
| Property | Type | Description |
24+
| --- | --- | --- |
25+
| [createOptions](./vertexai.ondeviceparams.md#ondeviceparamscreateoptions) | LanguageModelCreateOptions | |
26+
| [promptOptions](./vertexai.ondeviceparams.md#ondeviceparamspromptoptions) | LanguageModelPromptOptions | |
27+
28+
## OnDeviceParams.createOptions
29+
30+
<b>Signature:</b>
31+
32+
```typescript
33+
createOptions?: LanguageModelCreateOptions;
34+
```
35+
36+
## OnDeviceParams.promptOptions
37+
38+
<b>Signature:</b>
39+
40+
```typescript
41+
promptOptions?: LanguageModelPromptOptions;
42+
```

e2e/sample-apps/modular.js

+16-18
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ async function callVertexAI(app) {
314314
console.log('[VERTEXAI] start');
315315
const vertexAI = getVertexAI(app);
316316

317-
const responseSchema = Schema.object({
317+
const jsonSchema = Schema.object({
318318
properties: {
319319
characters: Schema.array({
320320
items: Schema.object({
@@ -331,26 +331,24 @@ async function callVertexAI(app) {
331331
});
332332

333333
const model = getGenerativeModel(vertexAI, {
334-
mode: 'prefer_on_device',
335-
// mode: 'only_in_cloud'
336-
});
337-
338-
const singleResult = await model.generateContent({
339-
generationConfig: {
340-
responseMimeType: 'application/json',
341-
responseSchema
334+
// mode: 'prefer_on_device',
335+
mode: 'only_in_cloud',
336+
inCloudParams: {
337+
generationConfig: {
338+
responseMimeType: 'application/json',
339+
responseSchema: jsonSchema
340+
}
342341
},
343-
contents: [
344-
{
345-
role: 'user',
346-
parts: [
347-
{
348-
text: "For use in a children's card game, generate 10 animal-based characters."
349-
}
350-
]
342+
onDeviceParams: {
343+
promptOptions: {
344+
responseConstraint: jsonSchema
351345
}
352-
]
346+
}
353347
});
348+
349+
const singleResult = await model.generateContent(
350+
"For use in a children's card game, generate 10 animal-based characters."
351+
);
354352
console.log(`Generated text:`, JSON.parse(singleResult.response.text()));
355353
console.log(`[VERTEXAI] end`);
356354
}

packages/vertexai/src/methods/chrome-adapter.test.ts

+38-40
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ describe('ChromeAdapter', () => {
8686
languageModelProvider,
8787
'availability'
8888
).resolves(Availability.available);
89-
const onDeviceParams = {
89+
const createOptions = {
9090
// Explicitly sets expected inputs.
9191
expectedInputs: [{ type: 'text' }]
9292
} as LanguageModelCreateOptions;
9393
const adapter = new ChromeAdapter(
9494
languageModelProvider,
9595
'prefer_on_device',
96-
onDeviceParams
96+
{
97+
createOptions
98+
}
9799
);
98100
await adapter.isAvailable({
99101
contents: [
@@ -103,7 +105,7 @@ describe('ChromeAdapter', () => {
103105
}
104106
]
105107
});
106-
expect(availabilityStub).to.have.been.calledWith(onDeviceParams);
108+
expect(availabilityStub).to.have.been.calledWith(createOptions);
107109
});
108110
});
109111
describe('isAvailable', () => {
@@ -211,20 +213,20 @@ describe('ChromeAdapter', () => {
211213
const createStub = stub(languageModelProvider, 'create').resolves(
212214
{} as LanguageModel
213215
);
214-
const expectedOnDeviceParams = {
216+
const createOptions = {
215217
expectedInputs: [{ type: 'image' }]
216218
} as LanguageModelCreateOptions;
217219
const adapter = new ChromeAdapter(
218220
languageModelProvider,
219221
'prefer_on_device',
220-
expectedOnDeviceParams
222+
{ createOptions }
221223
);
222224
expect(
223225
await adapter.isAvailable({
224226
contents: [{ role: 'user', parts: [{ text: 'hi' }] }]
225227
})
226228
).to.be.false;
227-
expect(createStub).to.have.been.calledOnceWith(expectedOnDeviceParams);
229+
expect(createStub).to.have.been.calledOnceWith(createOptions);
228230
});
229231
it('avoids redundant downloads', async () => {
230232
const languageModelProvider = {
@@ -311,21 +313,21 @@ describe('ChromeAdapter', () => {
311313
);
312314
const promptOutput = 'hi';
313315
const promptStub = stub(languageModel, 'prompt').resolves(promptOutput);
314-
const expectedOnDeviceParams = {
316+
const createOptions = {
315317
systemPrompt: 'be yourself',
316318
expectedInputs: [{ type: 'image' }]
317319
} as LanguageModelCreateOptions;
318320
const adapter = new ChromeAdapter(
319321
languageModelProvider,
320322
'prefer_on_device',
321-
expectedOnDeviceParams
323+
{ createOptions }
322324
);
323325
const request = {
324326
contents: [{ role: 'user', parts: [{ text: 'anything' }] }]
325327
} as GenerateContentRequest;
326328
const response = await adapter.generateContent(request);
327329
// Asserts initialization params are proxied.
328-
expect(createStub).to.have.been.calledOnceWith(expectedOnDeviceParams);
330+
expect(createStub).to.have.been.calledOnceWith(createOptions);
329331
// Asserts Vertex input type is mapped to Chrome type.
330332
expect(promptStub).to.have.been.calledOnceWith([
331333
{
@@ -357,14 +359,14 @@ describe('ChromeAdapter', () => {
357359
);
358360
const promptOutput = 'hi';
359361
const promptStub = stub(languageModel, 'prompt').resolves(promptOutput);
360-
const expectedOnDeviceParams = {
362+
const createOptions = {
361363
systemPrompt: 'be yourself',
362364
expectedInputs: [{ type: 'image' }]
363365
} as LanguageModelCreateOptions;
364366
const adapter = new ChromeAdapter(
365367
languageModelProvider,
366368
'prefer_on_device',
367-
expectedOnDeviceParams
369+
{ createOptions }
368370
);
369371
const request = {
370372
contents: [
@@ -384,7 +386,7 @@ describe('ChromeAdapter', () => {
384386
} as GenerateContentRequest;
385387
const response = await adapter.generateContent(request);
386388
// Asserts initialization params are proxied.
387-
expect(createStub).to.have.been.calledOnceWith(expectedOnDeviceParams);
389+
expect(createStub).to.have.been.calledOnceWith(createOptions);
388390
// Asserts Vertex input type is mapped to Chrome type.
389391
expect(promptStub).to.have.been.calledOnceWith([
390392
{
@@ -407,7 +409,7 @@ describe('ChromeAdapter', () => {
407409
]
408410
});
409411
});
410-
it('supports structured output by mapping responseSchema to responseConstraint', async () => {
412+
it('honors prompt options', async () => {
411413
const languageModel = {
412414
// eslint-disable-next-line @typescript-eslint/no-unused-vars
413415
prompt: (p: LanguageModelMessageContent[]) => Promise.resolve('')
@@ -417,17 +419,17 @@ describe('ChromeAdapter', () => {
417419
} as LanguageModel;
418420
const promptOutput = '{}';
419421
const promptStub = stub(languageModel, 'prompt').resolves(promptOutput);
422+
const promptOptions = {
423+
responseConstraint: Schema.object({
424+
properties: {}
425+
})
426+
};
420427
const adapter = new ChromeAdapter(
421428
languageModelProvider,
422-
'prefer_on_device'
429+
'prefer_on_device',
430+
{ promptOptions }
423431
);
424-
const responseSchema = Schema.object({
425-
properties: {}
426-
});
427432
const request = {
428-
generationConfig: {
429-
responseSchema
430-
},
431433
contents: [{ role: 'user', parts: [{ text: 'anything' }] }]
432434
} as GenerateContentRequest;
433435
await adapter.generateContent(request);
@@ -438,9 +440,7 @@ describe('ChromeAdapter', () => {
438440
content: request.contents[0].parts[0].text
439441
}
440442
],
441-
{
442-
responseConstraint: responseSchema
443-
}
443+
promptOptions
444444
);
445445
});
446446
});
@@ -499,19 +499,19 @@ describe('ChromeAdapter', () => {
499499
}
500500
})
501501
);
502-
const expectedOnDeviceParams = {
502+
const createOptions = {
503503
expectedInputs: [{ type: 'image' }]
504504
} as LanguageModelCreateOptions;
505505
const adapter = new ChromeAdapter(
506506
languageModelProvider,
507507
'prefer_on_device',
508-
expectedOnDeviceParams
508+
{ createOptions }
509509
);
510510
const request = {
511511
contents: [{ role: 'user', parts: [{ text: 'anything' }] }]
512512
} as GenerateContentRequest;
513513
const response = await adapter.generateContentStream(request);
514-
expect(createStub).to.have.been.calledOnceWith(expectedOnDeviceParams);
514+
expect(createStub).to.have.been.calledOnceWith(createOptions);
515515
expect(promptStub).to.have.been.calledOnceWith([
516516
{
517517
type: 'text',
@@ -542,13 +542,13 @@ describe('ChromeAdapter', () => {
542542
}
543543
})
544544
);
545-
const expectedOnDeviceParams = {
545+
const createOptions = {
546546
expectedInputs: [{ type: 'image' }]
547547
} as LanguageModelCreateOptions;
548548
const adapter = new ChromeAdapter(
549549
languageModelProvider,
550550
'prefer_on_device',
551-
expectedOnDeviceParams
551+
{ createOptions }
552552
);
553553
const request = {
554554
contents: [
@@ -567,7 +567,7 @@ describe('ChromeAdapter', () => {
567567
]
568568
} as GenerateContentRequest;
569569
const response = await adapter.generateContentStream(request);
570-
expect(createStub).to.have.been.calledOnceWith(expectedOnDeviceParams);
570+
expect(createStub).to.have.been.calledOnceWith(createOptions);
571571
expect(promptStub).to.have.been.calledOnceWith([
572572
{
573573
type: 'text',
@@ -583,7 +583,7 @@ describe('ChromeAdapter', () => {
583583
`data: {"candidates":[{"content":{"role":"model","parts":[{"text":["${part}"]}]}}]}\n\n`
584584
]);
585585
});
586-
it('supports structured output by mapping responseSchema to responseConstraint', async () => {
586+
it('honors prompt options', async () => {
587587
const languageModel = {
588588
// eslint-disable-next-line @typescript-eslint/no-unused-vars
589589
promptStreaming: p => new ReadableStream()
@@ -594,17 +594,17 @@ describe('ChromeAdapter', () => {
594594
const promptStub = stub(languageModel, 'promptStreaming').returns(
595595
new ReadableStream()
596596
);
597+
const promptOptions = {
598+
responseConstraint: Schema.object({
599+
properties: {}
600+
})
601+
};
597602
const adapter = new ChromeAdapter(
598603
languageModelProvider,
599-
'prefer_on_device'
604+
'prefer_on_device',
605+
{ promptOptions }
600606
);
601-
const responseSchema = Schema.object({
602-
properties: {}
603-
});
604607
const request = {
605-
generationConfig: {
606-
responseSchema
607-
},
608608
contents: [{ role: 'user', parts: [{ text: 'anything' }] }]
609609
} as GenerateContentRequest;
610610
await adapter.generateContentStream(request);
@@ -615,9 +615,7 @@ describe('ChromeAdapter', () => {
615615
content: request.contents[0].parts[0].text
616616
}
617617
],
618-
{
619-
responseConstraint: responseSchema
620-
}
618+
promptOptions
621619
);
622620
});
623621
});

0 commit comments

Comments
 (0)