UNPKG

5.88 kBTypeScriptView Raw
1/*! firebase-admin v10.0.0 */
2/*!
3 * Copyright 2020 Google Inc.
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 */
17import { App } from '../app';
18import { ListModelsOptions, ModelOptions } from './machine-learning-api-client';
19/** Response object for a listModels operation. */
20export interface ListModelsResult {
21 /** A list of models in your project. */
22 readonly models: Model[];
23 /**
24 * A token you can use to retrieve the next page of results. If null, the
25 * current page is the final page.
26 */
27 readonly pageToken?: string;
28}
29/**
30 * A TensorFlow Lite Model output object
31 *
32 * One of either the `gcsTfliteUri` or `automlModel` properties will be
33 * defined.
34 */
35export interface TFLiteModel {
36 /** The size of the model. */
37 readonly sizeBytes: number;
38 /** The URI from which the model was originally provided to Firebase. */
39 readonly gcsTfliteUri?: string;
40 /**
41 * The AutoML model reference from which the model was originally provided
42 * to Firebase.
43 */
44 readonly automlModel?: string;
45}
46/**
47 * The Firebase `MachineLearning` service interface.
48 */
49export declare class MachineLearning {
50 private readonly client;
51 private readonly appInternal;
52 /**
53 * The {@link firebase-admin.app#App} associated with the current `MachineLearning`
54 * service instance.
55 */
56 get app(): App;
57 /**
58 * Creates a model in the current Firebase project.
59 *
60 * @param model - The model to create.
61 *
62 * @returns A Promise fulfilled with the created model.
63 */
64 createModel(model: ModelOptions): Promise<Model>;
65 /**
66 * Updates a model's metadata or model file.
67 *
68 * @param modelId - The ID of the model to update.
69 * @param model - The model fields to update.
70 *
71 * @returns A Promise fulfilled with the updated model.
72 */
73 updateModel(modelId: string, model: ModelOptions): Promise<Model>;
74 /**
75 * Publishes a Firebase ML model.
76 *
77 * A published model can be downloaded to client apps.
78 *
79 * @param modelId - The ID of the model to publish.
80 *
81 * @returns A Promise fulfilled with the published model.
82 */
83 publishModel(modelId: string): Promise<Model>;
84 /**
85 * Unpublishes a Firebase ML model.
86 *
87 * @param modelId - The ID of the model to unpublish.
88 *
89 * @returns A Promise fulfilled with the unpublished model.
90 */
91 unpublishModel(modelId: string): Promise<Model>;
92 /**
93 * Gets the model specified by the given ID.
94 *
95 * @param modelId - The ID of the model to get.
96 *
97 * @returns A Promise fulfilled with the model object.
98 */
99 getModel(modelId: string): Promise<Model>;
100 /**
101 * Lists the current project's models.
102 *
103 * @param options - The listing options.
104 *
105 * @returns A promise that
106 * resolves with the current (filtered) list of models and the next page
107 * token. For the last page, an empty list of models and no page token
108 * are returned.
109 */
110 listModels(options?: ListModelsOptions): Promise<ListModelsResult>;
111 /**
112 * Deletes a model from the current project.
113 *
114 * @param modelId - The ID of the model to delete.
115 */
116 deleteModel(modelId: string): Promise<void>;
117 private setPublishStatus;
118 private signUrlIfPresent;
119 private signUrl;
120}
121/**
122 * A Firebase ML Model output object.
123 */
124export declare class Model {
125 private model;
126 private readonly client?;
127 /** The ID of the model. */
128 get modelId(): string;
129 /**
130 * The model's name. This is the name you use from your app to load the
131 * model.
132 */
133 get displayName(): string;
134 /**
135 * The model's tags, which can be used to group or filter models in list
136 * operations.
137 */
138 get tags(): string[];
139 /** The timestamp of the model's creation. */
140 get createTime(): string;
141 /** The timestamp of the model's most recent update. */
142 get updateTime(): string;
143 /** Error message when model validation fails. */
144 get validationError(): string | undefined;
145 /** True if the model is published. */
146 get published(): boolean;
147 /**
148 * The ETag identifier of the current version of the model. This value
149 * changes whenever you update any of the model's properties.
150 */
151 get etag(): string;
152 /**
153 * The hash of the model's `tflite` file. This value changes only when
154 * you upload a new TensorFlow Lite model.
155 */
156 get modelHash(): string | undefined;
157 /** Metadata about the model's TensorFlow Lite model file. */
158 get tfliteModel(): TFLiteModel | undefined;
159 /**
160 * True if the model is locked by a server-side operation. You can't make
161 * changes to a locked model. See {@link Model.waitForUnlocked}.
162 */
163 get locked(): boolean;
164 /**
165 * Return the model as a JSON object.
166 */
167 toJSON(): {
168 [key: string]: any;
169 };
170 /**
171 * Wait for the model to be unlocked.
172 *
173 * @param maxTimeMillis - The maximum time in milliseconds to wait.
174 * If not specified, a default maximum of 2 minutes is used.
175 *
176 * @returns A promise that resolves when the model is unlocked
177 * or the maximum wait time has passed.
178 */
179 waitForUnlocked(maxTimeMillis?: number): Promise<void>;
180 private static validateAndClone;
181}