@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,61 @@
|
|
|
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
|
+
* Defines the image format for images generated by Imagen.
|
|
19
|
+
*
|
|
20
|
+
* Use this class to specify the desired format (JPEG or PNG) and compression quality
|
|
21
|
+
* for images generated by Imagen. This is typically included as part of
|
|
22
|
+
* {@link ImagenModelParams}.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```javascript
|
|
26
|
+
* const imagenModelParams = {
|
|
27
|
+
* // ... other ImagenModelParams
|
|
28
|
+
* imageFormat: ImagenImageFormat.jpeg(75) // JPEG with a compression level of 75.
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* @beta
|
|
33
|
+
*/
|
|
34
|
+
export declare class ImagenImageFormat {
|
|
35
|
+
/**
|
|
36
|
+
* The MIME type.
|
|
37
|
+
*/
|
|
38
|
+
mimeType: string;
|
|
39
|
+
/**
|
|
40
|
+
* The level of compression (a number between 0 and 100).
|
|
41
|
+
*/
|
|
42
|
+
compressionQuality?: number;
|
|
43
|
+
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates an {@link ImagenImageFormat} for a JPEG image.
|
|
46
|
+
*
|
|
47
|
+
* @param compressionQuality - The level of compression (a number between 0 and 100).
|
|
48
|
+
* @returns An {@link ImagenImageFormat} object for a JPEG image.
|
|
49
|
+
*
|
|
50
|
+
* @beta
|
|
51
|
+
*/
|
|
52
|
+
static jpeg(compressionQuality?: number): ImagenImageFormat;
|
|
53
|
+
/**
|
|
54
|
+
* Creates an {@link ImagenImageFormat} for a PNG image.
|
|
55
|
+
*
|
|
56
|
+
* @returns An {@link ImagenImageFormat} object for a PNG image.
|
|
57
|
+
*
|
|
58
|
+
* @beta
|
|
59
|
+
*/
|
|
60
|
+
static png(): ImagenImageFormat;
|
|
61
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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, GenerateContentRequest, Part } from '../types';
|
|
18
|
+
import { ImagenGenerationParams, PredictRequestBody } from '../types/internal';
|
|
19
|
+
export declare function formatSystemInstruction(input?: string | Part | Content): Content | undefined;
|
|
20
|
+
export declare function formatNewContent(request: string | Array<string | Part>): Content;
|
|
21
|
+
export declare function formatGenerateContentInput(params: GenerateContentRequest | string | Array<string | Part>): GenerateContentRequest;
|
|
22
|
+
/**
|
|
23
|
+
* Convert the user-defined parameters in {@link ImagenGenerationParams} to the format
|
|
24
|
+
* that is expected from the REST API.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function createPredictRequestBody(prompt: string, { gcsURI, imageFormat, addWatermark, numberOfImages, negativePrompt, aspectRatio, safetyFilterLevel, personFilterLevel }: ImagenGenerationParams): PredictRequestBody;
|
|
@@ -0,0 +1,43 @@
|
|
|
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 { RequestOptions } from '../types';
|
|
18
|
+
import { ApiSettings } from '../types/internal';
|
|
19
|
+
export declare enum Task {
|
|
20
|
+
GENERATE_CONTENT = "generateContent",
|
|
21
|
+
STREAM_GENERATE_CONTENT = "streamGenerateContent",
|
|
22
|
+
COUNT_TOKENS = "countTokens",
|
|
23
|
+
PREDICT = "predict"
|
|
24
|
+
}
|
|
25
|
+
export declare class RequestUrl {
|
|
26
|
+
model: string;
|
|
27
|
+
task: Task;
|
|
28
|
+
apiSettings: ApiSettings;
|
|
29
|
+
stream: boolean;
|
|
30
|
+
requestOptions?: RequestOptions | undefined;
|
|
31
|
+
constructor(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, requestOptions?: RequestOptions | undefined);
|
|
32
|
+
toString(): string;
|
|
33
|
+
private get baseUrl();
|
|
34
|
+
private get apiVersion();
|
|
35
|
+
private get modelPath();
|
|
36
|
+
private get queryParams();
|
|
37
|
+
}
|
|
38
|
+
export declare function getHeaders(url: RequestUrl): Promise<Headers>;
|
|
39
|
+
export declare function constructRequest(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, body: string, requestOptions?: RequestOptions): Promise<{
|
|
40
|
+
url: string;
|
|
41
|
+
fetchOptions: RequestInit;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function makeRequest(model: string, task: Task, apiSettings: ApiSettings, stream: boolean, body: string, requestOptions?: RequestOptions): Promise<Response>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { EnhancedGenerateContentResponse, FunctionCall, GenerateContentResponse, ImagenGCSImage, ImagenInlineImage, InlineDataPart } from '../types';
|
|
18
|
+
/**
|
|
19
|
+
* Creates an EnhancedGenerateContentResponse object that has helper functions and
|
|
20
|
+
* other modifications that improve usability.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createEnhancedContentResponse(response: GenerateContentResponse): EnhancedGenerateContentResponse;
|
|
23
|
+
/**
|
|
24
|
+
* Adds convenience helper methods to a response object, including stream
|
|
25
|
+
* chunks (as long as each chunk is a complete GenerateContentResponse JSON).
|
|
26
|
+
*/
|
|
27
|
+
export declare function addHelpers(response: GenerateContentResponse): EnhancedGenerateContentResponse;
|
|
28
|
+
/**
|
|
29
|
+
* Returns all text found in all parts of first candidate.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getText(response: GenerateContentResponse): string;
|
|
32
|
+
/**
|
|
33
|
+
* Returns {@link FunctionCall}s associated with first candidate.
|
|
34
|
+
*/
|
|
35
|
+
export declare function getFunctionCalls(response: GenerateContentResponse): FunctionCall[] | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* Returns {@link InlineDataPart}s in the first candidate if present.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export declare function getInlineDataParts(response: GenerateContentResponse): InlineDataPart[] | undefined;
|
|
42
|
+
export declare function formatBlockErrorMessage(response: GenerateContentResponse): string;
|
|
43
|
+
/**
|
|
44
|
+
* Convert a generic successful fetch response body to an Imagen response object
|
|
45
|
+
* that can be returned to the user. This converts the REST APIs response format to our
|
|
46
|
+
* APIs representation of a response.
|
|
47
|
+
*
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export declare function handlePredictResponse<T extends ImagenInlineImage | ImagenGCSImage>(response: Response): Promise<{
|
|
51
|
+
images: T[];
|
|
52
|
+
filteredReason?: string;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,145 @@
|
|
|
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 { SchemaInterface, SchemaType, SchemaParams, SchemaRequest } from '../types/schema';
|
|
18
|
+
/**
|
|
19
|
+
* Parent class encompassing all Schema types, with static methods that
|
|
20
|
+
* allow building specific Schema types. This class can be converted with
|
|
21
|
+
* `JSON.stringify()` into a JSON string accepted by Vertex AI REST endpoints.
|
|
22
|
+
* (This string conversion is automatically done when calling SDK methods.)
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare abstract class Schema implements SchemaInterface {
|
|
26
|
+
/**
|
|
27
|
+
* Optional. The type of the property. {@link
|
|
28
|
+
* SchemaType}.
|
|
29
|
+
*/
|
|
30
|
+
type: SchemaType;
|
|
31
|
+
/** Optional. The format of the property.
|
|
32
|
+
* Supported formats:<br/>
|
|
33
|
+
* <ul>
|
|
34
|
+
* <li>for NUMBER type: "float", "double"</li>
|
|
35
|
+
* <li>for INTEGER type: "int32", "int64"</li>
|
|
36
|
+
* <li>for STRING type: "email", "byte", etc</li>
|
|
37
|
+
* </ul>
|
|
38
|
+
*/
|
|
39
|
+
format?: string;
|
|
40
|
+
/** Optional. The description of the property. */
|
|
41
|
+
description?: string;
|
|
42
|
+
/** Optional. Whether the property is nullable. Defaults to false. */
|
|
43
|
+
nullable: boolean;
|
|
44
|
+
/** Optional. The example of the property. */
|
|
45
|
+
example?: unknown;
|
|
46
|
+
/**
|
|
47
|
+
* Allows user to add other schema properties that have not yet
|
|
48
|
+
* been officially added to the SDK.
|
|
49
|
+
*/
|
|
50
|
+
[key: string]: unknown;
|
|
51
|
+
constructor(schemaParams: SchemaInterface);
|
|
52
|
+
/**
|
|
53
|
+
* Defines how this Schema should be serialized as JSON.
|
|
54
|
+
* See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
toJSON(): SchemaRequest;
|
|
58
|
+
static array(arrayParams: SchemaParams & {
|
|
59
|
+
items: Schema;
|
|
60
|
+
}): ArraySchema;
|
|
61
|
+
static object(objectParams: SchemaParams & {
|
|
62
|
+
properties: {
|
|
63
|
+
[k: string]: Schema;
|
|
64
|
+
};
|
|
65
|
+
optionalProperties?: string[];
|
|
66
|
+
}): ObjectSchema;
|
|
67
|
+
static string(stringParams?: SchemaParams): StringSchema;
|
|
68
|
+
static enumString(stringParams: SchemaParams & {
|
|
69
|
+
enum: string[];
|
|
70
|
+
}): StringSchema;
|
|
71
|
+
static integer(integerParams?: SchemaParams): IntegerSchema;
|
|
72
|
+
static number(numberParams?: SchemaParams): NumberSchema;
|
|
73
|
+
static boolean(booleanParams?: SchemaParams): BooleanSchema;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* A type that includes all specific Schema types.
|
|
77
|
+
* @public
|
|
78
|
+
*/
|
|
79
|
+
export type TypedSchema = IntegerSchema | NumberSchema | StringSchema | BooleanSchema | ObjectSchema | ArraySchema;
|
|
80
|
+
/**
|
|
81
|
+
* Schema class for "integer" types.
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
export declare class IntegerSchema extends Schema {
|
|
85
|
+
constructor(schemaParams?: SchemaParams);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Schema class for "number" types.
|
|
89
|
+
* @public
|
|
90
|
+
*/
|
|
91
|
+
export declare class NumberSchema extends Schema {
|
|
92
|
+
constructor(schemaParams?: SchemaParams);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Schema class for "boolean" types.
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export declare class BooleanSchema extends Schema {
|
|
99
|
+
constructor(schemaParams?: SchemaParams);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Schema class for "string" types. Can be used with or without
|
|
103
|
+
* enum values.
|
|
104
|
+
* @public
|
|
105
|
+
*/
|
|
106
|
+
export declare class StringSchema extends Schema {
|
|
107
|
+
enum?: string[];
|
|
108
|
+
constructor(schemaParams?: SchemaParams, enumValues?: string[]);
|
|
109
|
+
/**
|
|
110
|
+
* @internal
|
|
111
|
+
*/
|
|
112
|
+
toJSON(): SchemaRequest;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Schema class for "array" types.
|
|
116
|
+
* The `items` param should refer to the type of item that can be a member
|
|
117
|
+
* of the array.
|
|
118
|
+
* @public
|
|
119
|
+
*/
|
|
120
|
+
export declare class ArraySchema extends Schema {
|
|
121
|
+
items: TypedSchema;
|
|
122
|
+
constructor(schemaParams: SchemaParams, items: TypedSchema);
|
|
123
|
+
/**
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
toJSON(): SchemaRequest;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Schema class for "object" types.
|
|
130
|
+
* The `properties` param must be a map of `Schema` objects.
|
|
131
|
+
* @public
|
|
132
|
+
*/
|
|
133
|
+
export declare class ObjectSchema extends Schema {
|
|
134
|
+
properties: {
|
|
135
|
+
[k: string]: TypedSchema;
|
|
136
|
+
};
|
|
137
|
+
optionalProperties: string[];
|
|
138
|
+
constructor(schemaParams: SchemaParams, properties: {
|
|
139
|
+
[k: string]: TypedSchema;
|
|
140
|
+
}, optionalProperties?: string[]);
|
|
141
|
+
/**
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
toJSON(): SchemaRequest;
|
|
145
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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, GenerateContentStreamResult } from '../types';
|
|
18
|
+
import { ApiSettings } from '../types/internal';
|
|
19
|
+
/**
|
|
20
|
+
* Process a response.body stream from the backend and return an
|
|
21
|
+
* iterator that provides one complete GenerateContentResponse at a time
|
|
22
|
+
* and a promise that resolves with a single aggregated
|
|
23
|
+
* GenerateContentResponse.
|
|
24
|
+
*
|
|
25
|
+
* @param response - Response from a fetch call
|
|
26
|
+
*/
|
|
27
|
+
export declare function processStream(response: Response, apiSettings: ApiSettings): GenerateContentStreamResult;
|
|
28
|
+
/**
|
|
29
|
+
* Reads a raw stream from the fetch response and join incomplete
|
|
30
|
+
* chunks, returning a new stream that provides a single complete
|
|
31
|
+
* GenerateContentResponse in each iteration.
|
|
32
|
+
*/
|
|
33
|
+
export declare function getResponseStream<T>(inputStream: ReadableStream<string>): ReadableStream<T>;
|
|
34
|
+
/**
|
|
35
|
+
* Aggregates an array of `GenerateContentResponse`s into a single
|
|
36
|
+
* GenerateContentResponse.
|
|
37
|
+
*/
|
|
38
|
+
export declare function aggregateResponses(responses: GenerateContentResponse[]): GenerateContentResponse;
|
|
@@ -0,0 +1,31 @@
|
|
|
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 { FirebaseApp, _FirebaseService } from '@firebase/app';
|
|
18
|
+
import { AI } from './public-types';
|
|
19
|
+
import { AppCheckInternalComponentName, FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
|
|
20
|
+
import { Provider } from '@firebase/component';
|
|
21
|
+
import { FirebaseAuthInternal, FirebaseAuthInternalName } from '@firebase/auth-interop-types';
|
|
22
|
+
import { Backend } from './backend';
|
|
23
|
+
export declare class AIService implements AI, _FirebaseService {
|
|
24
|
+
app: FirebaseApp;
|
|
25
|
+
backend: Backend;
|
|
26
|
+
auth: FirebaseAuthInternal | null;
|
|
27
|
+
appCheck: FirebaseAppCheckInternal | null;
|
|
28
|
+
location: string;
|
|
29
|
+
constructor(app: FirebaseApp, backend: Backend, authProvider?: Provider<FirebaseAuthInternalName>, appCheckProvider?: Provider<AppCheckInternalComponentName>);
|
|
30
|
+
_delete(): Promise<void>;
|
|
31
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "0.1.2"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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 { Role } from './enums';
|
|
18
|
+
/**
|
|
19
|
+
* Content type for both prompts and response candidates.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export interface Content {
|
|
23
|
+
role: Role;
|
|
24
|
+
parts: Part[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Content part - includes text, image/video, or function call/response
|
|
28
|
+
* part types.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export type Part = TextPart | InlineDataPart | FunctionCallPart | FunctionResponsePart | FileDataPart;
|
|
32
|
+
/**
|
|
33
|
+
* Content part interface if the part represents a text string.
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export interface TextPart {
|
|
37
|
+
text: string;
|
|
38
|
+
inlineData?: never;
|
|
39
|
+
functionCall?: never;
|
|
40
|
+
functionResponse?: never;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Content part interface if the part represents an image.
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
export interface InlineDataPart {
|
|
47
|
+
text?: never;
|
|
48
|
+
inlineData: GenerativeContentBlob;
|
|
49
|
+
functionCall?: never;
|
|
50
|
+
functionResponse?: never;
|
|
51
|
+
/**
|
|
52
|
+
* Applicable if `inlineData` is a video.
|
|
53
|
+
*/
|
|
54
|
+
videoMetadata?: VideoMetadata;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Describes the input video content.
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
export interface VideoMetadata {
|
|
61
|
+
/**
|
|
62
|
+
* The start offset of the video in
|
|
63
|
+
* protobuf {@link https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping | Duration} format.
|
|
64
|
+
*/
|
|
65
|
+
startOffset: string;
|
|
66
|
+
/**
|
|
67
|
+
* The end offset of the video in
|
|
68
|
+
* protobuf {@link https://cloud.google.com/ruby/docs/reference/google-cloud-workflows-v1/latest/Google-Protobuf-Duration#json-mapping | Duration} format.
|
|
69
|
+
*/
|
|
70
|
+
endOffset: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Content part interface if the part represents a {@link FunctionCall}.
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
export interface FunctionCallPart {
|
|
77
|
+
text?: never;
|
|
78
|
+
inlineData?: never;
|
|
79
|
+
functionCall: FunctionCall;
|
|
80
|
+
functionResponse?: never;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Content part interface if the part represents {@link FunctionResponse}.
|
|
84
|
+
* @public
|
|
85
|
+
*/
|
|
86
|
+
export interface FunctionResponsePart {
|
|
87
|
+
text?: never;
|
|
88
|
+
inlineData?: never;
|
|
89
|
+
functionCall?: never;
|
|
90
|
+
functionResponse: FunctionResponse;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Content part interface if the part represents {@link FileData}
|
|
94
|
+
* @public
|
|
95
|
+
*/
|
|
96
|
+
export interface FileDataPart {
|
|
97
|
+
text?: never;
|
|
98
|
+
inlineData?: never;
|
|
99
|
+
functionCall?: never;
|
|
100
|
+
functionResponse?: never;
|
|
101
|
+
fileData: FileData;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* A predicted {@link FunctionCall} returned from the model
|
|
105
|
+
* that contains a string representing the {@link FunctionDeclaration.name}
|
|
106
|
+
* and a structured JSON object containing the parameters and their values.
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export interface FunctionCall {
|
|
110
|
+
name: string;
|
|
111
|
+
args: object;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The result output from a {@link FunctionCall} that contains a string
|
|
115
|
+
* representing the {@link FunctionDeclaration.name}
|
|
116
|
+
* and a structured JSON object containing any output
|
|
117
|
+
* from the function is used as context to the model.
|
|
118
|
+
* This should contain the result of a {@link FunctionCall}
|
|
119
|
+
* made based on model prediction.
|
|
120
|
+
* @public
|
|
121
|
+
*/
|
|
122
|
+
export interface FunctionResponse {
|
|
123
|
+
name: string;
|
|
124
|
+
response: object;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Interface for sending an image.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
130
|
+
export interface GenerativeContentBlob {
|
|
131
|
+
mimeType: string;
|
|
132
|
+
/**
|
|
133
|
+
* Image as a base64 string.
|
|
134
|
+
*/
|
|
135
|
+
data: string;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Data pointing to a file uploaded on Google Cloud Storage.
|
|
139
|
+
* @public
|
|
140
|
+
*/
|
|
141
|
+
export interface FileData {
|
|
142
|
+
mimeType: string;
|
|
143
|
+
fileUri: string;
|
|
144
|
+
}
|