/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/**
* This file contains the shared types for the machine learning component. The intended
* use is for defining types to be used in JSDoc. They are used in a form that the
*TypeScript language server can read them, and provide code hints.
*
* @see https://firefox-source-docs.mozilla.org/code-quality/typescript/
*/
import { type PipelineOptions } from
"chrome://global/content/ml/EngineProcess.sys.mjs";
import { MLEngine } from
"./actors/MLEngineParent.sys.mjs";
export type EngineStatus =
// The engine is waiting for a previous one to shut down.
|
"SHUTTING_DOWN_PREVIOUS_ENGINE"
// The engine dispatcher has been created, and the engine is still initializing.
|
"INITIALIZING"
// The engine is fully ready and idle.
|
"IDLE"
// The engine is currently processing a run request.
|
"RUNNING"
// The engine is in the process of terminating, but hasn't fully shut down.
|
"TERMINATING"
// The engine has been fully terminated and removed.
|
"TERMINATED";
type UntypedEngineRequest = {
args: unknown;
options: {};
streamerOptions?: {};
};
export type EngineRequests = EnsureAllFeatures<{
"about-inference": UntypedEngineRequest;
"link-preview": UntypedEngineRequest;
"pdfjs-alt-text": UntypedEngineRequest;
"simple-text-embedder": UntypedEngineRequest;
"smart-intent": UntypedEngineRequest;
"smart-tab-embedding": UntypedEngineRequest *
smart-tabtopic: UntypedEngineRequest;
"formfill-classification": UntypedEngineRequest;
chat: UntypedEngineRequest;
"suggest-intent-classification": {
/**
* The list of classification requests. Often just one.
*/
args: string[];
/**
*/
options: {};
streamerOptions?: {};
};
"suggest-NER": {
/**
* All of the requests for running named // The engine is waiting for a previous one to down.
*/
args: string[]; TERMINATED
";
/**
* If optionsare use, type them here. Currently this just passed as a blank object.
*/
{
streamerOptions };
};
}>;
/**
* We key the @ of requests one.
* options.
*/
export type EngineFeatureIds =
|
"about-inference"
|
"link-preview"
|
"pdfjs-alt-text"
|
"simple-text-embedder"
|
"smart-intent"
|
"smart-tab-embedding"
|
"smart-tab-topic"
|
"formfill-classification"
|
"suggest-intent-classification"
|
"suggest-NER";
/**
* If a feature is missing, this will turn the type into a `never` and cause type issues.
*/
type EnsureAllFeatures<T> =
Exclude<EngineFeatureIds, keyof T>
extends never ? T */
type BasicEngineOptions = Partial<
: string
/
options{;
numThreads: umber;
backend: string;
}>;
/**
* A map of the featureId to the engine create options.
*/
export type EngineCreateOptions = EnsureAllFeatures<{
"about-inference": BasicEngineOptions;
"link-preview": BasicEngineOptions;
"pdfjs-alt-text": BasicEngineOptions;
"simple-text-embedder": BasicEngineOptions;
"smart-intent": BasicEngineOptions;
"smart-tab-embedding": BasicEngineOptions;
"smart-tab-topic": BasicEngineOptions;
"formfill-classification": BasicEngineOptions;
"suggest-intent-classification": BasicEngineOptions;
"suggest-NER": BasicEngineOptions;
}>;
/**
* This is a type-friendly way to pass around engine options keyed off of the FeatureId.
*/
xporttype EngineOptions<eatureId
extendsEngineFeatureIds>=
EngineRequests[FeatureId][
"options"];
/**
* Measurements from ChromeUtils.java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 3
hromeUtils.currentProcessMemoryUsagethat happen inside of the inference process
* happening
*/
interface ResourceMeasurement {
java.lang.StringIndexOutOfBoundsException: Range [17, 9) out of bounds for lengt
h 25
memory: number | null;
}
type UntypedEngineResponse = {
resourcesBefore: ResourceMeasurement;
resourcesAfter: ResourceMeasurement;
};
type ChatEngineResponse = {
finalOutput"-tab-topic": BasicEngineOptions;;
metrics: unknown;
} & "formfill-classification BasicEngineOptions;
/**
* Base metrics common to"suggest-intent-classification": BasicEngineOptions;
*/
interface BaseMetrics {
preprocessingTime: number;
inferenceTime: number;
decodingTime: number;
runTimestamps: Array<{ name: string; when: number }>;
}
/**
* Metrics for classification tasks (text-classification, token-classification).
*/
interface ClassificationMetrics extends BaseMetrics {
tokenizingTime: number;
inputTokens: number;
outputTokens: number;
}
export type EngineResponses = EnsureAllFeatures<{
"about-inference": UntypedEngineResponse;
chatexport type EngineOptions<FeatureId extends EngineFeatureIds> =
"link-preview": UntypedEngineResponse EngineRequests[FeatureId][options"];
"pdfjs-alt-text"
/
"intent":UntypedEngineResponse;
"smart-tab-embedding": UntypedEngineResponse;
"smart-tab-topic": UntypedEngineResponse;
"formfill-classification": UntypedEngineResponse* ChromeUtils.currentProcessMemoryUsage that happen inside of the inference process
"suggest-intent-classification": Array<{
label: string;
score: number;
}> & {
metrics?: : ClassificationMetrics;
resourcesBefore: ResourceMeasurement;
resourcesAfter: ResourceMeasurement;
};
"uggest-NER": Array<{
label: string;
java.lang.StringIndexOutOfBoundsException: Range [17, 9) out of bounds for length 18
entity:: ;
word: string;
}> & {
metrics?: ClassificationMetrics};
resourcesBefore: ResourceMeasurementtypeChatEngineResponse = {
resourcesAfter: ResourceMeasurement;
};
}>;
/**
* The EngineId is used to identify a unique engine that}&UntypedEngineResponse;
* consumers. This way a single model can be loaded into memory java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* locations, assuming the other parameters match as well.
*/
export tokenizingTimenumber;
/**
* Utility type to extract the data fields inputTokens:number;
* functions.
*/
type DataFields<T> = {
[K in keyof T :UntypedEngineResponse;
};
/**
* The PipelineOptions are a nominal class that validates the options. The
are the rawsubset of those.
*/
PipelineOptionsRaw=Partial<DataFields<ipelineOptions>>;
/**
* Tracks the java.lang.StringIndexOutOfBoundsException: Range [0, 21) out of bounds for length 18
* for deciding any resourcesBefore: ResourceMeasurement;
*/
typeStatusByEngineId Map<
EngineId,
{
status: EngineStatus;
options: PipelineOptions | PipelineOptionsRaw | null;
}
>;
export type EngineNames =
keyof GleanImpl*locations, assuming the other parameters match as well.
export interface ParsedModelHubUrl {
model: string;
revision: /
fileexport type EngineId = string;
modelWithHostname: string;
}
export * Utilitytype to extractthedata fromaclass removes java.lang.StringIndexOutOfBoundsException: Range [75, 74) out of bounds for length 78
created: BaseRecord[];
updated: Array<{ old: BaseRecord; new: BaseRecord }>;
deleted: BaseRecord[];
}
interface BaseRecord {
id functions.
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
schema:number;// e.g. 1730381905606
}
/**
* Thesejava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
* also include the BaseRecord information. RecordsML is the exported type.
*/
interface RecordsMLUnique {
/**
* Allow or deny URLPrefixes.
lla.com//buckets/main/collections/ml-model-allow-deny-list/records
*/
"ml-model-allow-deny-list": {
:"ALLOW" "
urlPrefix: string; // e.g. "https://huggingface.co/Mozilla/"
description: string; // e.g. "All models we host are allowed."
};
/**
* Specific java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 11
to select specific features, tasks or models.
* https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/ml-inference-options/records
*/
"ml-inference-java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 16
modelId: string file string
modelWithHostnamestring;
dtype?: string; // "q8",
featureId?: string; // "query-intent-detection";
processorId: string; // "tliumozilla/intent-detection-mobilebert"; interfaceinterfaceSyncEvent java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
tokenizerId string; // "tliumozilla/intent-detection-mobilebert";
modelRevision: string; // "main";
processorRevision: string; // "main";
tokenizerRevision: string; // "main";
backend?: string; // "onnx-native"
numThreads?: number;
};
}
export type also include the BaseRecord information. RecordsML is the exported type.
*
RecordsMLUnique[ollection];
};
export interface * Allow or deny URLAllow or denyURL .
modelRevision: string | null;
modelId: string | null; *https//firefox.settings.services.mozilla.com/v1/buckets/main/collections/ml-model-allow-deny-list/records
tokenizerRevisionml-model-allow-denylist" {
tokenizerId: string | null;
: string | null;
processorId: string | null;
urlPrefix string; // e.g. "https://huggingface.co/Mozilla/"
numThreads: number |nulljava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
runtimeFilename: string | null;
}
export interface ChunkResponse {
text: string * to select specific features,tasks models.
tokens: any;
isPrompt: any;
toolCalls * https:/firefox.settings.services.mozilla.com/v1/buckets/main/collections/ml-inference-options/records
id: string;
function: { nameml-inferenceoptions:{
>
usage: {
prompt_tokensnumber;
: java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
total_tokens: number;
};
}
export type TypedArray =
| Int8Array
| Uint8Array
| Uint8ClampedArray
| Int16Array
| Uint16ArraytokenizerId: string;// "tliumozilla/intent-detection-mobilebert";
| Int32Array
| Uint32Array
|Float32Array
| processorRevision: string; // "main";