@firebase/ai 0.0.1
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 +5 -0
- package/dist/ai-public.d.ts +1972 -0
- package/dist/ai.d.ts +2073 -0
- package/dist/esm/index.esm2017.js +2624 -0
- package/dist/esm/index.esm2017.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/src/api.d.ts +120 -0
- package/dist/esm/src/backend.d.ts +74 -0
- package/dist/esm/src/constants.d.ts +23 -0
- package/dist/esm/src/errors.d.ts +35 -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 +12 -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 +50 -0
- package/dist/esm/src/methods/count-tokens.d.ts +19 -0
- package/dist/esm/src/methods/generate-content.d.ts +20 -0
- package/dist/esm/src/models/ai-model.d.ts +72 -0
- package/dist/esm/src/models/generative-model.d.ts +54 -0
- package/dist/esm/src/models/imagen-model.d.ts +102 -0
- package/dist/esm/src/models/index.d.ts +19 -0
- package/dist/esm/src/public-types.d.ts +106 -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 +43 -0
- package/dist/esm/src/requests/response-helpers.d.ts +53 -0
- package/dist/esm/src/requests/schema-builder.d.ts +145 -0
- package/dist/esm/src/requests/stream-reader.d.ts +38 -0
- package/dist/esm/src/service.d.ts +31 -0
- package/dist/esm/src/types/content.d.ts +144 -0
- package/dist/esm/src/types/enums.d.ts +263 -0
- package/dist/esm/src/types/error.d.ts +81 -0
- package/dist/esm/src/types/googleai.d.ts +56 -0
- package/dist/esm/src/types/imagen/index.d.ts +18 -0
- package/dist/esm/src/types/imagen/internal.d.ts +124 -0
- package/dist/esm/src/types/imagen/requests.d.ts +211 -0
- package/dist/esm/src/types/imagen/responses.d.ts +78 -0
- package/dist/esm/src/types/index.d.ts +24 -0
- package/dist/esm/src/types/internal.d.ts +33 -0
- package/dist/esm/src/types/requests.d.ts +213 -0
- package/dist/esm/src/types/responses.d.ts +257 -0
- package/dist/esm/src/types/schema.d.ts +102 -0
- package/dist/index.cjs.js +2652 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.node.cjs.js +2652 -0
- package/dist/index.node.cjs.js.map +1 -0
- package/dist/index.node.mjs +2624 -0
- package/dist/index.node.mjs.map +1 -0
- package/dist/src/api.d.ts +120 -0
- package/dist/src/backend.d.ts +74 -0
- package/dist/src/constants.d.ts +23 -0
- package/dist/src/errors.d.ts +35 -0
- package/dist/src/googleai-mappers.d.ts +73 -0
- package/dist/src/helpers.d.ts +30 -0
- package/dist/src/index.d.ts +12 -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 +50 -0
- package/dist/src/methods/count-tokens.d.ts +19 -0
- package/dist/src/methods/generate-content.d.ts +20 -0
- package/dist/src/models/ai-model.d.ts +72 -0
- package/dist/src/models/generative-model.d.ts +54 -0
- package/dist/src/models/imagen-model.d.ts +102 -0
- package/dist/src/models/index.d.ts +19 -0
- package/dist/src/public-types.d.ts +106 -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 +43 -0
- package/dist/src/requests/response-helpers.d.ts +53 -0
- package/dist/src/requests/schema-builder.d.ts +145 -0
- package/dist/src/requests/stream-reader.d.ts +38 -0
- package/dist/src/service.d.ts +31 -0
- package/dist/src/tsdoc-metadata.json +11 -0
- package/dist/src/types/content.d.ts +144 -0
- package/dist/src/types/enums.d.ts +263 -0
- package/dist/src/types/error.d.ts +81 -0
- package/dist/src/types/googleai.d.ts +56 -0
- package/dist/src/types/imagen/index.d.ts +18 -0
- package/dist/src/types/imagen/internal.d.ts +124 -0
- package/dist/src/types/imagen/requests.d.ts +211 -0
- package/dist/src/types/imagen/responses.d.ts +78 -0
- package/dist/src/types/index.d.ts +24 -0
- package/dist/src/types/internal.d.ts +33 -0
- package/dist/src/types/requests.d.ts +213 -0
- package/dist/src/types/responses.d.ts +257 -0
- package/dist/src/types/schema.d.ts +102 -0
- package/package.json +81 -0
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
/**
|
|
18
|
+
* Role is the producer of the content.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export type Role = (typeof POSSIBLE_ROLES)[number];
|
|
22
|
+
/**
|
|
23
|
+
* Possible roles.
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
export declare const POSSIBLE_ROLES: readonly ["user", "model", "function", "system"];
|
|
27
|
+
/**
|
|
28
|
+
* Harm categories that would cause prompts or candidates to be blocked.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare enum HarmCategory {
|
|
32
|
+
HARM_CATEGORY_HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH",
|
|
33
|
+
HARM_CATEGORY_SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
|
34
|
+
HARM_CATEGORY_HARASSMENT = "HARM_CATEGORY_HARASSMENT",
|
|
35
|
+
HARM_CATEGORY_DANGEROUS_CONTENT = "HARM_CATEGORY_DANGEROUS_CONTENT"
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Threshold above which a prompt or candidate will be blocked.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
export declare enum HarmBlockThreshold {
|
|
42
|
+
/**
|
|
43
|
+
* Content with `NEGLIGIBLE` will be allowed.
|
|
44
|
+
*/
|
|
45
|
+
BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE",
|
|
46
|
+
/**
|
|
47
|
+
* Content with `NEGLIGIBLE` and `LOW` will be allowed.
|
|
48
|
+
*/
|
|
49
|
+
BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE",
|
|
50
|
+
/**
|
|
51
|
+
* Content with `NEGLIGIBLE`, `LOW`, and `MEDIUM` will be allowed.
|
|
52
|
+
*/
|
|
53
|
+
BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH",
|
|
54
|
+
/**
|
|
55
|
+
* All content will be allowed.
|
|
56
|
+
*/
|
|
57
|
+
BLOCK_NONE = "BLOCK_NONE"
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* This property is not supported in the Gemini Developer API ({@link GoogleAIBackend}).
|
|
61
|
+
*
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export declare enum HarmBlockMethod {
|
|
65
|
+
/**
|
|
66
|
+
* The harm block method uses both probability and severity scores.
|
|
67
|
+
*/
|
|
68
|
+
SEVERITY = "SEVERITY",
|
|
69
|
+
/**
|
|
70
|
+
* The harm block method uses the probability score.
|
|
71
|
+
*/
|
|
72
|
+
PROBABILITY = "PROBABILITY"
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Probability that a prompt or candidate matches a harm category.
|
|
76
|
+
* @public
|
|
77
|
+
*/
|
|
78
|
+
export declare enum HarmProbability {
|
|
79
|
+
/**
|
|
80
|
+
* Content has a negligible chance of being unsafe.
|
|
81
|
+
*/
|
|
82
|
+
NEGLIGIBLE = "NEGLIGIBLE",
|
|
83
|
+
/**
|
|
84
|
+
* Content has a low chance of being unsafe.
|
|
85
|
+
*/
|
|
86
|
+
LOW = "LOW",
|
|
87
|
+
/**
|
|
88
|
+
* Content has a medium chance of being unsafe.
|
|
89
|
+
*/
|
|
90
|
+
MEDIUM = "MEDIUM",
|
|
91
|
+
/**
|
|
92
|
+
* Content has a high chance of being unsafe.
|
|
93
|
+
*/
|
|
94
|
+
HIGH = "HIGH"
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Harm severity levels.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
export declare enum HarmSeverity {
|
|
101
|
+
/**
|
|
102
|
+
* Negligible level of harm severity.
|
|
103
|
+
*/
|
|
104
|
+
HARM_SEVERITY_NEGLIGIBLE = "HARM_SEVERITY_NEGLIGIBLE",
|
|
105
|
+
/**
|
|
106
|
+
* Low level of harm severity.
|
|
107
|
+
*/
|
|
108
|
+
HARM_SEVERITY_LOW = "HARM_SEVERITY_LOW",
|
|
109
|
+
/**
|
|
110
|
+
* Medium level of harm severity.
|
|
111
|
+
*/
|
|
112
|
+
HARM_SEVERITY_MEDIUM = "HARM_SEVERITY_MEDIUM",
|
|
113
|
+
/**
|
|
114
|
+
* High level of harm severity.
|
|
115
|
+
*/
|
|
116
|
+
HARM_SEVERITY_HIGH = "HARM_SEVERITY_HIGH",
|
|
117
|
+
/**
|
|
118
|
+
* Harm severity is not supported.
|
|
119
|
+
*
|
|
120
|
+
* @remarks
|
|
121
|
+
* The GoogleAI backend does not support `HarmSeverity`, so this value is used as a fallback.
|
|
122
|
+
*/
|
|
123
|
+
HARM_SEVERITY_UNSUPPORTED = "HARM_SEVERITY_UNSUPPORTED"
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Reason that a prompt was blocked.
|
|
127
|
+
* @public
|
|
128
|
+
*/
|
|
129
|
+
export declare enum BlockReason {
|
|
130
|
+
/**
|
|
131
|
+
* Content was blocked by safety settings.
|
|
132
|
+
*/
|
|
133
|
+
SAFETY = "SAFETY",
|
|
134
|
+
/**
|
|
135
|
+
* Content was blocked, but the reason is uncategorized.
|
|
136
|
+
*/
|
|
137
|
+
OTHER = "OTHER",
|
|
138
|
+
/**
|
|
139
|
+
* Content was blocked because it contained terms from the terminology blocklist.
|
|
140
|
+
*/
|
|
141
|
+
BLOCKLIST = "BLOCKLIST",
|
|
142
|
+
/**
|
|
143
|
+
* Content was blocked due to prohibited content.
|
|
144
|
+
*/
|
|
145
|
+
PROHIBITED_CONTENT = "PROHIBITED_CONTENT"
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Reason that a candidate finished.
|
|
149
|
+
* @public
|
|
150
|
+
*/
|
|
151
|
+
export declare enum FinishReason {
|
|
152
|
+
/**
|
|
153
|
+
* Natural stop point of the model or provided stop sequence.
|
|
154
|
+
*/
|
|
155
|
+
STOP = "STOP",
|
|
156
|
+
/**
|
|
157
|
+
* The maximum number of tokens as specified in the request was reached.
|
|
158
|
+
*/
|
|
159
|
+
MAX_TOKENS = "MAX_TOKENS",
|
|
160
|
+
/**
|
|
161
|
+
* The candidate content was flagged for safety reasons.
|
|
162
|
+
*/
|
|
163
|
+
SAFETY = "SAFETY",
|
|
164
|
+
/**
|
|
165
|
+
* The candidate content was flagged for recitation reasons.
|
|
166
|
+
*/
|
|
167
|
+
RECITATION = "RECITATION",
|
|
168
|
+
/**
|
|
169
|
+
* Unknown reason.
|
|
170
|
+
*/
|
|
171
|
+
OTHER = "OTHER",
|
|
172
|
+
/**
|
|
173
|
+
* The candidate content contained forbidden terms.
|
|
174
|
+
*/
|
|
175
|
+
BLOCKLIST = "BLOCKLIST",
|
|
176
|
+
/**
|
|
177
|
+
* The candidate content potentially contained prohibited content.
|
|
178
|
+
*/
|
|
179
|
+
PROHIBITED_CONTENT = "PROHIBITED_CONTENT",
|
|
180
|
+
/**
|
|
181
|
+
* The candidate content potentially contained Sensitive Personally Identifiable Information (SPII).
|
|
182
|
+
*/
|
|
183
|
+
SPII = "SPII",
|
|
184
|
+
/**
|
|
185
|
+
* The function call generated by the model was invalid.
|
|
186
|
+
*/
|
|
187
|
+
MALFORMED_FUNCTION_CALL = "MALFORMED_FUNCTION_CALL"
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @public
|
|
191
|
+
*/
|
|
192
|
+
export declare enum FunctionCallingMode {
|
|
193
|
+
/**
|
|
194
|
+
* Default model behavior; model decides to predict either a function call
|
|
195
|
+
* or a natural language response.
|
|
196
|
+
*/
|
|
197
|
+
AUTO = "AUTO",
|
|
198
|
+
/**
|
|
199
|
+
* Model is constrained to always predicting a function call only.
|
|
200
|
+
* If `allowed_function_names` is set, the predicted function call will be
|
|
201
|
+
* limited to any one of `allowed_function_names`, else the predicted
|
|
202
|
+
* function call will be any one of the provided `function_declarations`.
|
|
203
|
+
*/
|
|
204
|
+
ANY = "ANY",
|
|
205
|
+
/**
|
|
206
|
+
* Model will not predict any function call. Model behavior is same as when
|
|
207
|
+
* not passing any function declarations.
|
|
208
|
+
*/
|
|
209
|
+
NONE = "NONE"
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Content part modality.
|
|
213
|
+
* @public
|
|
214
|
+
*/
|
|
215
|
+
export declare enum Modality {
|
|
216
|
+
/**
|
|
217
|
+
* Unspecified modality.
|
|
218
|
+
*/
|
|
219
|
+
MODALITY_UNSPECIFIED = "MODALITY_UNSPECIFIED",
|
|
220
|
+
/**
|
|
221
|
+
* Plain text.
|
|
222
|
+
*/
|
|
223
|
+
TEXT = "TEXT",
|
|
224
|
+
/**
|
|
225
|
+
* Image.
|
|
226
|
+
*/
|
|
227
|
+
IMAGE = "IMAGE",
|
|
228
|
+
/**
|
|
229
|
+
* Video.
|
|
230
|
+
*/
|
|
231
|
+
VIDEO = "VIDEO",
|
|
232
|
+
/**
|
|
233
|
+
* Audio.
|
|
234
|
+
*/
|
|
235
|
+
AUDIO = "AUDIO",
|
|
236
|
+
/**
|
|
237
|
+
* Document (for example, PDF).
|
|
238
|
+
*/
|
|
239
|
+
DOCUMENT = "DOCUMENT"
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Generation modalities to be returned in generation responses.
|
|
243
|
+
*
|
|
244
|
+
* @beta
|
|
245
|
+
*/
|
|
246
|
+
export declare const ResponseModality: {
|
|
247
|
+
/**
|
|
248
|
+
* Text.
|
|
249
|
+
* @beta
|
|
250
|
+
*/
|
|
251
|
+
readonly TEXT: "TEXT";
|
|
252
|
+
/**
|
|
253
|
+
* Image.
|
|
254
|
+
* @beta
|
|
255
|
+
*/
|
|
256
|
+
readonly IMAGE: "IMAGE";
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Generation modalities to be returned in generation responses.
|
|
260
|
+
*
|
|
261
|
+
* @beta
|
|
262
|
+
*/
|
|
263
|
+
export type ResponseModality = (typeof ResponseModality)[keyof typeof ResponseModality];
|
|
@@ -0,0 +1,81 @@
|
|
|
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 { GenerateContentResponse } from './responses';
|
|
18
|
+
/**
|
|
19
|
+
* Details object that may be included in an error response.
|
|
20
|
+
*
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export interface ErrorDetails {
|
|
24
|
+
'@type'?: string;
|
|
25
|
+
/** The reason for the error. */
|
|
26
|
+
reason?: string;
|
|
27
|
+
/** The domain where the error occurred. */
|
|
28
|
+
domain?: string;
|
|
29
|
+
/** Additional metadata about the error. */
|
|
30
|
+
metadata?: Record<string, unknown>;
|
|
31
|
+
/** Any other relevant information about the error. */
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Details object that contains data originating from a bad HTTP response.
|
|
36
|
+
*
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export interface CustomErrorData {
|
|
40
|
+
/** HTTP status code of the error response. */
|
|
41
|
+
status?: number;
|
|
42
|
+
/** HTTP status text of the error response. */
|
|
43
|
+
statusText?: string;
|
|
44
|
+
/** Response from a {@link GenerateContentRequest} */
|
|
45
|
+
response?: GenerateContentResponse;
|
|
46
|
+
/** Optional additional details about the error. */
|
|
47
|
+
errorDetails?: ErrorDetails[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Standardized error codes that {@link AIError} can have.
|
|
51
|
+
*
|
|
52
|
+
* @public
|
|
53
|
+
*/
|
|
54
|
+
export declare const enum AIErrorCode {
|
|
55
|
+
/** A generic error occurred. */
|
|
56
|
+
ERROR = "error",
|
|
57
|
+
/** An error occurred in a request. */
|
|
58
|
+
REQUEST_ERROR = "request-error",
|
|
59
|
+
/** An error occurred in a response. */
|
|
60
|
+
RESPONSE_ERROR = "response-error",
|
|
61
|
+
/** An error occurred while performing a fetch. */
|
|
62
|
+
FETCH_ERROR = "fetch-error",
|
|
63
|
+
/** An error associated with a Content object. */
|
|
64
|
+
INVALID_CONTENT = "invalid-content",
|
|
65
|
+
/** An error due to the Firebase API not being enabled in the Console. */
|
|
66
|
+
API_NOT_ENABLED = "api-not-enabled",
|
|
67
|
+
/** An error due to invalid Schema input. */
|
|
68
|
+
INVALID_SCHEMA = "invalid-schema",
|
|
69
|
+
/** An error occurred due to a missing Firebase API key. */
|
|
70
|
+
NO_API_KEY = "no-api-key",
|
|
71
|
+
/** An error occured due to a missing Firebase app ID. */
|
|
72
|
+
NO_APP_ID = "no-app-id",
|
|
73
|
+
/** An error occurred due to a model name not being specified during initialization. */
|
|
74
|
+
NO_MODEL = "no-model",
|
|
75
|
+
/** An error occurred due to a missing project ID. */
|
|
76
|
+
NO_PROJECT_ID = "no-project-id",
|
|
77
|
+
/** An error occurred while parsing. */
|
|
78
|
+
PARSE_FAILED = "parse-failed",
|
|
79
|
+
/** An error occured due an attempt to use an unsupported feature. */
|
|
80
|
+
UNSUPPORTED = "unsupported"
|
|
81
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 { Tool, GenerationConfig, Citation, FinishReason, GroundingMetadata, PromptFeedback, SafetyRating, UsageMetadata } from '../public-types';
|
|
18
|
+
import { Content, Part } from './content';
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export interface GoogleAICountTokensRequest {
|
|
23
|
+
generateContentRequest: {
|
|
24
|
+
model: string;
|
|
25
|
+
contents: Content[];
|
|
26
|
+
systemInstruction?: string | Part | Content;
|
|
27
|
+
tools?: Tool[];
|
|
28
|
+
generationConfig?: GenerationConfig;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
34
|
+
export interface GoogleAIGenerateContentResponse {
|
|
35
|
+
candidates?: GoogleAIGenerateContentCandidate[];
|
|
36
|
+
promptFeedback?: PromptFeedback;
|
|
37
|
+
usageMetadata?: UsageMetadata;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @internal
|
|
41
|
+
*/
|
|
42
|
+
export interface GoogleAIGenerateContentCandidate {
|
|
43
|
+
index: number;
|
|
44
|
+
content: Content;
|
|
45
|
+
finishReason?: FinishReason;
|
|
46
|
+
finishMessage?: string;
|
|
47
|
+
safetyRatings?: SafetyRating[];
|
|
48
|
+
citationMetadata?: GoogleAICitationMetadata;
|
|
49
|
+
groundingMetadata?: GroundingMetadata;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export interface GoogleAICitationMetadata {
|
|
55
|
+
citationSources: Citation[];
|
|
56
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export * from './requests';
|
|
18
|
+
export * from './responses';
|
|
@@ -0,0 +1,124 @@
|
|
|
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
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The parameters to be sent in the request body of the HTTP call
|
|
66
|
+
* to the Vertex AI backend.
|
|
67
|
+
*
|
|
68
|
+
* We need a seperate internal-only interface for this because the REST
|
|
69
|
+
* API expects different parameter names than what we show to our users.
|
|
70
|
+
*
|
|
71
|
+
* Sample request body JSON:
|
|
72
|
+
* {
|
|
73
|
+
* "instances": [
|
|
74
|
+
* {
|
|
75
|
+
* "prompt": "Portrait of a golden retriever on a beach."
|
|
76
|
+
* }
|
|
77
|
+
* ],
|
|
78
|
+
* "parameters": {
|
|
79
|
+
* "mimeType": "image/png",
|
|
80
|
+
* "safetyFilterLevel": "block_low_and_above",
|
|
81
|
+
* "personGeneration": "allow_all",
|
|
82
|
+
* "sampleCount": 2,
|
|
83
|
+
* "includeRaiReason": true,
|
|
84
|
+
* "aspectRatio": "9:16"
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
*
|
|
88
|
+
* See the Google Cloud docs: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/imagen-api#-drest
|
|
89
|
+
*
|
|
90
|
+
* @internal
|
|
91
|
+
*/
|
|
92
|
+
export interface PredictRequestBody {
|
|
93
|
+
instances: [
|
|
94
|
+
{
|
|
95
|
+
prompt: string;
|
|
96
|
+
}
|
|
97
|
+
];
|
|
98
|
+
parameters: {
|
|
99
|
+
sampleCount: number;
|
|
100
|
+
aspectRatio?: string;
|
|
101
|
+
outputOptions?: {
|
|
102
|
+
mimeType: string;
|
|
103
|
+
compressionQuality?: number;
|
|
104
|
+
};
|
|
105
|
+
negativePrompt?: string;
|
|
106
|
+
storageUri?: string;
|
|
107
|
+
addWatermark?: boolean;
|
|
108
|
+
safetyFilterLevel?: string;
|
|
109
|
+
personGeneration?: string;
|
|
110
|
+
includeRaiReason: boolean;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Contains all possible REST API paramaters that are provided by the caller.
|
|
115
|
+
*
|
|
116
|
+
* @internal
|
|
117
|
+
*/
|
|
118
|
+
export type ImagenGenerationParams = {
|
|
119
|
+
/**
|
|
120
|
+
* The Cloud Storage for Firebase bucket URI where the images should be stored
|
|
121
|
+
* (for GCS requests only).
|
|
122
|
+
*/
|
|
123
|
+
gcsURI?: string;
|
|
124
|
+
} & ImagenGenerationConfig & ImagenSafetySettings;
|