@depup/firebase__ai 2.9.0-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/changes.json +10 -0
- package/dist/ai-public.d.ts +3472 -0
- package/dist/ai.d.ts +3712 -0
- package/dist/esm/index.esm.js +4765 -0
- package/dist/esm/index.esm.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/api.d.ts +121 -0
- package/dist/esm/src/backend.d.ts +98 -0
- package/dist/esm/src/constants.d.ts +29 -0
- package/dist/esm/src/errors.d.ts +35 -0
- package/dist/esm/src/factory-browser.d.ts +19 -0
- package/dist/esm/src/factory-node.d.ts +19 -0
- package/dist/esm/src/googleai-mappers.d.ts +73 -0
- package/dist/esm/src/helpers.d.ts +30 -0
- package/dist/esm/src/index.d.ts +13 -0
- package/dist/esm/src/index.node.d.ts +7 -0
- package/dist/esm/src/logger.d.ts +18 -0
- package/dist/esm/src/methods/chat-session-helpers.d.ts +18 -0
- package/dist/esm/src/methods/chat-session.d.ts +77 -0
- package/dist/esm/src/methods/chrome-adapter.d.ts +124 -0
- package/dist/esm/src/methods/count-tokens.d.ts +21 -0
- package/dist/esm/src/methods/generate-content.d.ts +25 -0
- package/dist/esm/src/methods/live-session-helpers.d.ts +154 -0
- package/dist/esm/src/methods/live-session.d.ts +154 -0
- package/dist/esm/src/models/ai-model.d.ts +72 -0
- package/dist/esm/src/models/generative-model.d.ts +56 -0
- package/dist/esm/src/models/imagen-model.d.ts +102 -0
- package/dist/esm/src/models/index.d.ts +20 -0
- package/dist/esm/src/models/live-generative-model.d.ts +55 -0
- package/dist/esm/src/models/template-generative-model.d.ts +64 -0
- package/dist/esm/src/models/template-imagen-model.d.ts +51 -0
- package/dist/esm/src/models/utils.d.ts +26 -0
- package/dist/esm/src/public-types.d.ts +97 -0
- package/dist/esm/src/requests/hybrid-helpers.d.ts +33 -0
- package/dist/esm/src/requests/imagen-image-format.d.ts +61 -0
- package/dist/esm/src/requests/request-helpers.d.ts +28 -0
- package/dist/esm/src/requests/request.d.ts +69 -0
- package/dist/esm/src/requests/response-helpers.d.ts +57 -0
- package/dist/esm/src/requests/schema-builder.d.ts +170 -0
- package/dist/esm/src/requests/stream-reader.d.ts +39 -0
- package/dist/esm/src/service.d.ts +35 -0
- package/dist/esm/src/types/chrome-adapter.d.ts +61 -0
- package/dist/esm/src/types/content.d.ts +266 -0
- package/dist/esm/src/types/enums.d.ts +419 -0
- package/dist/esm/src/types/error.d.ts +89 -0
- package/dist/esm/src/types/googleai.d.ts +57 -0
- package/dist/esm/src/types/imagen/index.d.ts +18 -0
- package/dist/esm/src/types/imagen/internal.d.ts +134 -0
- package/dist/esm/src/types/imagen/requests.d.ts +245 -0
- package/dist/esm/src/types/imagen/responses.d.ts +79 -0
- package/dist/esm/src/types/index.d.ts +26 -0
- package/dist/esm/src/types/internal.d.ts +35 -0
- package/dist/esm/src/types/language-model.d.ts +107 -0
- package/dist/esm/src/types/live-responses.d.ts +79 -0
- package/dist/esm/src/types/requests.d.ts +543 -0
- package/dist/esm/src/types/responses.d.ts +607 -0
- package/dist/esm/src/types/schema.d.ts +139 -0
- package/dist/esm/src/websocket.d.ts +67 -0
- package/dist/index.cjs.js +4820 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.node.cjs.js +4512 -0
- package/dist/index.node.cjs.js.map +1 -0
- package/dist/index.node.mjs +4457 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/src/api.d.ts +121 -0
- package/dist/src/backend.d.ts +98 -0
- package/dist/src/constants.d.ts +29 -0
- package/dist/src/errors.d.ts +35 -0
- package/dist/src/factory-browser.d.ts +19 -0
- package/dist/src/factory-node.d.ts +19 -0
- package/dist/src/googleai-mappers.d.ts +73 -0
- package/dist/src/helpers.d.ts +30 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.node.d.ts +7 -0
- package/dist/src/logger.d.ts +18 -0
- package/dist/src/methods/chat-session-helpers.d.ts +18 -0
- package/dist/src/methods/chat-session.d.ts +77 -0
- package/dist/src/methods/chrome-adapter.d.ts +124 -0
- package/dist/src/methods/count-tokens.d.ts +21 -0
- package/dist/src/methods/generate-content.d.ts +25 -0
- package/dist/src/methods/live-session-helpers.d.ts +154 -0
- package/dist/src/methods/live-session.d.ts +154 -0
- package/dist/src/models/ai-model.d.ts +72 -0
- package/dist/src/models/generative-model.d.ts +56 -0
- package/dist/src/models/imagen-model.d.ts +102 -0
- package/dist/src/models/index.d.ts +20 -0
- package/dist/src/models/live-generative-model.d.ts +55 -0
- package/dist/src/models/template-generative-model.d.ts +64 -0
- package/dist/src/models/template-imagen-model.d.ts +51 -0
- package/dist/src/models/utils.d.ts +26 -0
- package/dist/src/public-types.d.ts +97 -0
- package/dist/src/requests/hybrid-helpers.d.ts +33 -0
- package/dist/src/requests/imagen-image-format.d.ts +61 -0
- package/dist/src/requests/request-helpers.d.ts +28 -0
- package/dist/src/requests/request.d.ts +69 -0
- package/dist/src/requests/response-helpers.d.ts +57 -0
- package/dist/src/requests/schema-builder.d.ts +170 -0
- package/dist/src/requests/stream-reader.d.ts +39 -0
- package/dist/src/service.d.ts +35 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/chrome-adapter.d.ts +61 -0
- package/dist/src/types/content.d.ts +266 -0
- package/dist/src/types/enums.d.ts +419 -0
- package/dist/src/types/error.d.ts +89 -0
- package/dist/src/types/googleai.d.ts +57 -0
- package/dist/src/types/imagen/index.d.ts +18 -0
- package/dist/src/types/imagen/internal.d.ts +134 -0
- package/dist/src/types/imagen/requests.d.ts +245 -0
- package/dist/src/types/imagen/responses.d.ts +79 -0
- package/dist/src/types/index.d.ts +26 -0
- package/dist/src/types/internal.d.ts +35 -0
- package/dist/src/types/language-model.d.ts +107 -0
- package/dist/src/types/live-responses.d.ts +79 -0
- package/dist/src/types/requests.d.ts +543 -0
- package/dist/src/types/responses.d.ts +607 -0
- package/dist/src/types/schema.d.ts +139 -0
- package/dist/src/websocket.d.ts +67 -0
- package/package.json +106 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { ImagenGenerationConfig, ImagenSafetySettings } from './requests';
|
|
18
|
+
/**
|
|
19
|
+
* A response from the REST API is expected to look like this in the success case:
|
|
20
|
+
* {
|
|
21
|
+
* "predictions": [
|
|
22
|
+
* {
|
|
23
|
+
* "mimeType": "image/png",
|
|
24
|
+
* "bytesBase64Encoded": "iVBORw0KG..."
|
|
25
|
+
* },
|
|
26
|
+
* {
|
|
27
|
+
* "mimeType": "image/png",
|
|
28
|
+
* "bytesBase64Encoded": "i4BOtw0KG..."
|
|
29
|
+
* }
|
|
30
|
+
* ]
|
|
31
|
+
* }
|
|
32
|
+
*
|
|
33
|
+
* And like this in the failure case:
|
|
34
|
+
* {
|
|
35
|
+
* "predictions": [
|
|
36
|
+
* {
|
|
37
|
+
* "raiFilteredReason": "..."
|
|
38
|
+
* }
|
|
39
|
+
* ]
|
|
40
|
+
* }
|
|
41
|
+
*
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export interface ImagenResponseInternal {
|
|
45
|
+
predictions?: Array<{
|
|
46
|
+
/**
|
|
47
|
+
* The MIME type of the generated image.
|
|
48
|
+
*/
|
|
49
|
+
mimeType?: string;
|
|
50
|
+
/**
|
|
51
|
+
* The image data encoded as a base64 string.
|
|
52
|
+
*/
|
|
53
|
+
bytesBase64Encoded?: string;
|
|
54
|
+
/**
|
|
55
|
+
* The GCS URI where the image was stored.
|
|
56
|
+
*/
|
|
57
|
+
gcsUri?: string;
|
|
58
|
+
/**
|
|
59
|
+
* The reason why the image was filtered.
|
|
60
|
+
*/
|
|
61
|
+
raiFilteredReason?: string;
|
|
62
|
+
/**
|
|
63
|
+
* The safety attributes.
|
|
64
|
+
*
|
|
65
|
+
* This type is currently unused in the SDK. It is sent back because our requests set
|
|
66
|
+
* `includeSafetyAttributes`. This property is currently only used to avoid throwing an error
|
|
67
|
+
* when encountering this unsupported prediction type.
|
|
68
|
+
*/
|
|
69
|
+
safetyAttributes?: unknown;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The parameters to be sent in the request body of the HTTP call
|
|
74
|
+
* to the Vertex AI backend.
|
|
75
|
+
*
|
|
76
|
+
* We need a separate internal-only interface for this because the REST
|
|
77
|
+
* API expects different parameter names than what we show to our users.
|
|
78
|
+
*
|
|
79
|
+
* Sample request body JSON:
|
|
80
|
+
* {
|
|
81
|
+
* "instances": [
|
|
82
|
+
* {
|
|
83
|
+
* "prompt": "Portrait of a golden retriever on a beach."
|
|
84
|
+
* }
|
|
85
|
+
* ],
|
|
86
|
+
* "parameters": {
|
|
87
|
+
* "mimeType": "image/png",
|
|
88
|
+
* "safetyFilterLevel": "block_low_and_above",
|
|
89
|
+
* "personGeneration": "allow_all",
|
|
90
|
+
* "sampleCount": 2,
|
|
91
|
+
* "includeRaiReason": true,
|
|
92
|
+
* "includeSafetyAttributes": true,
|
|
93
|
+
* "aspectRatio": "9:16"
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* See the Google Cloud docs: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api#-drest
|
|
98
|
+
*
|
|
99
|
+
* @internal
|
|
100
|
+
*/
|
|
101
|
+
export interface PredictRequestBody {
|
|
102
|
+
instances: [
|
|
103
|
+
{
|
|
104
|
+
prompt: string;
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
parameters: {
|
|
108
|
+
sampleCount: number;
|
|
109
|
+
aspectRatio?: string;
|
|
110
|
+
outputOptions?: {
|
|
111
|
+
mimeType: string;
|
|
112
|
+
compressionQuality?: number;
|
|
113
|
+
};
|
|
114
|
+
negativePrompt?: string;
|
|
115
|
+
storageUri?: string;
|
|
116
|
+
addWatermark?: boolean;
|
|
117
|
+
safetyFilterLevel?: string;
|
|
118
|
+
personGeneration?: string;
|
|
119
|
+
includeRaiReason: boolean;
|
|
120
|
+
includeSafetyAttributes: boolean;
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Contains all possible REST API paramaters that are provided by the caller.
|
|
125
|
+
*
|
|
126
|
+
* @internal
|
|
127
|
+
*/
|
|
128
|
+
export type ImagenGenerationParams = {
|
|
129
|
+
/**
|
|
130
|
+
* The Cloud Storage for Firebase bucket URI where the images should be stored
|
|
131
|
+
* (for GCS requests only).
|
|
132
|
+
*/
|
|
133
|
+
gcsURI?: string;
|
|
134
|
+
} & ImagenGenerationConfig & ImagenSafetySettings;
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { ImagenImageFormat } from '../../requests/imagen-image-format';
|
|
18
|
+
/**
|
|
19
|
+
* Parameters for configuring an {@link ImagenModel}.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface ImagenModelParams {
|
|
24
|
+
/**
|
|
25
|
+
* The Imagen model to use for generating images.
|
|
26
|
+
* For example: `imagen-3.0-generate-002`.
|
|
27
|
+
*
|
|
28
|
+
* Only Imagen 3 models (named `imagen-3.0-*`) are supported.
|
|
29
|
+
*
|
|
30
|
+
* See {@link https://firebase.google.com/docs/vertex-ai/models | model versions}
|
|
31
|
+
* for a full list of supported Imagen 3 models.
|
|
32
|
+
*/
|
|
33
|
+
model: string;
|
|
34
|
+
/**
|
|
35
|
+
* Configuration options for generating images with Imagen.
|
|
36
|
+
*/
|
|
37
|
+
generationConfig?: ImagenGenerationConfig;
|
|
38
|
+
/**
|
|
39
|
+
* Safety settings for filtering potentially inappropriate content.
|
|
40
|
+
*/
|
|
41
|
+
safetySettings?: ImagenSafetySettings;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Configuration options for generating images with Imagen.
|
|
45
|
+
*
|
|
46
|
+
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images-imagen | documentation} for
|
|
47
|
+
* more details.
|
|
48
|
+
*
|
|
49
|
+
* @public
|
|
50
|
+
*/
|
|
51
|
+
export interface ImagenGenerationConfig {
|
|
52
|
+
/**
|
|
53
|
+
* A description of what should be omitted from the generated images.
|
|
54
|
+
*
|
|
55
|
+
* Support for negative prompts depends on the Imagen model.
|
|
56
|
+
*
|
|
57
|
+
* See the {@link http://firebase.google.com/docs/vertex-ai/model-parameters#imagen | documentation} for more details.
|
|
58
|
+
*
|
|
59
|
+
* This is no longer supported in the Gemini Developer API ({@link GoogleAIBackend}) in versions
|
|
60
|
+
* greater than `imagen-3.0-generate-002`.
|
|
61
|
+
*/
|
|
62
|
+
negativePrompt?: string;
|
|
63
|
+
/**
|
|
64
|
+
* The number of images to generate. The default value is 1.
|
|
65
|
+
*
|
|
66
|
+
* The number of sample images that may be generated in each request depends on the model
|
|
67
|
+
* (typically up to 4); see the <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">sampleCount</a>
|
|
68
|
+
* documentation for more details.
|
|
69
|
+
*/
|
|
70
|
+
numberOfImages?: number;
|
|
71
|
+
/**
|
|
72
|
+
* The aspect ratio of the generated images. The default value is square 1:1.
|
|
73
|
+
* Supported aspect ratios depend on the Imagen model, see {@link (ImagenAspectRatio:type)}
|
|
74
|
+
* for more details.
|
|
75
|
+
*/
|
|
76
|
+
aspectRatio?: ImagenAspectRatio;
|
|
77
|
+
/**
|
|
78
|
+
* The image format of the generated images. The default is PNG.
|
|
79
|
+
*
|
|
80
|
+
* See {@link ImagenImageFormat} for more details.
|
|
81
|
+
*/
|
|
82
|
+
imageFormat?: ImagenImageFormat;
|
|
83
|
+
/**
|
|
84
|
+
* Whether to add an invisible watermark to generated images.
|
|
85
|
+
*
|
|
86
|
+
* If set to `true`, an invisible SynthID watermark is embedded in generated images to indicate
|
|
87
|
+
* that they are AI generated. If set to `false`, watermarking will be disabled.
|
|
88
|
+
*
|
|
89
|
+
* For Imagen 3 models, the default value is `true`; see the <a href="http://firebase.google.com/docs/vertex-ai/model-parameters#imagen">addWatermark</a>
|
|
90
|
+
* documentation for more details.
|
|
91
|
+
*
|
|
92
|
+
* When using the Gemini Developer API ({@link GoogleAIBackend}), this will default to true,
|
|
93
|
+
* and cannot be turned off.
|
|
94
|
+
*/
|
|
95
|
+
addWatermark?: boolean;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* A filter level controlling how aggressively to filter sensitive content.
|
|
99
|
+
*
|
|
100
|
+
* Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI
|
|
101
|
+
* are assessed against a list of safety filters, which include 'harmful categories' (for example,
|
|
102
|
+
* `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to
|
|
103
|
+
* filter out potentially harmful content from responses. See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
|
104
|
+
* and the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters | Responsible AI and usage guidelines}
|
|
105
|
+
* for more details.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare const ImagenSafetyFilterLevel: {
|
|
110
|
+
/**
|
|
111
|
+
* The most aggressive filtering level; most strict blocking.
|
|
112
|
+
*/
|
|
113
|
+
readonly BLOCK_LOW_AND_ABOVE: "block_low_and_above";
|
|
114
|
+
/**
|
|
115
|
+
* Blocks some sensitive prompts and responses.
|
|
116
|
+
*/
|
|
117
|
+
readonly BLOCK_MEDIUM_AND_ABOVE: "block_medium_and_above";
|
|
118
|
+
/**
|
|
119
|
+
* Blocks few sensitive prompts and responses.
|
|
120
|
+
*/
|
|
121
|
+
readonly BLOCK_ONLY_HIGH: "block_only_high";
|
|
122
|
+
/**
|
|
123
|
+
* The least aggressive filtering level; blocks very few sensitive prompts and responses.
|
|
124
|
+
*
|
|
125
|
+
* Access to this feature is restricted and may require your case to be reviewed and approved by
|
|
126
|
+
* Cloud support.
|
|
127
|
+
*/
|
|
128
|
+
readonly BLOCK_NONE: "block_none";
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* A filter level controlling how aggressively to filter sensitive content.
|
|
132
|
+
*
|
|
133
|
+
* Text prompts provided as inputs and images (generated or uploaded) through Imagen on Vertex AI
|
|
134
|
+
* are assessed against a list of safety filters, which include 'harmful categories' (for example,
|
|
135
|
+
* `violence`, `sexual`, `derogatory`, and `toxic`). This filter level controls how aggressively to
|
|
136
|
+
* filter out potentially harmful content from responses. See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
|
137
|
+
* and the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#safety-filters | Responsible AI and usage guidelines}
|
|
138
|
+
* for more details.
|
|
139
|
+
*
|
|
140
|
+
* @public
|
|
141
|
+
*/
|
|
142
|
+
export type ImagenSafetyFilterLevel = (typeof ImagenSafetyFilterLevel)[keyof typeof ImagenSafetyFilterLevel];
|
|
143
|
+
/**
|
|
144
|
+
* A filter level controlling whether generation of images containing people or faces is allowed.
|
|
145
|
+
*
|
|
146
|
+
* See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a>
|
|
147
|
+
* documentation for more details.
|
|
148
|
+
*
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
export declare const ImagenPersonFilterLevel: {
|
|
152
|
+
/**
|
|
153
|
+
* Disallow generation of images containing people or faces; images of people are filtered out.
|
|
154
|
+
*/
|
|
155
|
+
readonly BLOCK_ALL: "dont_allow";
|
|
156
|
+
/**
|
|
157
|
+
* Allow generation of images containing adults only; images of children are filtered out.
|
|
158
|
+
*
|
|
159
|
+
* Generation of images containing people or faces may require your use case to be
|
|
160
|
+
* reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines}
|
|
161
|
+
* for more details.
|
|
162
|
+
*/
|
|
163
|
+
readonly ALLOW_ADULT: "allow_adult";
|
|
164
|
+
/**
|
|
165
|
+
* Allow generation of images containing adults only; images of children are filtered out.
|
|
166
|
+
*
|
|
167
|
+
* Generation of images containing people or faces may require your use case to be
|
|
168
|
+
* reviewed and approved by Cloud support; see the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen#person-face-gen | Responsible AI and usage guidelines}
|
|
169
|
+
* for more details.
|
|
170
|
+
*/
|
|
171
|
+
readonly ALLOW_ALL: "allow_all";
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* A filter level controlling whether generation of images containing people or faces is allowed.
|
|
175
|
+
*
|
|
176
|
+
* See the <a href="http://firebase.google.com/docs/vertex-ai/generate-images">personGeneration</a>
|
|
177
|
+
* documentation for more details.
|
|
178
|
+
*
|
|
179
|
+
* @public
|
|
180
|
+
*/
|
|
181
|
+
export type ImagenPersonFilterLevel = (typeof ImagenPersonFilterLevel)[keyof typeof ImagenPersonFilterLevel];
|
|
182
|
+
/**
|
|
183
|
+
* Settings for controlling the aggressiveness of filtering out sensitive content.
|
|
184
|
+
*
|
|
185
|
+
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
|
186
|
+
* for more details.
|
|
187
|
+
*
|
|
188
|
+
* @public
|
|
189
|
+
*/
|
|
190
|
+
export interface ImagenSafetySettings {
|
|
191
|
+
/**
|
|
192
|
+
* A filter level controlling how aggressive to filter out sensitive content from generated
|
|
193
|
+
* images.
|
|
194
|
+
*/
|
|
195
|
+
safetyFilterLevel?: ImagenSafetyFilterLevel;
|
|
196
|
+
/**
|
|
197
|
+
* A filter level controlling whether generation of images containing people or faces is allowed.
|
|
198
|
+
*/
|
|
199
|
+
personFilterLevel?: ImagenPersonFilterLevel;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Aspect ratios for Imagen images.
|
|
203
|
+
*
|
|
204
|
+
* To specify an aspect ratio for generated images, set the `aspectRatio` property in your
|
|
205
|
+
* {@link ImagenGenerationConfig}.
|
|
206
|
+
*
|
|
207
|
+
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
|
208
|
+
* for more details and examples of the supported aspect ratios.
|
|
209
|
+
*
|
|
210
|
+
* @public
|
|
211
|
+
*/
|
|
212
|
+
export declare const ImagenAspectRatio: {
|
|
213
|
+
/**
|
|
214
|
+
* Square (1:1) aspect ratio.
|
|
215
|
+
*/
|
|
216
|
+
readonly SQUARE: "1:1";
|
|
217
|
+
/**
|
|
218
|
+
* Landscape (3:4) aspect ratio.
|
|
219
|
+
*/
|
|
220
|
+
readonly LANDSCAPE_3x4: "3:4";
|
|
221
|
+
/**
|
|
222
|
+
* Portrait (4:3) aspect ratio.
|
|
223
|
+
*/
|
|
224
|
+
readonly PORTRAIT_4x3: "4:3";
|
|
225
|
+
/**
|
|
226
|
+
* Landscape (16:9) aspect ratio.
|
|
227
|
+
*/
|
|
228
|
+
readonly LANDSCAPE_16x9: "16:9";
|
|
229
|
+
/**
|
|
230
|
+
* Portrait (9:16) aspect ratio.
|
|
231
|
+
*/
|
|
232
|
+
readonly PORTRAIT_9x16: "9:16";
|
|
233
|
+
};
|
|
234
|
+
/**
|
|
235
|
+
* Aspect ratios for Imagen images.
|
|
236
|
+
*
|
|
237
|
+
* To specify an aspect ratio for generated images, set the `aspectRatio` property in your
|
|
238
|
+
* {@link ImagenGenerationConfig}.
|
|
239
|
+
*
|
|
240
|
+
* See the {@link http://firebase.google.com/docs/vertex-ai/generate-images | documentation }
|
|
241
|
+
* for more details and examples of the supported aspect ratios.
|
|
242
|
+
*
|
|
243
|
+
* @public
|
|
244
|
+
*/
|
|
245
|
+
export type ImagenAspectRatio = (typeof ImagenAspectRatio)[keyof typeof ImagenAspectRatio];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* An image generated by Imagen, represented as inline data.
|
|
19
|
+
*
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export interface ImagenInlineImage {
|
|
23
|
+
/**
|
|
24
|
+
* The MIME type of the image; either `"image/png"` or `"image/jpeg"`.
|
|
25
|
+
*
|
|
26
|
+
* To request a different format, set the `imageFormat` property in your {@link ImagenGenerationConfig}.
|
|
27
|
+
*/
|
|
28
|
+
mimeType: string;
|
|
29
|
+
/**
|
|
30
|
+
* The base64-encoded image data.
|
|
31
|
+
*/
|
|
32
|
+
bytesBase64Encoded: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* An image generated by Imagen, stored in a Cloud Storage for Firebase bucket.
|
|
36
|
+
*
|
|
37
|
+
* This feature is not available yet.
|
|
38
|
+
* @public
|
|
39
|
+
*/
|
|
40
|
+
export interface ImagenGCSImage {
|
|
41
|
+
/**
|
|
42
|
+
* The MIME type of the image; either `"image/png"` or `"image/jpeg"`.
|
|
43
|
+
*
|
|
44
|
+
* To request a different format, set the `imageFormat` property in your {@link ImagenGenerationConfig}.
|
|
45
|
+
*/
|
|
46
|
+
mimeType: string;
|
|
47
|
+
/**
|
|
48
|
+
* The URI of the file stored in a Cloud Storage for Firebase bucket.
|
|
49
|
+
*
|
|
50
|
+
* @example `"gs://bucket-name/path/sample_0.jpg"`.
|
|
51
|
+
*/
|
|
52
|
+
gcsURI: string;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The response from a request to generate images with Imagen.
|
|
56
|
+
*
|
|
57
|
+
* @public
|
|
58
|
+
*/
|
|
59
|
+
export interface ImagenGenerationResponse<T extends ImagenInlineImage | ImagenGCSImage> {
|
|
60
|
+
/**
|
|
61
|
+
* The images generated by Imagen.
|
|
62
|
+
*
|
|
63
|
+
* The number of images generated may be fewer than the number requested if one or more were
|
|
64
|
+
* filtered out; see `filteredReason`.
|
|
65
|
+
*/
|
|
66
|
+
images: T[];
|
|
67
|
+
/**
|
|
68
|
+
* The reason that images were filtered out. This property will only be defined if one
|
|
69
|
+
* or more images were filtered.
|
|
70
|
+
*
|
|
71
|
+
* Images may be filtered out due to the {@link (ImagenSafetyFilterLevel:type)},
|
|
72
|
+
* {@link (ImagenPersonFilterLevel:type)}, or filtering included in the model.
|
|
73
|
+
* The filter levels may be adjusted in your {@link ImagenSafetySettings}.
|
|
74
|
+
*
|
|
75
|
+
* See the {@link https://cloud.google.com/vertex-ai/generative-ai/docs/image/responsible-ai-imagen | Responsible AI and usage guidelines for Imagen}
|
|
76
|
+
* for more details.
|
|
77
|
+
*/
|
|
78
|
+
filteredReason?: string;
|
|
79
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2024 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
export * from './content';
|
|
18
|
+
export * from './enums';
|
|
19
|
+
export * from './requests';
|
|
20
|
+
export * from './responses';
|
|
21
|
+
export * from './error';
|
|
22
|
+
export * from './schema';
|
|
23
|
+
export * from './imagen';
|
|
24
|
+
export * from './googleai';
|
|
25
|
+
export { LanguageModelCreateOptions, LanguageModelCreateCoreOptions, LanguageModelExpected, LanguageModelMessage, LanguageModelMessageContent, LanguageModelMessageContentValue, LanguageModelMessageRole, LanguageModelMessageType, LanguageModelPromptOptions } from './language-model';
|
|
26
|
+
export * from './chrome-adapter';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2024 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
import { AppCheckTokenResult } from '@firebase/app-check-interop-types';
|
|
18
|
+
import { FirebaseAuthTokenData } from '@firebase/auth-interop-types';
|
|
19
|
+
import { Backend } from '../backend';
|
|
20
|
+
import { InferenceMode } from './enums';
|
|
21
|
+
export * from './imagen/internal';
|
|
22
|
+
export interface ApiSettings {
|
|
23
|
+
apiKey: string;
|
|
24
|
+
project: string;
|
|
25
|
+
appId: string;
|
|
26
|
+
automaticDataCollectionEnabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated Use `backend.location` instead.
|
|
29
|
+
*/
|
|
30
|
+
location: string;
|
|
31
|
+
backend: Backend;
|
|
32
|
+
getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
|
|
33
|
+
getAppCheckToken?: () => Promise<AppCheckTokenResult>;
|
|
34
|
+
inferenceMode?: InferenceMode;
|
|
35
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* The subset of the Prompt API
|
|
19
|
+
* (see {@link https://github.com/webmachinelearning/prompt-api#full-api-surface-in-web-idl }
|
|
20
|
+
* required for hybrid functionality.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface LanguageModel extends EventTarget {
|
|
25
|
+
create(options?: LanguageModelCreateOptions): Promise<LanguageModel>;
|
|
26
|
+
availability(options?: LanguageModelCreateCoreOptions): Promise<Availability>;
|
|
27
|
+
prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise<string>;
|
|
28
|
+
promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream;
|
|
29
|
+
measureInputUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise<number>;
|
|
30
|
+
destroy(): undefined;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export declare enum Availability {
|
|
36
|
+
'UNAVAILABLE' = "unavailable",
|
|
37
|
+
'DOWNLOADABLE' = "downloadable",
|
|
38
|
+
'DOWNLOADING' = "downloading",
|
|
39
|
+
'AVAILABLE' = "available"
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Configures the creation of an on-device language model session.
|
|
43
|
+
* @beta
|
|
44
|
+
*/
|
|
45
|
+
export interface LanguageModelCreateCoreOptions {
|
|
46
|
+
topK?: number;
|
|
47
|
+
temperature?: number;
|
|
48
|
+
expectedInputs?: LanguageModelExpected[];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Configures the creation of an on-device language model session.
|
|
52
|
+
* @beta
|
|
53
|
+
*/
|
|
54
|
+
export interface LanguageModelCreateOptions extends LanguageModelCreateCoreOptions {
|
|
55
|
+
signal?: AbortSignal;
|
|
56
|
+
initialPrompts?: LanguageModelMessage[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options for an on-device language model prompt.
|
|
60
|
+
* @beta
|
|
61
|
+
*/
|
|
62
|
+
export interface LanguageModelPromptOptions {
|
|
63
|
+
responseConstraint?: object;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Options for the expected inputs for an on-device language model.
|
|
67
|
+
* @beta
|
|
68
|
+
*/ export interface LanguageModelExpected {
|
|
69
|
+
type: LanguageModelMessageType;
|
|
70
|
+
languages?: string[];
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* An on-device language model prompt.
|
|
74
|
+
* @beta
|
|
75
|
+
*/
|
|
76
|
+
export type LanguageModelPrompt = LanguageModelMessage[];
|
|
77
|
+
/**
|
|
78
|
+
* An on-device language model message.
|
|
79
|
+
* @beta
|
|
80
|
+
*/
|
|
81
|
+
export interface LanguageModelMessage {
|
|
82
|
+
role: LanguageModelMessageRole;
|
|
83
|
+
content: LanguageModelMessageContent[];
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* An on-device language model content object.
|
|
87
|
+
* @beta
|
|
88
|
+
*/
|
|
89
|
+
export interface LanguageModelMessageContent {
|
|
90
|
+
type: LanguageModelMessageType;
|
|
91
|
+
value: LanguageModelMessageContentValue;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Allowable roles for on-device language model usage.
|
|
95
|
+
* @beta
|
|
96
|
+
*/
|
|
97
|
+
export type LanguageModelMessageRole = 'system' | 'user' | 'assistant';
|
|
98
|
+
/**
|
|
99
|
+
* Allowable types for on-device language model messages.
|
|
100
|
+
* @beta
|
|
101
|
+
*/
|
|
102
|
+
export type LanguageModelMessageType = 'text' | 'image' | 'audio';
|
|
103
|
+
/**
|
|
104
|
+
* Content formats that can be provided as on-device message content.
|
|
105
|
+
* @beta
|
|
106
|
+
*/
|
|
107
|
+
export type LanguageModelMessageContentValue = ImageBitmapSource | AudioBuffer | BufferSource | string;
|