@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.
Files changed (90) hide show
  1. package/README.md +5 -0
  2. package/dist/ai-public.d.ts +1972 -0
  3. package/dist/ai.d.ts +2073 -0
  4. package/dist/esm/index.esm2017.js +2624 -0
  5. package/dist/esm/index.esm2017.js.map +1 -0
  6. package/dist/esm/package.json +1 -0
  7. package/dist/esm/src/api.d.ts +120 -0
  8. package/dist/esm/src/backend.d.ts +74 -0
  9. package/dist/esm/src/constants.d.ts +23 -0
  10. package/dist/esm/src/errors.d.ts +35 -0
  11. package/dist/esm/src/googleai-mappers.d.ts +73 -0
  12. package/dist/esm/src/helpers.d.ts +30 -0
  13. package/dist/esm/src/index.d.ts +12 -0
  14. package/dist/esm/src/index.node.d.ts +7 -0
  15. package/dist/esm/src/logger.d.ts +18 -0
  16. package/dist/esm/src/methods/chat-session-helpers.d.ts +18 -0
  17. package/dist/esm/src/methods/chat-session.d.ts +50 -0
  18. package/dist/esm/src/methods/count-tokens.d.ts +19 -0
  19. package/dist/esm/src/methods/generate-content.d.ts +20 -0
  20. package/dist/esm/src/models/ai-model.d.ts +72 -0
  21. package/dist/esm/src/models/generative-model.d.ts +54 -0
  22. package/dist/esm/src/models/imagen-model.d.ts +102 -0
  23. package/dist/esm/src/models/index.d.ts +19 -0
  24. package/dist/esm/src/public-types.d.ts +106 -0
  25. package/dist/esm/src/requests/imagen-image-format.d.ts +61 -0
  26. package/dist/esm/src/requests/request-helpers.d.ts +28 -0
  27. package/dist/esm/src/requests/request.d.ts +43 -0
  28. package/dist/esm/src/requests/response-helpers.d.ts +53 -0
  29. package/dist/esm/src/requests/schema-builder.d.ts +145 -0
  30. package/dist/esm/src/requests/stream-reader.d.ts +38 -0
  31. package/dist/esm/src/service.d.ts +31 -0
  32. package/dist/esm/src/types/content.d.ts +144 -0
  33. package/dist/esm/src/types/enums.d.ts +263 -0
  34. package/dist/esm/src/types/error.d.ts +81 -0
  35. package/dist/esm/src/types/googleai.d.ts +56 -0
  36. package/dist/esm/src/types/imagen/index.d.ts +18 -0
  37. package/dist/esm/src/types/imagen/internal.d.ts +124 -0
  38. package/dist/esm/src/types/imagen/requests.d.ts +211 -0
  39. package/dist/esm/src/types/imagen/responses.d.ts +78 -0
  40. package/dist/esm/src/types/index.d.ts +24 -0
  41. package/dist/esm/src/types/internal.d.ts +33 -0
  42. package/dist/esm/src/types/requests.d.ts +213 -0
  43. package/dist/esm/src/types/responses.d.ts +257 -0
  44. package/dist/esm/src/types/schema.d.ts +102 -0
  45. package/dist/index.cjs.js +2652 -0
  46. package/dist/index.cjs.js.map +1 -0
  47. package/dist/index.node.cjs.js +2652 -0
  48. package/dist/index.node.cjs.js.map +1 -0
  49. package/dist/index.node.mjs +2624 -0
  50. package/dist/index.node.mjs.map +1 -0
  51. package/dist/src/api.d.ts +120 -0
  52. package/dist/src/backend.d.ts +74 -0
  53. package/dist/src/constants.d.ts +23 -0
  54. package/dist/src/errors.d.ts +35 -0
  55. package/dist/src/googleai-mappers.d.ts +73 -0
  56. package/dist/src/helpers.d.ts +30 -0
  57. package/dist/src/index.d.ts +12 -0
  58. package/dist/src/index.node.d.ts +7 -0
  59. package/dist/src/logger.d.ts +18 -0
  60. package/dist/src/methods/chat-session-helpers.d.ts +18 -0
  61. package/dist/src/methods/chat-session.d.ts +50 -0
  62. package/dist/src/methods/count-tokens.d.ts +19 -0
  63. package/dist/src/methods/generate-content.d.ts +20 -0
  64. package/dist/src/models/ai-model.d.ts +72 -0
  65. package/dist/src/models/generative-model.d.ts +54 -0
  66. package/dist/src/models/imagen-model.d.ts +102 -0
  67. package/dist/src/models/index.d.ts +19 -0
  68. package/dist/src/public-types.d.ts +106 -0
  69. package/dist/src/requests/imagen-image-format.d.ts +61 -0
  70. package/dist/src/requests/request-helpers.d.ts +28 -0
  71. package/dist/src/requests/request.d.ts +43 -0
  72. package/dist/src/requests/response-helpers.d.ts +53 -0
  73. package/dist/src/requests/schema-builder.d.ts +145 -0
  74. package/dist/src/requests/stream-reader.d.ts +38 -0
  75. package/dist/src/service.d.ts +31 -0
  76. package/dist/src/tsdoc-metadata.json +11 -0
  77. package/dist/src/types/content.d.ts +144 -0
  78. package/dist/src/types/enums.d.ts +263 -0
  79. package/dist/src/types/error.d.ts +81 -0
  80. package/dist/src/types/googleai.d.ts +56 -0
  81. package/dist/src/types/imagen/index.d.ts +18 -0
  82. package/dist/src/types/imagen/internal.d.ts +124 -0
  83. package/dist/src/types/imagen/requests.d.ts +211 -0
  84. package/dist/src/types/imagen/responses.d.ts +78 -0
  85. package/dist/src/types/index.d.ts +24 -0
  86. package/dist/src/types/internal.d.ts +33 -0
  87. package/dist/src/types/requests.d.ts +213 -0
  88. package/dist/src/types/responses.d.ts +257 -0
  89. package/dist/src/types/schema.d.ts +102 -0
  90. package/package.json +81 -0
@@ -0,0 +1,257 @@
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 { Content, FunctionCall, InlineDataPart } from './content';
18
+ import { BlockReason, FinishReason, HarmCategory, HarmProbability, HarmSeverity, Modality } from './enums';
19
+ /**
20
+ * Result object returned from {@link GenerativeModel.generateContent} call.
21
+ *
22
+ * @public
23
+ */
24
+ export interface GenerateContentResult {
25
+ response: EnhancedGenerateContentResponse;
26
+ }
27
+ /**
28
+ * Result object returned from {@link GenerativeModel.generateContentStream} call.
29
+ * Iterate over `stream` to get chunks as they come in and/or
30
+ * use the `response` promise to get the aggregated response when
31
+ * the stream is done.
32
+ *
33
+ * @public
34
+ */
35
+ export interface GenerateContentStreamResult {
36
+ stream: AsyncGenerator<EnhancedGenerateContentResponse>;
37
+ response: Promise<EnhancedGenerateContentResponse>;
38
+ }
39
+ /**
40
+ * Response object wrapped with helper methods.
41
+ *
42
+ * @public
43
+ */
44
+ export interface EnhancedGenerateContentResponse extends GenerateContentResponse {
45
+ /**
46
+ * Returns the text string from the response, if available.
47
+ * Throws if the prompt or candidate was blocked.
48
+ */
49
+ text: () => string;
50
+ /**
51
+ * Aggregates and returns all {@link InlineDataPart}s from the {@link GenerateContentResponse}'s
52
+ * first candidate.
53
+ *
54
+ * @returns An array of {@link InlineDataPart}s containing data from the response, if available.
55
+ *
56
+ * @throws If the prompt or candidate was blocked.
57
+ */
58
+ inlineDataParts: () => InlineDataPart[] | undefined;
59
+ functionCalls: () => FunctionCall[] | undefined;
60
+ }
61
+ /**
62
+ * Individual response from {@link GenerativeModel.generateContent} and
63
+ * {@link GenerativeModel.generateContentStream}.
64
+ * `generateContentStream()` will return one in each chunk until
65
+ * the stream is done.
66
+ * @public
67
+ */
68
+ export interface GenerateContentResponse {
69
+ candidates?: GenerateContentCandidate[];
70
+ promptFeedback?: PromptFeedback;
71
+ usageMetadata?: UsageMetadata;
72
+ }
73
+ /**
74
+ * Usage metadata about a {@link GenerateContentResponse}.
75
+ *
76
+ * @public
77
+ */
78
+ export interface UsageMetadata {
79
+ promptTokenCount: number;
80
+ candidatesTokenCount: number;
81
+ totalTokenCount: number;
82
+ promptTokensDetails?: ModalityTokenCount[];
83
+ candidatesTokensDetails?: ModalityTokenCount[];
84
+ }
85
+ /**
86
+ * Represents token counting info for a single modality.
87
+ *
88
+ * @public
89
+ */
90
+ export interface ModalityTokenCount {
91
+ /** The modality associated with this token count. */
92
+ modality: Modality;
93
+ /** The number of tokens counted. */
94
+ tokenCount: number;
95
+ }
96
+ /**
97
+ * If the prompt was blocked, this will be populated with `blockReason` and
98
+ * the relevant `safetyRatings`.
99
+ * @public
100
+ */
101
+ export interface PromptFeedback {
102
+ blockReason?: BlockReason;
103
+ safetyRatings: SafetyRating[];
104
+ /**
105
+ * A human-readable description of the `blockReason`.
106
+ *
107
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
108
+ */
109
+ blockReasonMessage?: string;
110
+ }
111
+ /**
112
+ * A candidate returned as part of a {@link GenerateContentResponse}.
113
+ * @public
114
+ */
115
+ export interface GenerateContentCandidate {
116
+ index: number;
117
+ content: Content;
118
+ finishReason?: FinishReason;
119
+ finishMessage?: string;
120
+ safetyRatings?: SafetyRating[];
121
+ citationMetadata?: CitationMetadata;
122
+ groundingMetadata?: GroundingMetadata;
123
+ }
124
+ /**
125
+ * Citation metadata that may be found on a {@link GenerateContentCandidate}.
126
+ * @public
127
+ */
128
+ export interface CitationMetadata {
129
+ citations: Citation[];
130
+ }
131
+ /**
132
+ * A single citation.
133
+ * @public
134
+ */
135
+ export interface Citation {
136
+ startIndex?: number;
137
+ endIndex?: number;
138
+ uri?: string;
139
+ license?: string;
140
+ /**
141
+ * The title of the cited source, if available.
142
+ *
143
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
144
+ */
145
+ title?: string;
146
+ /**
147
+ * The publication date of the cited source, if available.
148
+ *
149
+ * This property is only supported in the Vertex AI Gemini API ({@link VertexAIBackend}).
150
+ */
151
+ publicationDate?: Date;
152
+ }
153
+ /**
154
+ * Metadata returned to client when grounding is enabled.
155
+ * @public
156
+ */
157
+ export interface GroundingMetadata {
158
+ webSearchQueries?: string[];
159
+ retrievalQueries?: string[];
160
+ /**
161
+ * @deprecated
162
+ */
163
+ groundingAttributions: GroundingAttribution[];
164
+ }
165
+ /**
166
+ * @deprecated
167
+ * @public
168
+ */
169
+ export interface GroundingAttribution {
170
+ segment: Segment;
171
+ confidenceScore?: number;
172
+ web?: WebAttribution;
173
+ retrievedContext?: RetrievedContextAttribution;
174
+ }
175
+ /**
176
+ * @public
177
+ */
178
+ export interface Segment {
179
+ partIndex: number;
180
+ startIndex: number;
181
+ endIndex: number;
182
+ }
183
+ /**
184
+ * @public
185
+ */
186
+ export interface WebAttribution {
187
+ uri: string;
188
+ title: string;
189
+ }
190
+ /**
191
+ * @public
192
+ */
193
+ export interface RetrievedContextAttribution {
194
+ uri: string;
195
+ title: string;
196
+ }
197
+ /**
198
+ * Protobuf google.type.Date
199
+ * @public
200
+ */
201
+ export interface Date {
202
+ year: number;
203
+ month: number;
204
+ day: number;
205
+ }
206
+ /**
207
+ * A safety rating associated with a {@link GenerateContentCandidate}
208
+ * @public
209
+ */
210
+ export interface SafetyRating {
211
+ category: HarmCategory;
212
+ probability: HarmProbability;
213
+ /**
214
+ * The harm severity level.
215
+ *
216
+ * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
217
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to `HarmSeverity.UNSUPPORTED`.
218
+ */
219
+ severity: HarmSeverity;
220
+ /**
221
+ * The probability score of the harm category.
222
+ *
223
+ * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
224
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
225
+ */
226
+ probabilityScore: number;
227
+ /**
228
+ * The severity score of the harm category.
229
+ *
230
+ * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
231
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
232
+ */
233
+ severityScore: number;
234
+ blocked: boolean;
235
+ }
236
+ /**
237
+ * Response from calling {@link GenerativeModel.countTokens}.
238
+ * @public
239
+ */
240
+ export interface CountTokensResponse {
241
+ /**
242
+ * The total number of tokens counted across all instances from the request.
243
+ */
244
+ totalTokens: number;
245
+ /**
246
+ * The total number of billable characters counted across all instances
247
+ * from the request.
248
+ *
249
+ * This property is only supported when using the Vertex AI Gemini API ({@link VertexAIBackend}).
250
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this property is not supported and will default to 0.
251
+ */
252
+ totalBillableCharacters?: number;
253
+ /**
254
+ * The breakdown, by modality, of how many tokens are consumed by the prompt.
255
+ */
256
+ promptTokensDetails?: ModalityTokenCount[];
257
+ }
@@ -0,0 +1,102 @@
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
+ * Contains the list of OpenAPI data types
19
+ * as defined by the
20
+ * {@link https://swagger.io/docs/specification/data-models/data-types/ | OpenAPI specification}
21
+ * @public
22
+ */
23
+ export declare enum SchemaType {
24
+ /** String type. */
25
+ STRING = "string",
26
+ /** Number type. */
27
+ NUMBER = "number",
28
+ /** Integer type. */
29
+ INTEGER = "integer",
30
+ /** Boolean type. */
31
+ BOOLEAN = "boolean",
32
+ /** Array type. */
33
+ ARRAY = "array",
34
+ /** Object type. */
35
+ OBJECT = "object"
36
+ }
37
+ /**
38
+ * Basic {@link Schema} properties shared across several Schema-related
39
+ * types.
40
+ * @public
41
+ */
42
+ export interface SchemaShared<T> {
43
+ /** Optional. The format of the property.
44
+ * When using the Gemini Developer API ({@link GoogleAIBackend}), this must be either `'enum'` or
45
+ * `'date-time'`, otherwise requests will fail.
46
+ */
47
+ format?: string;
48
+ /** Optional. The description of the property. */
49
+ description?: string;
50
+ /** Optional. The items of the property. */
51
+ items?: T;
52
+ /** Optional. Map of `Schema` objects. */
53
+ properties?: {
54
+ [k: string]: T;
55
+ };
56
+ /** Optional. The enum of the property. */
57
+ enum?: string[];
58
+ /** Optional. The example of the property. */
59
+ example?: unknown;
60
+ /** Optional. Whether the property is nullable. */
61
+ nullable?: boolean;
62
+ [key: string]: unknown;
63
+ }
64
+ /**
65
+ * Params passed to {@link Schema} static methods to create specific
66
+ * {@link Schema} classes.
67
+ * @public
68
+ */
69
+ export interface SchemaParams extends SchemaShared<SchemaInterface> {
70
+ }
71
+ /**
72
+ * Final format for {@link Schema} params passed to backend requests.
73
+ * @public
74
+ */
75
+ export interface SchemaRequest extends SchemaShared<SchemaRequest> {
76
+ /**
77
+ * The type of the property. {@link
78
+ * SchemaType}.
79
+ */
80
+ type: SchemaType;
81
+ /** Optional. Array of required property. */
82
+ required?: string[];
83
+ }
84
+ /**
85
+ * Interface for {@link Schema} class.
86
+ * @public
87
+ */
88
+ export interface SchemaInterface extends SchemaShared<SchemaInterface> {
89
+ /**
90
+ * The type of the property. {@link
91
+ * SchemaType}.
92
+ */
93
+ type: SchemaType;
94
+ }
95
+ /**
96
+ * Interface for {@link ObjectSchema} class.
97
+ * @public
98
+ */
99
+ export interface ObjectSchemaInterface extends SchemaInterface {
100
+ type: SchemaType.OBJECT;
101
+ optionalProperties?: string[];
102
+ }