Skip to content

Commit f9f641d

Browse files
committed
Fill out chrome-adapter doc comments
1 parent 9e4e910 commit f9f641d

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

common/api-review/ai.api.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,9 @@ export class ChatSession {
139139

140140
// @public
141141
export interface ChromeAdapter {
142-
// (undocumented)
143142
countTokens(_request: CountTokensRequest): Promise<Response>;
144-
// (undocumented)
145143
generateContent(request: GenerateContentRequest): Promise<Response>;
146-
// (undocumented)
147144
generateContentStream(request: GenerateContentRequest): Promise<Response>;
148-
// (undocumented)
149145
isAvailable(request: GenerateContentRequest): Promise<boolean>;
150146
}
151147

packages/ai/src/types/chrome-adapter.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,50 @@ import { CountTokensRequest, GenerateContentRequest } from './requests';
2121
* Defines an inference "backend" that uses Chrome's on-device model,
2222
* and encapsulates logic for detecting when on-device is possible.
2323
*
24+
* These methods should not be called directly by the user.
25+
*
2426
* @public
2527
*/
2628
export interface ChromeAdapter {
29+
/**
30+
* Checks if a given request can be made on-device.
31+
*
32+
* <ol>Encapsulates a few concerns:
33+
* <li>the mode</li>
34+
* <li>API existence</li>
35+
* <li>prompt formatting</li>
36+
* <li>model availability, including triggering download if necessary</li>
37+
* </ol>
38+
*
39+
* <p>Pros: callers needn't be concerned with details of on-device availability.</p>
40+
* <p>Cons: this method spans a few concerns and splits request validation from usage.
41+
* If instance variables weren't already part of the API, we could consider a better
42+
* separation of concerns.</p>
43+
*/
2744
isAvailable(request: GenerateContentRequest): Promise<boolean>;
45+
46+
/**
47+
* Stub - not yet available for on-device.
48+
*/
2849
countTokens(_request: CountTokensRequest): Promise<Response>;
50+
51+
/**
52+
* Generates content on device.
53+
*
54+
* <p>This is comparable to {@link GenerativeModel.generateContent} for generating content in
55+
* Cloud.</p>
56+
* @param request - a standard Firebase AI {@link GenerateContentRequest}
57+
* @returns {@link Response}, so we can reuse common response formatting.
58+
*/
2959
generateContent(request: GenerateContentRequest): Promise<Response>;
60+
61+
/**
62+
* Generates content stream on device.
63+
*
64+
* <p>This is comparable to {@link GenerativeModel.generateContentStream} for generating content in
65+
* Cloud.</p>
66+
* @param request - a standard Firebase AI {@link GenerateContentRequest}
67+
* @returns {@link Response}, so we can reuse common response formatting.
68+
*/
3069
generateContentStream(request: GenerateContentRequest): Promise<Response>;
3170
}

0 commit comments

Comments
 (0)