Skip to content

Inject LanguageModel provider #8946

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
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: 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