Skip to content

VinF Hybrid Inference: Implement ChromeAdapter (rebased) #8943

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
47c48b3
Define HybridParams
erikeldridge Mar 24, 2025
4b2b2a6
Copy over most types from @types package
erikeldridge Mar 24, 2025
ddcae13
Document HybridParams and InferenceMode
erikeldridge Mar 24, 2025
c46825b
Assert HybridParams sets the model name
erikeldridge Mar 25, 2025
2d58976
Use dom-chromium-ai package directly
erikeldridge Mar 26, 2025
35f03f6
Use type for inference mode and update docs
erikeldridge Apr 2, 2025
c1fa837
Run yarn format
erikeldridge Apr 3, 2025
b37b237
rebased and updated deps
hsubox76 Apr 14, 2025
97958ab
revert deps
hsubox76 Apr 14, 2025
9e1b32d
Remove erroneous type dep
erikeldridge Apr 15, 2025
b516b90
docgen
gsiddh Apr 16, 2025
21d3aa1
Inject LanguageModel provider
erikeldridge Apr 16, 2025
1f720b9
Run gendoc
erikeldridge Apr 16, 2025
9763167
Define ChromeAdapter class
erikeldridge Mar 25, 2025
bf9de16
Implement ChromeAdapter class
erikeldridge Apr 2, 2025
be75b4f
Integrate with e2e test app
erikeldridge Apr 2, 2025
50272f4
Remove stray ai.ts
erikeldridge Apr 3, 2025
a90440e
Run yarn format
erikeldridge Apr 3, 2025
04b8334
Test model download logic
erikeldridge Apr 4, 2025
8b6f483
Test request-based availability checks
erikeldridge Apr 4, 2025
8056bc9
Test content generation
erikeldridge Apr 4, 2025
a32421d
Remove request.systemInstruction validation
erikeldridge Apr 4, 2025
d3176c2
Update content generator to emulate Vertex response
erikeldridge Apr 8, 2025
dc0628f
Remove redundant callVertex e2e test
erikeldridge Apr 17, 2025
47f00b2
Document ChromeAdapter methods
erikeldridge Apr 17, 2025
b460b8b
Update yarn.lock
erikeldridge Apr 17, 2025
8d9a493
Use package.json files from base branch
erikeldridge Apr 17, 2025
adef2fe
Stub chrome in positive test
erikeldridge Apr 17, 2025
9304e47
Defer checking for Chrome
erikeldridge Apr 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions common/api-review/util.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ export function isBrowser(): boolean;
// @public (undocumented)
export function isBrowserExtension(): boolean;

// Warning: (ae-missing-release-tag) "isChrome" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public (undocumented)
export function isChrome(): boolean;

// Warning: (ae-missing-release-tag) "isCloudflareWorker" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
//
// @public
Expand Down
19 changes: 18 additions & 1 deletion e2e/sample-apps/modular.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ import {
onValue,
off
} from 'firebase/database';
import { getGenerativeModel, getVertexAI, VertexAI } from 'firebase/vertexai';
import {
getGenerativeModel,
getVertexAI,
InferenceMode,
VertexAI
} from 'firebase/vertexai';
import { getDataConnect, DataConnect } from 'firebase/data-connect';

/**
Expand Down Expand Up @@ -332,6 +337,17 @@ function callDataConnect(app) {
console.log('[DATACONNECT] initialized');
}

async function callVertex(app) {
console.log('[VERTEX] start');
const vertex = getVertexAI(app);
const model = getGenerativeModel(vertex, {
mode: InferenceMode.PREFER_ON_DEVICE
});
const result = await model.generateContent("What is Roko's Basalisk?");
console.log(result.response.text());
console.log('[VERTEX] initialized');
}

/**
* Run smoke tests for all products.
* Comment out any products you want to ignore.
Expand All @@ -353,6 +369,7 @@ async function main() {
await callVertexAI(app);
callDataConnect(app);
await authLogout(app);
await callVertex(app);
console.log('DONE');
}

Expand Down
21 changes: 13 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,16 @@
"type": "git",
"url": "git+https://github.com/firebase/firebase-js-sdk.git"
},
"workspaces": [
"packages/*",
"integration/*",
"repo-scripts/*"
],
"workspaces": {
"packages": [
"packages/*",
"integration/*",
"repo-scripts/*"
],
"nohoist": [
"**/vertexai/@types/dom-chromium-ai"
]
},
"devDependencies": {
"@babel/core": "7.26.8",
"@babel/plugin-transform-modules-commonjs": "7.26.3",
Expand All @@ -80,7 +85,7 @@
"@types/long": "4.0.2",
"@types/mocha": "9.1.1",
"@types/mz": "2.7.8",
"@types/node": "18.19.83",
"@types/node": "18.19.75",
"@types/request": "2.48.12",
"@types/sinon": "9.0.11",
"@types/sinon-chai": "3.2.12",
Expand Down Expand Up @@ -139,7 +144,7 @@
"nyc": "15.1.0",
"ora": "5.4.1",
"patch-package": "7.0.2",
"playwright": "1.51.1",
"playwright": "1.50.1",
"postinstall-postinstall": "2.1.0",
"prettier": "2.8.8",
"protractor": "5.4.2",
Expand All @@ -158,7 +163,7 @@
"typedoc": "0.16.11",
"typescript": "5.5.4",
"watch": "1.0.2",
"webpack": "5.98.0",
"webpack": "5.97.1",
"yargs": "17.7.2"
}
}
6 changes: 6 additions & 0 deletions packages/util/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,12 @@ export function isSafari(): boolean {
);
}

export function isChrome(): boolean {
return (
!isNode() && !!navigator.userAgent && navigator.userAgent.includes('Chrome')
);
}

/**
* This method checks if indexedDB is supported by current browser/service worker context
* @return true if indexedDB is supported by current browser/service worker context
Expand Down
7 changes: 4 additions & 3 deletions packages/vertexai/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@firebase/vertexai",
"version": "1.2.1",
"version": "1.2.0",
"description": "A Firebase SDK for VertexAI",
"author": "Firebase <[email protected]> (https://firebase.google.com/)",
"engines": {
Expand Down Expand Up @@ -56,8 +56,9 @@
},
"license": "Apache-2.0",
"devDependencies": {
"@firebase/app": "0.11.4",
"@firebase/app": "0.11.3",
"@rollup/plugin-json": "6.1.0",
"@types/dom-chromium-ai": "0.0.6",
"rollup": "2.79.2",
"rollup-plugin-replace": "2.2.0",
"rollup-plugin-typescript2": "0.36.0",
Expand All @@ -78,4 +79,4 @@
],
"reportDir": "./coverage/node"
}
}
}
7 changes: 6 additions & 1 deletion packages/vertexai/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
import { VertexAIError } from './errors';
import { VertexAIModel, GenerativeModel, ImagenModel } from './models';
import { ChromeAdapter } from './methods/chrome-adapter';
import { LanguageModel } from './types/language-model';

export { ChatSession } from './methods/chat-session';
export * from './requests/schema-builder';
Expand Down Expand Up @@ -95,7 +96,11 @@ export function getGenerativeModel(
return new GenerativeModel(
vertexAI,
inCloudParams,
new ChromeAdapter(hybridParams.mode, hybridParams.onDeviceParams),
new ChromeAdapter(
window.LanguageModel as LanguageModel,
hybridParams.mode,
hybridParams.onDeviceParams
),
requestOptions
);
}
Expand Down
Loading
Loading