@@ -21,11 +21,50 @@ import { CountTokensRequest, GenerateContentRequest } from './requests';
21
21
* Defines an inference "backend" that uses Chrome's on-device model,
22
22
* and encapsulates logic for detecting when on-device is possible.
23
23
*
24
+ * These methods should not be called directly by the user.
25
+ *
24
26
* @public
25
27
*/
26
28
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
+ */
27
44
isAvailable ( request : GenerateContentRequest ) : Promise < boolean > ;
45
+
46
+ /**
47
+ * Stub - not yet available for on-device.
48
+ */
28
49
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
+ */
29
59
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
+ */
30
69
generateContentStream ( request : GenerateContentRequest ) : Promise < Response > ;
31
70
}
0 commit comments