@trymirai/uzu 0.2.10 → 0.3.0
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 +52 -6
- package/bridging/classificationLabel.d.mts +12 -0
- package/bridging/classificationLabel.d.mts.map +1 -0
- package/bridging/classificationLabel.d.ts +12 -0
- package/bridging/classificationLabel.d.ts.map +1 -0
- package/bridging/classificationLabel.js +26 -0
- package/bridging/classificationLabel.js.map +1 -0
- package/bridging/classificationLabel.mjs +22 -0
- package/bridging/classificationLabel.mjs.map +1 -0
- package/bridging/classificationOutput.d.mts +10 -0
- package/bridging/classificationOutput.d.mts.map +1 -0
- package/bridging/classificationOutput.d.ts +10 -0
- package/bridging/classificationOutput.d.ts.map +1 -0
- package/bridging/classificationOutput.js +16 -0
- package/bridging/classificationOutput.js.map +1 -0
- package/bridging/classificationOutput.mjs +12 -0
- package/bridging/classificationOutput.mjs.map +1 -0
- package/bridging/classificationSession.d.mts +9 -0
- package/bridging/classificationSession.d.mts.map +1 -0
- package/bridging/classificationSession.d.ts +9 -0
- package/bridging/classificationSession.d.ts.map +1 -0
- package/bridging/classificationSession.js +16 -0
- package/bridging/classificationSession.js.map +1 -0
- package/bridging/classificationSession.mjs +12 -0
- package/bridging/classificationSession.mjs.map +1 -0
- package/bridging/classificationStats.d.mts +14 -0
- package/bridging/classificationStats.d.mts.map +1 -0
- package/bridging/classificationStats.d.ts +14 -0
- package/bridging/classificationStats.d.ts.map +1 -0
- package/bridging/classificationStats.js +20 -0
- package/bridging/classificationStats.js.map +1 -0
- package/bridging/classificationStats.mjs +16 -0
- package/bridging/classificationStats.mjs.map +1 -0
- package/bridging/engine.d.mts +14 -6
- package/bridging/engine.d.mts.map +1 -1
- package/bridging/engine.d.ts +14 -6
- package/bridging/engine.d.ts.map +1 -1
- package/bridging/engine.js +53 -23
- package/bridging/engine.js.map +1 -1
- package/bridging/engine.mjs +53 -23
- package/bridging/engine.mjs.map +1 -1
- package/bridging/model.d.mts +19 -0
- package/bridging/model.d.mts.map +1 -0
- package/bridging/model.d.ts +19 -0
- package/bridging/model.d.ts.map +1 -0
- package/bridging/model.js +39 -0
- package/bridging/model.js.map +1 -0
- package/bridging/model.mjs +35 -0
- package/bridging/model.mjs.map +1 -0
- package/bridging/modelKind.d.mts +8 -0
- package/bridging/modelKind.d.mts.map +1 -0
- package/bridging/modelKind.d.ts +8 -0
- package/bridging/modelKind.d.ts.map +1 -0
- package/bridging/modelKind.js +30 -0
- package/bridging/modelKind.js.map +1 -0
- package/bridging/modelKind.mjs +25 -0
- package/bridging/modelKind.mjs.map +1 -0
- package/bridging/modelType.d.mts +3 -2
- package/bridging/modelType.d.mts.map +1 -1
- package/bridging/modelType.d.ts +3 -2
- package/bridging/modelType.d.ts.map +1 -1
- package/bridging/modelType.js +11 -6
- package/bridging/modelType.js.map +1 -1
- package/bridging/modelType.mjs +11 -6
- package/bridging/modelType.mjs.map +1 -1
- package/bridging/preset.d.mts +2 -0
- package/bridging/preset.d.mts.map +1 -1
- package/bridging/preset.d.ts +2 -0
- package/bridging/preset.d.ts.map +1 -1
- package/bridging/preset.js +12 -0
- package/bridging/preset.js.map +1 -1
- package/bridging/preset.mjs +12 -0
- package/bridging/preset.mjs.map +1 -1
- package/bridging/samplingMethod.d.mts +2 -1
- package/bridging/samplingMethod.d.mts.map +1 -1
- package/bridging/samplingMethod.d.ts +2 -1
- package/bridging/samplingMethod.d.ts.map +1 -1
- package/bridging/samplingMethod.js +3 -1
- package/bridging/samplingMethod.js.map +1 -1
- package/bridging/samplingMethod.mjs +3 -1
- package/bridging/samplingMethod.mjs.map +1 -1
- package/bridging/samplingProcessingOrder.d.mts +8 -0
- package/bridging/samplingProcessingOrder.d.mts.map +1 -0
- package/bridging/samplingProcessingOrder.d.ts +8 -0
- package/bridging/samplingProcessingOrder.d.ts.map +1 -0
- package/bridging/samplingProcessingOrder.js +30 -0
- package/bridging/samplingProcessingOrder.js.map +1 -0
- package/bridging/samplingProcessingOrder.mjs +25 -0
- package/bridging/samplingProcessingOrder.mjs.map +1 -0
- package/bridging/textToSpeechSession.d.mts +8 -0
- package/bridging/textToSpeechSession.d.mts.map +1 -0
- package/bridging/textToSpeechSession.d.ts +8 -0
- package/bridging/textToSpeechSession.d.ts.map +1 -0
- package/bridging/textToSpeechSession.js +14 -0
- package/bridging/textToSpeechSession.js.map +1 -0
- package/bridging/textToSpeechSession.mjs +10 -0
- package/bridging/textToSpeechSession.mjs.map +1 -0
- package/error.d.mts +2 -0
- package/error.d.mts.map +1 -1
- package/error.d.ts +2 -0
- package/error.d.ts.map +1 -1
- package/error.js +4 -0
- package/error.js.map +1 -1
- package/error.mjs +4 -0
- package/error.mjs.map +1 -1
- package/index.d.mts +8 -1
- package/index.d.mts.map +1 -1
- package/index.d.ts +8 -1
- package/index.d.ts.map +1 -1
- package/index.js +17 -3
- package/index.js.map +1 -1
- package/index.mjs +8 -1
- package/index.mjs.map +1 -1
- package/interactors/chatModelInteractor.d.mts +5 -5
- package/interactors/chatModelInteractor.d.mts.map +1 -1
- package/interactors/chatModelInteractor.d.ts +5 -5
- package/interactors/chatModelInteractor.d.ts.map +1 -1
- package/interactors/chatModelInteractor.js +2 -2
- package/interactors/chatModelInteractor.js.map +1 -1
- package/interactors/chatModelInteractor.mjs +2 -2
- package/interactors/chatModelInteractor.mjs.map +1 -1
- package/interactors/chatModelsInteractor.d.mts +5 -5
- package/interactors/chatModelsInteractor.d.mts.map +1 -1
- package/interactors/chatModelsInteractor.d.ts +5 -5
- package/interactors/chatModelsInteractor.d.ts.map +1 -1
- package/interactors/chatModelsInteractor.js.map +1 -1
- package/interactors/chatModelsInteractor.mjs.map +1 -1
- package/interactors/engineInteractor.d.mts +4 -4
- package/interactors/engineInteractor.d.ts +4 -4
- package/interactors/engineInteractor.js +5 -5
- package/interactors/engineInteractor.mjs +5 -5
- package/napi/uzu.d.ts +69 -15
- package/napi/uzu.js +16 -2
- package/napi/uzu.mjs +8 -1
- package/napi/uzu.node +0 -0
- package/package.json +1 -1
- package/src/bridging/classificationLabel.ts +43 -0
- package/src/bridging/classificationOutput.ts +22 -0
- package/src/bridging/classificationSession.ts +17 -0
- package/src/bridging/classificationStats.ts +45 -0
- package/src/bridging/engine.ts +62 -26
- package/src/bridging/model.ts +68 -0
- package/src/bridging/modelKind.ts +27 -0
- package/src/bridging/modelType.ts +11 -6
- package/src/bridging/preset.ts +14 -0
- package/src/bridging/samplingMethod.ts +6 -0
- package/src/bridging/samplingProcessingOrder.ts +31 -0
- package/src/bridging/textToSpeechSession.ts +15 -0
- package/src/error.ts +4 -0
- package/src/index.ts +8 -1
- package/src/interactors/chatModelInteractor.ts +7 -7
- package/src/interactors/chatModelsInteractor.ts +5 -5
- package/src/interactors/engineInteractor.ts +7 -7
- package/src/napi/uzu.d.ts +69 -15
- package/src/napi/uzu.js +16 -2
- package/src/napi/uzu.mjs +8 -1
- package/src/napi/uzu.node +0 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.mts.map +1 -1
- package/version.d.ts +1 -1
- package/version.d.ts.map +1 -1
- package/version.js +1 -1
- package/version.js.map +1 -1
- package/version.mjs +1 -1
- package/version.mjs.map +1 -1
- package/bridging/chatModel.d.mts +0 -15
- package/bridging/chatModel.d.mts.map +0 -1
- package/bridging/chatModel.d.ts +0 -15
- package/bridging/chatModel.d.ts.map +0 -1
- package/bridging/chatModel.js +0 -33
- package/bridging/chatModel.js.map +0 -1
- package/bridging/chatModel.mjs +0 -29
- package/bridging/chatModel.mjs.map +0 -1
- package/src/bridging/chatModel.ts +0 -54
package/src/bridging/engine.ts
CHANGED
|
@@ -2,14 +2,16 @@ import { EngineError, EngineErrorCode, unwrapOrThrow } from '../error';
|
|
|
2
2
|
import { EngineInteractor } from '../interactors/engineInteractor';
|
|
3
3
|
import { Engine as NapiEngine } from '../napi/uzu';
|
|
4
4
|
import { readEnv } from '../utilities/env';
|
|
5
|
-
import { ChatModel } from './chatModel';
|
|
6
5
|
import { ChatSession } from './chatSession';
|
|
6
|
+
import { ClassificationSession } from './classificationSession';
|
|
7
7
|
import { Config } from './config';
|
|
8
8
|
import { DownloadHandle } from './downloadHandle';
|
|
9
9
|
import { DownloadProgressUpdate } from './downloadProgressUpdate';
|
|
10
10
|
import { DownloadPhase, DownloadState } from './downloadState';
|
|
11
11
|
import { LicenseStatus, licenseStatusFromNapiLicenseStatus } from './licenseStatus';
|
|
12
|
-
import {
|
|
12
|
+
import { Model } from './model';
|
|
13
|
+
import { ModelKind, modelKindToNapiModelKind } from './modelKind';
|
|
14
|
+
import { TextToSpeechSession } from './textToSpeechSession';
|
|
13
15
|
|
|
14
16
|
export class Engine {
|
|
15
17
|
private readonly napiEngine: NapiEngine;
|
|
@@ -55,32 +57,18 @@ export class Engine {
|
|
|
55
57
|
return new DownloadHandle(this.napiEngine.createModelDownloadHandle(repoId));
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
let napiModelTypes = typesToFilter.map(modelTypeToNapiModelType);
|
|
61
|
-
let napiChatModels = await this.napiEngine.getChatModels(napiModelTypes);
|
|
62
|
-
let results: ChatModel[] = napiChatModels.map(ChatModel.fromNapiChatModel);
|
|
63
|
-
return results;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
async chatModel(repoId: string, types: ModelType[] | null = null): Promise<ChatModel> {
|
|
67
|
-
const chatModels = await this.chatModels(types);
|
|
68
|
-
const chatModel = chatModels.find((model) => model.repoId === repoId);
|
|
69
|
-
return unwrapOrThrow(chatModel, EngineErrorCode.ModelNotFound);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async downloadChatModel(
|
|
73
|
-
chatModel: ChatModel,
|
|
60
|
+
async downloadModel(
|
|
61
|
+
model: Model,
|
|
74
62
|
progress: (progressUpdate: DownloadProgressUpdate) => void = () => {},
|
|
75
63
|
): Promise<DownloadState> {
|
|
76
|
-
switch (
|
|
77
|
-
case
|
|
64
|
+
switch (model.kind) {
|
|
65
|
+
case ModelKind.Local:
|
|
78
66
|
break;
|
|
79
|
-
case
|
|
80
|
-
throw new EngineError(EngineErrorCode.
|
|
67
|
+
case ModelKind.Cloud:
|
|
68
|
+
throw new EngineError(EngineErrorCode.UnexpectedModelKind);
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
const downloadHandle = this.downloadHandle(
|
|
71
|
+
const downloadHandle = this.downloadHandle(model.repoId);
|
|
84
72
|
const state = await downloadHandle.state();
|
|
85
73
|
switch (state.phase) {
|
|
86
74
|
case DownloadPhase.Downloaded:
|
|
@@ -97,9 +85,57 @@ export class Engine {
|
|
|
97
85
|
return finalState;
|
|
98
86
|
}
|
|
99
87
|
|
|
100
|
-
|
|
101
|
-
|
|
88
|
+
async chatModels(kinds: ModelKind[] | null = null): Promise<Model[]> {
|
|
89
|
+
let kindsToFilter: ModelKind[] = kinds ?? [ModelKind.Local, ModelKind.Cloud];
|
|
90
|
+
let napiModelKinds = kindsToFilter.map(modelKindToNapiModelKind);
|
|
91
|
+
let napiChatModels = await this.napiEngine.getChatModels(napiModelKinds);
|
|
92
|
+
let results: Model[] = napiChatModels.map(Model.fromNapiModel);
|
|
93
|
+
return results;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async chatModel(repoId: string, kinds: ModelKind[] | null = null): Promise<Model> {
|
|
97
|
+
const chatModels = await this.chatModels(kinds);
|
|
98
|
+
const chatModel = chatModels.find((model) => model.repoId === repoId);
|
|
99
|
+
return unwrapOrThrow(chatModel, EngineErrorCode.ModelNotFound);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
chatSession(model: Model, config: Config = Config.default()): ChatSession {
|
|
103
|
+
const napiModel = model.toNapi();
|
|
102
104
|
const napiConfig = config.toNapi();
|
|
103
|
-
return new ChatSession(this.napiEngine.createChatSession(
|
|
105
|
+
return new ChatSession(this.napiEngine.createChatSession(napiModel, napiConfig));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async classificationModels(): Promise<Model[]> {
|
|
109
|
+
const napiClassificationModels = await this.napiEngine.getClassificationModels();
|
|
110
|
+
const results: Model[] = napiClassificationModels.map(Model.fromNapiModel);
|
|
111
|
+
return results;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async classificationModel(repoId: string): Promise<Model> {
|
|
115
|
+
const classificationModels = await this.classificationModels();
|
|
116
|
+
const classificationModel = classificationModels.find((model) => model.repoId === repoId);
|
|
117
|
+
return unwrapOrThrow(classificationModel, EngineErrorCode.ModelNotFound);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
classificationSession(model: Model): ClassificationSession {
|
|
121
|
+
const napiModel = model.toNapi();
|
|
122
|
+
return new ClassificationSession(this.napiEngine.createClassificationSession(napiModel));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async textToSpeechModels(): Promise<Model[]> {
|
|
126
|
+
const napiTextToSpeechModels = await this.napiEngine.getTextToSpeechModels();
|
|
127
|
+
const results: Model[] = napiTextToSpeechModels.map(Model.fromNapiModel);
|
|
128
|
+
return results;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async textToSpeechModel(repoId: string): Promise<Model> {
|
|
132
|
+
const textToSpeechModels = await this.textToSpeechModels();
|
|
133
|
+
const textToSpeechModel = textToSpeechModels.find((model) => model.repoId === repoId);
|
|
134
|
+
return unwrapOrThrow(textToSpeechModel, EngineErrorCode.ModelNotFound);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
textToSpeechSession(model: Model): TextToSpeechSession {
|
|
138
|
+
const napiModel = model.toNapi();
|
|
139
|
+
return new TextToSpeechSession(this.napiEngine.createTextToSpeechSession(napiModel));
|
|
104
140
|
}
|
|
105
141
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Model as NapiModel } from '../napi/uzu';
|
|
2
|
+
import { ClassificationLabel } from './classificationLabel';
|
|
3
|
+
import { ModelKind, modelKindFromNapiModelKind, modelKindToNapiModelKind } from './modelKind';
|
|
4
|
+
import { ModelType, modelTypeFromNapiModelType, modelTypeToNapiModelType } from './modelType';
|
|
5
|
+
|
|
6
|
+
export class Model {
|
|
7
|
+
readonly repoId: string;
|
|
8
|
+
readonly type: ModelType;
|
|
9
|
+
readonly kind: ModelKind;
|
|
10
|
+
readonly name: string;
|
|
11
|
+
readonly vendor: string;
|
|
12
|
+
readonly quantization: string | null;
|
|
13
|
+
readonly outputParserRegex: string | null;
|
|
14
|
+
readonly classificationLabels: ClassificationLabel[];
|
|
15
|
+
|
|
16
|
+
get isThinking(): boolean {
|
|
17
|
+
return this.outputParserRegex !== null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private constructor(
|
|
21
|
+
repoId: string,
|
|
22
|
+
type: ModelType,
|
|
23
|
+
kind: ModelKind,
|
|
24
|
+
name: string,
|
|
25
|
+
vendor: string,
|
|
26
|
+
quantization: string | null,
|
|
27
|
+
outputParserRegex: string | null,
|
|
28
|
+
classificationLabels: ClassificationLabel[],
|
|
29
|
+
) {
|
|
30
|
+
this.repoId = repoId;
|
|
31
|
+
this.type = type;
|
|
32
|
+
this.kind = kind;
|
|
33
|
+
this.name = name;
|
|
34
|
+
this.vendor = vendor;
|
|
35
|
+
this.quantization = quantization;
|
|
36
|
+
this.outputParserRegex = outputParserRegex;
|
|
37
|
+
this.classificationLabels = classificationLabels;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static fromNapiModel(napiModel: NapiModel): Model {
|
|
41
|
+
return new Model(
|
|
42
|
+
napiModel.repoId,
|
|
43
|
+
modelTypeFromNapiModelType(napiModel.type),
|
|
44
|
+
modelKindFromNapiModelKind(napiModel.kind),
|
|
45
|
+
napiModel.name,
|
|
46
|
+
napiModel.vendor,
|
|
47
|
+
napiModel.quantization ?? null,
|
|
48
|
+
napiModel.outputParserRegex ?? null,
|
|
49
|
+
napiModel.classificationLabels.map(ClassificationLabel.fromNapi),
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
toNapi(): NapiModel {
|
|
54
|
+
const napiModel: NapiModel = {
|
|
55
|
+
repoId: this.repoId,
|
|
56
|
+
type: modelTypeToNapiModelType(this.type),
|
|
57
|
+
kind: modelKindToNapiModelKind(this.kind),
|
|
58
|
+
name: this.name,
|
|
59
|
+
vendor: this.vendor,
|
|
60
|
+
...(this.quantization !== null && { quantization: this.quantization }),
|
|
61
|
+
...(this.outputParserRegex !== null && { outputParserRegex: this.outputParserRegex }),
|
|
62
|
+
classificationLabels: this.classificationLabels.map((classificationLabel) =>
|
|
63
|
+
classificationLabel.toNapi(),
|
|
64
|
+
),
|
|
65
|
+
};
|
|
66
|
+
return napiModel;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '../error';
|
|
2
|
+
import { ModelKind as NapiModelKind } from '../napi/uzu';
|
|
3
|
+
|
|
4
|
+
export enum ModelKind {
|
|
5
|
+
Local = 'Local',
|
|
6
|
+
Cloud = 'Cloud',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function modelKindFromNapiModelKind(napiModelKind: NapiModelKind): ModelKind {
|
|
10
|
+
switch (napiModelKind) {
|
|
11
|
+
case 0:
|
|
12
|
+
return ModelKind.Local;
|
|
13
|
+
case 1:
|
|
14
|
+
return ModelKind.Cloud;
|
|
15
|
+
default:
|
|
16
|
+
throw new EngineError(EngineErrorCode.UnexpectedModelKind);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function modelKindToNapiModelKind(modelKind: ModelKind): NapiModelKind {
|
|
21
|
+
switch (modelKind) {
|
|
22
|
+
case ModelKind.Local:
|
|
23
|
+
return 0;
|
|
24
|
+
case ModelKind.Cloud:
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -2,16 +2,19 @@ import { EngineError, EngineErrorCode } from '../error';
|
|
|
2
2
|
import { ModelType as NapiModelType } from '../napi/uzu';
|
|
3
3
|
|
|
4
4
|
export enum ModelType {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
Chat = 'Chat',
|
|
6
|
+
Classification = 'Classification',
|
|
7
|
+
TTS = 'TTS',
|
|
7
8
|
}
|
|
8
9
|
|
|
9
10
|
export function modelTypeFromNapiModelType(napiModelType: NapiModelType): ModelType {
|
|
10
11
|
switch (napiModelType) {
|
|
11
12
|
case 0:
|
|
12
|
-
return ModelType.
|
|
13
|
+
return ModelType.Chat;
|
|
13
14
|
case 1:
|
|
14
|
-
return ModelType.
|
|
15
|
+
return ModelType.Classification;
|
|
16
|
+
case 2:
|
|
17
|
+
return ModelType.TTS;
|
|
15
18
|
default:
|
|
16
19
|
throw new EngineError(EngineErrorCode.UnexpectedModelType);
|
|
17
20
|
}
|
|
@@ -19,9 +22,11 @@ export function modelTypeFromNapiModelType(napiModelType: NapiModelType): ModelT
|
|
|
19
22
|
|
|
20
23
|
export function modelTypeToNapiModelType(modelType: ModelType): NapiModelType {
|
|
21
24
|
switch (modelType) {
|
|
22
|
-
case ModelType.
|
|
25
|
+
case ModelType.Chat:
|
|
23
26
|
return 0;
|
|
24
|
-
case ModelType.
|
|
27
|
+
case ModelType.Classification:
|
|
25
28
|
return 1;
|
|
29
|
+
case ModelType.TTS:
|
|
30
|
+
return 2;
|
|
26
31
|
}
|
|
27
32
|
}
|
package/src/bridging/preset.ts
CHANGED
|
@@ -28,6 +28,20 @@ export class Preset implements ToNapi<NapiPreset> {
|
|
|
28
28
|
return new Preset(napiPreset);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
static nGramSpeculator(useCase: string, numberOfSpeculatedTokens: number): Preset {
|
|
32
|
+
const napiPreset: NapiPreset = {
|
|
33
|
+
type: 'NGramSpeculator',
|
|
34
|
+
useCase,
|
|
35
|
+
numberOfSpeculatedTokens,
|
|
36
|
+
};
|
|
37
|
+
return new Preset(napiPreset);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static chat(): Preset {
|
|
41
|
+
const napiPreset: NapiPreset = { type: 'Chat' };
|
|
42
|
+
return new Preset(napiPreset);
|
|
43
|
+
}
|
|
44
|
+
|
|
31
45
|
toNapi(): NapiPreset {
|
|
32
46
|
return this.napiPreset;
|
|
33
47
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { SamplingMethod as NapiSamplingMethod } from '../napi/uzu';
|
|
2
2
|
import { ToNapi } from './napi';
|
|
3
|
+
import {
|
|
4
|
+
SamplingProcessingOrder,
|
|
5
|
+
samplingProcessingOrderToNapiSamplingProcessingOrder,
|
|
6
|
+
} from './samplingProcessingOrder';
|
|
3
7
|
|
|
4
8
|
export class SamplingMethod implements ToNapi<NapiSamplingMethod> {
|
|
5
9
|
private readonly napiSamplingMethod: NapiSamplingMethod;
|
|
@@ -18,9 +22,11 @@ export class SamplingMethod implements ToNapi<NapiSamplingMethod> {
|
|
|
18
22
|
topK: number | null,
|
|
19
23
|
topP: number | null,
|
|
20
24
|
minP: number | null,
|
|
25
|
+
processingOrder: SamplingProcessingOrder,
|
|
21
26
|
): SamplingMethod {
|
|
22
27
|
let napiSamplingMethod: NapiSamplingMethod = {
|
|
23
28
|
type: 'Stochastic',
|
|
29
|
+
processingOrder: samplingProcessingOrderToNapiSamplingProcessingOrder(processingOrder),
|
|
24
30
|
};
|
|
25
31
|
if (temperature !== null) {
|
|
26
32
|
napiSamplingMethod.temperature = temperature;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '../error';
|
|
2
|
+
import { SamplingProcessingOrder as NapiSamplingProcessingOrder } from '../napi/uzu';
|
|
3
|
+
|
|
4
|
+
export enum SamplingProcessingOrder {
|
|
5
|
+
TemperatureThenFilters = 'TemperatureThenFilters',
|
|
6
|
+
FiltersThenTemperature = 'FiltersThenTemperature',
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function samplingProcessingOrderFromNapiSamplingProcessingOrder(
|
|
10
|
+
napiSamplingProcessingOrder: NapiSamplingProcessingOrder,
|
|
11
|
+
): SamplingProcessingOrder {
|
|
12
|
+
switch (napiSamplingProcessingOrder) {
|
|
13
|
+
case 0:
|
|
14
|
+
return SamplingProcessingOrder.TemperatureThenFilters;
|
|
15
|
+
case 1:
|
|
16
|
+
return SamplingProcessingOrder.FiltersThenTemperature;
|
|
17
|
+
default:
|
|
18
|
+
throw new EngineError(EngineErrorCode.UnexpectedSamplingProcessingOrder);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function samplingProcessingOrderToNapiSamplingProcessingOrder(
|
|
23
|
+
samplingProcessingOrder: SamplingProcessingOrder,
|
|
24
|
+
): NapiSamplingProcessingOrder {
|
|
25
|
+
switch (samplingProcessingOrder) {
|
|
26
|
+
case SamplingProcessingOrder.TemperatureThenFilters:
|
|
27
|
+
return 0;
|
|
28
|
+
case SamplingProcessingOrder.FiltersThenTemperature:
|
|
29
|
+
return 1;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TextToSpeechSession as NapiTextToSpeechSession } from '../napi/uzu';
|
|
2
|
+
import { Input } from './input';
|
|
3
|
+
|
|
4
|
+
export class TextToSpeechSession {
|
|
5
|
+
private readonly napiTextToSpeechSession: NapiTextToSpeechSession;
|
|
6
|
+
|
|
7
|
+
constructor(napiTextToSpeechSession: NapiTextToSpeechSession) {
|
|
8
|
+
this.napiTextToSpeechSession = napiTextToSpeechSession;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
run(input: Input, outputPath: string): void {
|
|
12
|
+
const napiInput = input.toNapi();
|
|
13
|
+
this.napiTextToSpeechSession.run(napiInput, outputPath);
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/error.ts
CHANGED
|
@@ -6,6 +6,8 @@ export enum EngineErrorCode {
|
|
|
6
6
|
UnexpectedFinishReason = 'unexpectedFinishReason',
|
|
7
7
|
UnexpectedLicenseStatus = 'unexpectedLicenseStatus',
|
|
8
8
|
UnexpectedModelType = 'unexpectedModelType',
|
|
9
|
+
UnexpectedModelKind = 'unexpectedModelKind',
|
|
10
|
+
UnexpectedSamplingProcessingOrder = 'unexpectedSamplingProcessingOrder',
|
|
9
11
|
LicenseNotActivated = 'licenseNotActivated',
|
|
10
12
|
Unknown = 'unknown',
|
|
11
13
|
}
|
|
@@ -18,6 +20,8 @@ const errorCodeToMessage = {
|
|
|
18
20
|
[EngineErrorCode.UnexpectedFinishReason]: 'Unexpected finish reason',
|
|
19
21
|
[EngineErrorCode.UnexpectedLicenseStatus]: 'Unexpected license status',
|
|
20
22
|
[EngineErrorCode.UnexpectedModelType]: 'Unexpected model type',
|
|
23
|
+
[EngineErrorCode.UnexpectedModelKind]: 'Unexpected model kind',
|
|
24
|
+
[EngineErrorCode.UnexpectedSamplingProcessingOrder]: 'Unexpected sampling processing order',
|
|
21
25
|
[EngineErrorCode.LicenseNotActivated]: 'License not activated',
|
|
22
26
|
[EngineErrorCode.Unknown]: 'Unknown error',
|
|
23
27
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
export { AsyncBatchSize } from './bridging/asyncBatchSize';
|
|
2
|
-
export { ChatModel } from './bridging/chatModel';
|
|
3
2
|
export { ChatSession } from './bridging/chatSession';
|
|
4
3
|
export { ClassificationFeature } from './bridging/classificationFeature';
|
|
4
|
+
export { ClassificationLabel } from './bridging/classificationLabel';
|
|
5
|
+
export { ClassificationOutput } from './bridging/classificationOutput';
|
|
6
|
+
export { ClassificationSession } from './bridging/classificationSession';
|
|
7
|
+
export { ClassificationStats } from './bridging/classificationStats';
|
|
5
8
|
export { Config } from './bridging/config';
|
|
6
9
|
export { ContextLength } from './bridging/contextLength';
|
|
7
10
|
export { ContextMode } from './bridging/contextMode';
|
|
@@ -13,6 +16,8 @@ export { FinishReason } from './bridging/finishReason';
|
|
|
13
16
|
export { GrammarConfig } from './bridging/grammarConfig';
|
|
14
17
|
export { Input } from './bridging/input';
|
|
15
18
|
export { Message } from './bridging/message';
|
|
19
|
+
export { Model } from './bridging/model';
|
|
20
|
+
export { ModelKind } from './bridging/modelKind';
|
|
16
21
|
export { ModelType } from './bridging/modelType';
|
|
17
22
|
export { Output } from './bridging/output';
|
|
18
23
|
export { ParsedText } from './bridging/parsedText';
|
|
@@ -23,10 +28,12 @@ export { RunConfig } from './bridging/runConfig';
|
|
|
23
28
|
export { RunStats } from './bridging/runStats';
|
|
24
29
|
export { SamplingMethod } from './bridging/samplingMethod';
|
|
25
30
|
export { SamplingPolicy } from './bridging/samplingPolicy';
|
|
31
|
+
export { SamplingProcessingOrder } from './bridging/samplingProcessingOrder';
|
|
26
32
|
export { SamplingSeed } from './bridging/samplingSeed';
|
|
27
33
|
export { Stats } from './bridging/stats';
|
|
28
34
|
export { StepStats } from './bridging/stepStats';
|
|
29
35
|
export { Text } from './bridging/text';
|
|
36
|
+
export { TextToSpeechSession } from './bridging/textToSpeechSession';
|
|
30
37
|
export { TotalStats } from './bridging/totalStats';
|
|
31
38
|
export { EngineError } from './error';
|
|
32
39
|
export { ChatModelInteractor } from './interactors/chatModelInteractor';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { AsyncBatchSize } from '../bridging/asyncBatchSize';
|
|
2
|
-
import { ChatModel } from '../bridging/chatModel';
|
|
3
2
|
import { Config } from '../bridging/config';
|
|
4
3
|
import { ContextLength } from '../bridging/contextLength';
|
|
5
4
|
import { ContextMode } from '../bridging/contextMode';
|
|
6
5
|
import { DownloadProgressUpdate } from '../bridging/downloadProgressUpdate';
|
|
7
6
|
import { DownloadPhase } from '../bridging/downloadState';
|
|
8
7
|
import { Message } from '../bridging/message';
|
|
9
|
-
import {
|
|
8
|
+
import { Model } from '../bridging/model';
|
|
9
|
+
import { ModelKind } from '../bridging/modelKind';
|
|
10
10
|
import { Output } from '../bridging/output';
|
|
11
11
|
import { PrefillStepSize } from '../bridging/prefillStepSize';
|
|
12
12
|
import { Preset } from '../bridging/preset';
|
|
@@ -17,18 +17,18 @@ import { ChatSessionInteractor } from './chatSessionInteractor';
|
|
|
17
17
|
import { DownloadInteractor } from './downloadInteractor';
|
|
18
18
|
import { Interactor, InteractorEntity } from './interactor';
|
|
19
19
|
|
|
20
|
-
export class ChatModelInteractor implements Interactor<
|
|
20
|
+
export class ChatModelInteractor implements Interactor<Model> {
|
|
21
21
|
readonly modelsInteractor: ChatModelsInteractor;
|
|
22
|
-
readonly entity: InteractorEntity<
|
|
22
|
+
readonly entity: InteractorEntity<Model>;
|
|
23
23
|
readonly config: Config;
|
|
24
24
|
|
|
25
|
-
constructor(modelsInteractor: ChatModelsInteractor, model: InteractorEntity<
|
|
25
|
+
constructor(modelsInteractor: ChatModelsInteractor, model: InteractorEntity<Model>, config: Config) {
|
|
26
26
|
this.modelsInteractor = modelsInteractor;
|
|
27
27
|
this.entity = model;
|
|
28
28
|
this.config = config;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
async finalize(): Promise<
|
|
31
|
+
async finalize(): Promise<Model> {
|
|
32
32
|
return await this.entity;
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -103,7 +103,7 @@ export class ChatModelInteractor implements Interactor<ChatModel> {
|
|
|
103
103
|
const engine = await this.modelsInteractor.engineInteractor.finalize();
|
|
104
104
|
|
|
105
105
|
let model = await this.finalize();
|
|
106
|
-
if (model.
|
|
106
|
+
if (model.kind === ModelKind.Local) {
|
|
107
107
|
model = await this.download().finalize();
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { ChatModel } from '../bridging/chatModel';
|
|
2
1
|
import { Config } from '../bridging/config';
|
|
2
|
+
import { Model } from '../bridging/model';
|
|
3
3
|
import { EngineErrorCode, unwrapOrThrow } from '../error';
|
|
4
4
|
import { ChatModelInteractor } from './chatModelInteractor';
|
|
5
5
|
import { EngineInteractor } from './engineInteractor';
|
|
6
6
|
import { Interactor, InteractorEntity } from './interactor';
|
|
7
7
|
|
|
8
|
-
export class ChatModelsInteractor implements Interactor<
|
|
8
|
+
export class ChatModelsInteractor implements Interactor<Model[]> {
|
|
9
9
|
readonly engineInteractor: EngineInteractor;
|
|
10
|
-
readonly entity: InteractorEntity<
|
|
10
|
+
readonly entity: InteractorEntity<Model[]>;
|
|
11
11
|
|
|
12
|
-
constructor(engineInteractor: EngineInteractor, models: InteractorEntity<
|
|
12
|
+
constructor(engineInteractor: EngineInteractor, models: InteractorEntity<Model[]>) {
|
|
13
13
|
this.engineInteractor = engineInteractor;
|
|
14
14
|
this.entity = models;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
async finalize(): Promise<
|
|
17
|
+
async finalize(): Promise<Model[]> {
|
|
18
18
|
return await this.entity;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Engine } from '../bridging/engine';
|
|
2
|
-
import {
|
|
2
|
+
import { ModelKind } from '../bridging/modelKind';
|
|
3
3
|
import { ChatModelInteractor } from './chatModelInteractor';
|
|
4
4
|
import { ChatModelsInteractor } from './chatModelsInteractor';
|
|
5
5
|
import { Interactor, InteractorEntity } from './interactor';
|
|
6
6
|
|
|
7
7
|
export class EngineInteractor implements Interactor<Engine> {
|
|
8
8
|
readonly entity: InteractorEntity<Engine>;
|
|
9
|
-
readonly
|
|
9
|
+
readonly modelKindFilter: ModelKind[] | null;
|
|
10
10
|
|
|
11
|
-
constructor(engine: InteractorEntity<Engine>,
|
|
11
|
+
constructor(engine: InteractorEntity<Engine>, modelKindFilter: ModelKind[] | null = null) {
|
|
12
12
|
this.entity = engine;
|
|
13
|
-
this.
|
|
13
|
+
this.modelKindFilter = modelKindFilter;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async finalize(): Promise<Engine> {
|
|
@@ -19,14 +19,14 @@ export class EngineInteractor implements Interactor<Engine> {
|
|
|
19
19
|
|
|
20
20
|
/* Models */
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
return new EngineInteractor(this.entity,
|
|
22
|
+
filterKinds(kinds: ModelKind[] | null): EngineInteractor {
|
|
23
|
+
return new EngineInteractor(this.entity, kinds);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
chatModels(): ChatModelsInteractor {
|
|
27
27
|
const modelsPromise = (async () => {
|
|
28
28
|
const engine = await this.finalize();
|
|
29
|
-
return await engine.chatModels(this.
|
|
29
|
+
return await engine.chatModels(this.modelKindFilter);
|
|
30
30
|
})();
|
|
31
31
|
return new ChatModelsInteractor(this, modelsPromise);
|
|
32
32
|
}
|
package/src/napi/uzu.d.ts
CHANGED
|
@@ -5,17 +5,25 @@ export declare class ChatSession {
|
|
|
5
5
|
reset(): void
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
+
export declare class ClassificationSession {
|
|
9
|
+
run(input: Input): ClassificationOutput
|
|
10
|
+
}
|
|
11
|
+
|
|
8
12
|
export declare class Engine {
|
|
9
13
|
activate(apiKey: string): Promise<LicenseStatus>
|
|
10
|
-
getChatModels(
|
|
14
|
+
getChatModels(kinds: Array<ModelKind>): Promise<Array<Model>>
|
|
15
|
+
getTextToSpeechModels(): Promise<Array<Model>>
|
|
16
|
+
getClassificationModels(): Promise<Array<Model>>
|
|
11
17
|
getModelDownloadState(repoId: string): ModelDownloadState
|
|
12
18
|
createModelDownloadHandle(repoId: string): ModelDownloadHandle
|
|
13
19
|
benchmark(task: BenchmarksTask, prefillStepSize?: number | undefined | null): Promise<Array<BenchmarksResult>>
|
|
14
20
|
constructor()
|
|
15
|
-
createChatSession(model:
|
|
21
|
+
createChatSession(model: Model, config: Config): ChatSession
|
|
22
|
+
createTextToSpeechSession(model: Model): TextToSpeechSession
|
|
23
|
+
createClassificationSession(model: Model): ClassificationSession
|
|
16
24
|
registerLicenseStatusHandler(callback?: ((arg: LicenseStatus) => void) | undefined | null): void
|
|
17
25
|
registerModelDownloadStateHandler(callback?: ((arg0: string, arg1: ModelDownloadState) => void) | undefined | null): void
|
|
18
|
-
|
|
26
|
+
registerModelsHandler(callback?: ((arg: Array<Model>) => void) | undefined | null): void
|
|
19
27
|
}
|
|
20
28
|
|
|
21
29
|
export declare class ModelDownloadHandle {
|
|
@@ -40,6 +48,10 @@ export declare class ProgressUpdate {
|
|
|
40
48
|
progress: number
|
|
41
49
|
}
|
|
42
50
|
|
|
51
|
+
export declare class TextToSpeechSession {
|
|
52
|
+
run(input: Input, outputPath: string): void
|
|
53
|
+
}
|
|
54
|
+
|
|
43
55
|
export type AsyncBatchSize =
|
|
44
56
|
| { type: 'Default' }
|
|
45
57
|
| { type: 'Custom', size: number }
|
|
@@ -74,20 +86,36 @@ export interface BenchmarksTask {
|
|
|
74
86
|
greedy: boolean
|
|
75
87
|
}
|
|
76
88
|
|
|
77
|
-
export interface ChatModel {
|
|
78
|
-
readonly repoId: string
|
|
79
|
-
readonly type: ModelType
|
|
80
|
-
readonly name: string
|
|
81
|
-
readonly vendor: string
|
|
82
|
-
readonly quantization?: string
|
|
83
|
-
readonly outputParserRegex?: string
|
|
84
|
-
}
|
|
85
|
-
|
|
86
89
|
export interface ClassificationFeature {
|
|
87
90
|
name: string
|
|
88
91
|
values: Array<string>
|
|
89
92
|
}
|
|
90
93
|
|
|
94
|
+
export interface ClassificationLabel {
|
|
95
|
+
index: number
|
|
96
|
+
label: string
|
|
97
|
+
title: string
|
|
98
|
+
description: string
|
|
99
|
+
recommendedThreshold: number
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface ClassificationOutput {
|
|
103
|
+
logits: Array<number>
|
|
104
|
+
probabilities: Record<string, number>
|
|
105
|
+
stats: ClassificationStats
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ClassificationStats {
|
|
109
|
+
preprocessingDuration: number
|
|
110
|
+
forwardPassDuration: number
|
|
111
|
+
postprocessingDuration: number
|
|
112
|
+
totalDuration: number
|
|
113
|
+
tokensCount: number
|
|
114
|
+
tokensPerSecond: number
|
|
115
|
+
predictedLabel: string
|
|
116
|
+
confidence: number
|
|
117
|
+
}
|
|
118
|
+
|
|
91
119
|
export interface Config {
|
|
92
120
|
preset: Preset
|
|
93
121
|
contextMode: ContextMode
|
|
@@ -148,6 +176,17 @@ export interface Message {
|
|
|
148
176
|
reasoningContent?: string
|
|
149
177
|
}
|
|
150
178
|
|
|
179
|
+
export interface Model {
|
|
180
|
+
readonly repoId: string
|
|
181
|
+
readonly type: ModelType
|
|
182
|
+
readonly kind: ModelKind
|
|
183
|
+
readonly name: string
|
|
184
|
+
readonly vendor: string
|
|
185
|
+
readonly quantization?: string
|
|
186
|
+
readonly outputParserRegex?: string
|
|
187
|
+
readonly classificationLabels: Array<ClassificationLabel>
|
|
188
|
+
}
|
|
189
|
+
|
|
151
190
|
export declare const enum ModelDownloadPhase {
|
|
152
191
|
NotDownloaded = 0,
|
|
153
192
|
Downloading = 1,
|
|
@@ -168,6 +207,11 @@ export interface ModelDownloadState {
|
|
|
168
207
|
readonly error?: string
|
|
169
208
|
}
|
|
170
209
|
|
|
210
|
+
export declare const enum ModelKind {
|
|
211
|
+
Local = 0,
|
|
212
|
+
Cloud = 1
|
|
213
|
+
}
|
|
214
|
+
|
|
171
215
|
export type ModelStorageError =
|
|
172
216
|
| { type: 'Io', message: string }
|
|
173
217
|
| { type: 'Network', message: string }
|
|
@@ -179,8 +223,9 @@ export type ModelStorageError =
|
|
|
179
223
|
| { type: 'Paused' }
|
|
180
224
|
|
|
181
225
|
export declare const enum ModelType {
|
|
182
|
-
|
|
183
|
-
|
|
226
|
+
Chat = 0,
|
|
227
|
+
Classification = 1,
|
|
228
|
+
TTS = 2
|
|
184
229
|
}
|
|
185
230
|
|
|
186
231
|
export interface Output {
|
|
@@ -203,6 +248,8 @@ export type Preset =
|
|
|
203
248
|
| { type: 'General' }
|
|
204
249
|
| { type: 'Classification', feature: ClassificationFeature }
|
|
205
250
|
| { type: 'Summarization' }
|
|
251
|
+
| { type: 'NGramSpeculator', useCase: string, numberOfSpeculatedTokens: number }
|
|
252
|
+
| { type: 'Chat' }
|
|
206
253
|
|
|
207
254
|
export declare const enum Role {
|
|
208
255
|
System = 0,
|
|
@@ -224,12 +271,17 @@ export interface RunStats {
|
|
|
224
271
|
|
|
225
272
|
export type SamplingMethod =
|
|
226
273
|
| { type: 'Greedy' }
|
|
227
|
-
| { type: 'Stochastic', temperature?: number, topK?: number, topP?: number, minP?: number }
|
|
274
|
+
| { type: 'Stochastic', temperature?: number, topK?: number, topP?: number, minP?: number, processingOrder: SamplingProcessingOrder }
|
|
228
275
|
|
|
229
276
|
export type SamplingPolicy =
|
|
230
277
|
| { type: 'Default' }
|
|
231
278
|
| { type: 'Custom', value: SamplingMethod }
|
|
232
279
|
|
|
280
|
+
export declare const enum SamplingProcessingOrder {
|
|
281
|
+
TemperatureThenFilters = 0,
|
|
282
|
+
FiltersThenTemperature = 1
|
|
283
|
+
}
|
|
284
|
+
|
|
233
285
|
export type SamplingSeed =
|
|
234
286
|
| { type: 'Default' }
|
|
235
287
|
| { type: 'Custom', seed: number }
|
|
@@ -248,6 +300,8 @@ export interface StepStats {
|
|
|
248
300
|
processedTokensPerSecond: number
|
|
249
301
|
modelRun: RunStats
|
|
250
302
|
run?: RunStats
|
|
303
|
+
speculatorProposed: bigint
|
|
304
|
+
speculatorAccepted: bigint
|
|
251
305
|
}
|
|
252
306
|
|
|
253
307
|
export type StorageError =
|