-
Notifications
You must be signed in to change notification settings - Fork 962
Firebase AI Hybrid Inference Implementation #9029
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
Changes from 15 commits
55c05a0
c16cbf1
50f142a
72cd626
177f546
58d92df
2a33a07
e5e8c36
e9dc43e
9e4e910
f9f641d
5df0f21
ca3fc07
4f469cf
d32c661
0efb0d0
a27968c
c2d7bae
254b257
2d81e00
67ad283
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
Project: /docs/reference/js/_project.yaml | ||
Book: /docs/reference/_book.yaml | ||
page_type: reference | ||
|
||
{% comment %} | ||
DO NOT EDIT THIS FILE! | ||
This is generated by the JS SDK team, and any local changes will be | ||
overwritten. Changes should be made in the source code at | ||
https://github.com/firebase/firebase-js-sdk | ||
{% endcomment %} | ||
|
||
# ChromeAdapter interface | ||
(EXPERIMENTAL) | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Defines an inference "backend" that uses Chrome's on-device model, and encapsulates logic for detecting when on-device is possible. | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
These methods should not be called directly by the user. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
export interface ChromeAdapter | ||
``` | ||
|
||
## Methods | ||
|
||
| Method | Description | | ||
| --- | --- | | ||
| [countTokens(\_request)](./ai.chromeadapter.md#chromeadaptercounttokens) | Stub - not yet available for on-device. | | ||
| [generateContent(request)](./ai.chromeadapter.md#chromeadaptergeneratecontent) | Generates content on device.<p>This is comparable to [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) for generating content in Cloud.</p> | | ||
| [generateContentStream(request)](./ai.chromeadapter.md#chromeadaptergeneratecontentstream) | Generates content stream on device.<p>This is comparable to [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) for generating content in Cloud.</p> | | ||
| [isAvailable(request)](./ai.chromeadapter.md#chromeadapterisavailable) | Checks if a given request can be made on-device.<ol>Encapsulates a few concerns: <li>the mode</li> <li>API existence</li> <li>prompt formatting</li> <li>model availability, including triggering download if necessary</li> </ol><p>Pros: callers needn't be concerned with details of on-device availability.</p> <p>Cons: this method spans a few concerns and splits request validation from usage. If instance variables weren't already part of the API, we could consider a better separation of concerns.</p> | | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## ChromeAdapter.countTokens() | ||
|
||
Stub - not yet available for on-device. | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
countTokens(_request: CountTokensRequest): Promise<Response>; | ||
``` | ||
|
||
#### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| \_request | [CountTokensRequest](./ai.counttokensrequest.md#counttokensrequest_interface) | | | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Returns:</b> | ||
|
||
Promise<Response> | ||
|
||
## ChromeAdapter.generateContent() | ||
|
||
Generates content on device. | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<p>This is comparable to [GenerativeModel.generateContent()](./ai.generativemodel.md#generativemodelgeneratecontent) for generating content in Cloud.</p> | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
generateContent(request: GenerateContentRequest): Promise<Response>; | ||
``` | ||
|
||
#### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | a standard Firebase AI [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | | ||
|
||
<b>Returns:</b> | ||
|
||
Promise<Response> | ||
|
||
Response, so we can reuse common response formatting. | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## ChromeAdapter.generateContentStream() | ||
|
||
Generates content stream on device. | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<p>This is comparable to [GenerativeModel.generateContentStream()](./ai.generativemodel.md#generativemodelgeneratecontentstream) for generating content in Cloud.</p> | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
generateContentStream(request: GenerateContentRequest): Promise<Response>; | ||
``` | ||
|
||
#### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | a standard Firebase AI [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | | ||
|
||
<b>Returns:</b> | ||
|
||
Promise<Response> | ||
|
||
Response, so we can reuse common response formatting. | ||
|
||
## ChromeAdapter.isAvailable() | ||
|
||
Checks if a given request can be made on-device. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe something like: Checks if a given request can be fulfilled using on-device inference. Don't know if "fulfilled" is the quite the right word, though. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took a shot: "Checks if the on-device model is capable of handling a given request." |
||
|
||
<ol>Encapsulates a few concerns: <li>the mode</li> <li>API existence</li> <li>prompt formatting</li> <li>model availability, including triggering download if necessary</li> </ol> | ||
|
||
<p>Pros: callers needn't be concerned with details of on-device availability.</p> <p>Cons: this method spans a few concerns and splits request validation from usage. If instance variables weren't already part of the API, we could consider a better separation of concerns.</p> | ||
rachelsaunders marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
isAvailable(request: GenerateContentRequest): Promise<boolean>; | ||
``` | ||
|
||
#### Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| request | [GenerateContentRequest](./ai.generatecontentrequest.md#generatecontentrequest_interface) | | | ||
|
||
<b>Returns:</b> | ||
|
||
Promise<boolean> | ||
|
Uh oh!
There was an error while loading. Please reload this page.