@trymirai/uzu 0.1.39 → 0.1.42
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 +30 -6
- package/bridging/chatModel.d.mts +15 -0
- package/bridging/chatModel.d.mts.map +1 -0
- package/bridging/chatModel.d.ts +15 -0
- package/bridging/chatModel.d.ts.map +1 -0
- package/bridging/chatModel.js +33 -0
- package/bridging/chatModel.js.map +1 -0
- package/bridging/chatModel.mjs +29 -0
- package/bridging/chatModel.mjs.map +1 -0
- package/bridging/chatSession.d.mts +10 -0
- package/bridging/chatSession.d.mts.map +1 -0
- package/bridging/chatSession.d.ts +10 -0
- package/bridging/chatSession.d.ts.map +1 -0
- package/bridging/{session.js → chatSession.js} +7 -7
- package/bridging/chatSession.js.map +1 -0
- package/bridging/{session.mjs → chatSession.mjs} +5 -5
- package/bridging/chatSession.mjs.map +1 -0
- package/bridging/engine.d.mts +10 -10
- package/bridging/engine.d.mts.map +1 -1
- package/bridging/engine.d.ts +10 -10
- package/bridging/engine.d.ts.map +1 -1
- package/bridging/engine.js +42 -44
- package/bridging/engine.js.map +1 -1
- package/bridging/engine.mjs +43 -45
- package/bridging/engine.mjs.map +1 -1
- package/bridging/modelType.d.mts +2 -1
- package/bridging/modelType.d.mts.map +1 -1
- package/bridging/modelType.d.ts +2 -1
- package/bridging/modelType.d.ts.map +1 -1
- package/bridging/modelType.js +14 -2
- package/bridging/modelType.js.map +1 -1
- package/bridging/modelType.mjs +12 -1
- package/bridging/modelType.mjs.map +1 -1
- package/error.d.mts +1 -1
- package/error.d.mts.map +1 -1
- package/error.d.ts +1 -1
- package/error.d.ts.map +1 -1
- package/error.js +2 -2
- package/error.js.map +1 -1
- package/error.mjs +2 -2
- package/error.mjs.map +1 -1
- package/index.d.mts +5 -5
- package/index.d.mts.map +1 -1
- package/index.d.ts +5 -5
- package/index.d.ts.map +1 -1
- package/index.js +11 -12
- package/index.js.map +1 -1
- package/index.mjs +5 -5
- package/index.mjs.map +1 -1
- package/interactors/{modelInteractor.d.mts → chatModelInteractor.d.mts} +15 -15
- package/interactors/chatModelInteractor.d.mts.map +1 -0
- package/interactors/{modelInteractor.d.ts → chatModelInteractor.d.ts} +15 -15
- package/interactors/chatModelInteractor.d.ts.map +1 -0
- package/interactors/{modelInteractor.js → chatModelInteractor.js} +13 -13
- package/interactors/chatModelInteractor.js.map +1 -0
- package/interactors/{modelInteractor.mjs → chatModelInteractor.mjs} +11 -11
- package/interactors/chatModelInteractor.mjs.map +1 -0
- package/interactors/chatModelsInteractor.d.mts +12 -0
- package/interactors/chatModelsInteractor.d.mts.map +1 -0
- package/interactors/chatModelsInteractor.d.ts +12 -0
- package/interactors/chatModelsInteractor.d.ts.map +1 -0
- package/interactors/{modelsInteractor.js → chatModelsInteractor.js} +6 -6
- package/interactors/chatModelsInteractor.js.map +1 -0
- package/interactors/{modelsInteractor.mjs → chatModelsInteractor.mjs} +4 -4
- package/interactors/chatModelsInteractor.mjs.map +1 -0
- package/interactors/chatSessionInteractor.d.mts +24 -0
- package/interactors/chatSessionInteractor.d.mts.map +1 -0
- package/interactors/chatSessionInteractor.d.ts +24 -0
- package/interactors/chatSessionInteractor.d.ts.map +1 -0
- package/interactors/{sessionInteractor.js → chatSessionInteractor.js} +8 -8
- package/interactors/chatSessionInteractor.js.map +1 -0
- package/interactors/{sessionInteractor.mjs → chatSessionInteractor.mjs} +6 -6
- package/interactors/chatSessionInteractor.mjs.map +1 -0
- package/interactors/downloadInteractor.d.mts +3 -3
- package/interactors/downloadInteractor.d.mts.map +1 -1
- package/interactors/downloadInteractor.d.ts +3 -3
- package/interactors/downloadInteractor.d.ts.map +1 -1
- package/interactors/downloadInteractor.js.map +1 -1
- package/interactors/downloadInteractor.mjs.map +1 -1
- package/interactors/engineInteractor.d.mts +5 -8
- package/interactors/engineInteractor.d.mts.map +1 -1
- package/interactors/engineInteractor.d.ts +5 -8
- package/interactors/engineInteractor.d.ts.map +1 -1
- package/interactors/engineInteractor.js +8 -12
- package/interactors/engineInteractor.js.map +1 -1
- package/interactors/engineInteractor.mjs +8 -12
- package/interactors/engineInteractor.mjs.map +1 -1
- package/napi/uzu.d.ts +18 -32
- package/napi/uzu.js +4 -6
- package/napi/uzu.mjs +2 -3
- package/napi/uzu.node +0 -0
- package/package.json +1 -1
- package/src/bridging/chatModel.ts +54 -0
- package/src/bridging/{session.ts → chatSession.ts} +6 -6
- package/src/bridging/engine.ts +47 -47
- package/src/bridging/modelType.ts +13 -1
- package/src/error.ts +2 -2
- package/src/index.ts +5 -5
- package/src/interactors/{modelInteractor.ts → chatModelInteractor.ts} +22 -22
- package/src/interactors/{modelsInteractor.ts → chatModelsInteractor.ts} +8 -8
- package/src/interactors/{sessionInteractor.ts → chatSessionInteractor.ts} +19 -15
- package/src/interactors/downloadInteractor.ts +3 -3
- package/src/interactors/engineInteractor.ts +9 -20
- package/src/napi/uzu.d.ts +18 -32
- package/src/napi/uzu.js +4 -6
- package/src/napi/uzu.mjs +2 -3
- package/src/napi/uzu.node +0 -0
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
- package/bridging/model.d.mts +0 -18
- package/bridging/model.d.mts.map +0 -1
- package/bridging/model.d.ts +0 -18
- package/bridging/model.d.ts.map +0 -1
- package/bridging/model.js +0 -27
- package/bridging/model.js.map +0 -1
- package/bridging/model.mjs +0 -23
- package/bridging/model.mjs.map +0 -1
- package/bridging/session.d.mts +0 -10
- package/bridging/session.d.mts.map +0 -1
- package/bridging/session.d.ts +0 -10
- package/bridging/session.d.ts.map +0 -1
- package/bridging/session.js.map +0 -1
- package/bridging/session.mjs.map +0 -1
- package/interactors/modelInteractor.d.mts.map +0 -1
- package/interactors/modelInteractor.d.ts.map +0 -1
- package/interactors/modelInteractor.js.map +0 -1
- package/interactors/modelInteractor.mjs.map +0 -1
- package/interactors/modelsInteractor.d.mts +0 -12
- package/interactors/modelsInteractor.d.mts.map +0 -1
- package/interactors/modelsInteractor.d.ts +0 -12
- package/interactors/modelsInteractor.d.ts.map +0 -1
- package/interactors/modelsInteractor.js.map +0 -1
- package/interactors/modelsInteractor.mjs.map +0 -1
- package/interactors/sessionInteractor.d.mts +0 -24
- package/interactors/sessionInteractor.d.mts.map +0 -1
- package/interactors/sessionInteractor.d.ts +0 -24
- package/interactors/sessionInteractor.d.ts.map +0 -1
- package/interactors/sessionInteractor.js.map +0 -1
- package/interactors/sessionInteractor.mjs.map +0 -1
- package/src/bridging/model.ts +0 -58
|
@@ -1,32 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.EngineInteractor = void 0;
|
|
4
|
-
const
|
|
4
|
+
const chatModelsInteractor_1 = require("./chatModelsInteractor.js");
|
|
5
5
|
class EngineInteractor {
|
|
6
|
-
constructor(engine, modelTypeFilter = null
|
|
6
|
+
constructor(engine, modelTypeFilter = null) {
|
|
7
7
|
this.entity = engine;
|
|
8
8
|
this.modelTypeFilter = modelTypeFilter;
|
|
9
|
-
this.modelKindFilter = modelKindFilter;
|
|
10
9
|
}
|
|
11
10
|
async finalize() {
|
|
12
11
|
return await this.entity;
|
|
13
12
|
}
|
|
14
13
|
/* Models */
|
|
15
14
|
filterTypes(types) {
|
|
16
|
-
return new EngineInteractor(this.entity, types
|
|
15
|
+
return new EngineInteractor(this.entity, types);
|
|
17
16
|
}
|
|
18
|
-
|
|
19
|
-
return new EngineInteractor(this.entity, this.modelTypeFilter, kinds);
|
|
20
|
-
}
|
|
21
|
-
models() {
|
|
17
|
+
chatModels() {
|
|
22
18
|
const modelsPromise = (async () => {
|
|
23
19
|
const engine = await this.finalize();
|
|
24
|
-
return await engine.
|
|
20
|
+
return await engine.chatModels(this.modelTypeFilter);
|
|
25
21
|
})();
|
|
26
|
-
return new
|
|
22
|
+
return new chatModelsInteractor_1.ChatModelsInteractor(this, modelsPromise);
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
const models = this.
|
|
24
|
+
chatModel(repoId) {
|
|
25
|
+
const models = this.chatModels();
|
|
30
26
|
return models.get(repoId);
|
|
31
27
|
}
|
|
32
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineInteractor.js","sourceRoot":"","sources":["../src/interactors/engineInteractor.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"engineInteractor.js","sourceRoot":"","sources":["../src/interactors/engineInteractor.ts"],"names":[],"mappings":";;;AAGA,oEAA8D;AAG9D,MAAa,gBAAgB;IAIzB,YAAY,MAAgC,EAAE,kBAAsC,IAAI;QACpF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,QAAQ;QACV,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,YAAY;IAEZ,WAAW,CAAC,KAAyB;QACjC,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,UAAU;QACN,MAAM,aAAa,GAAG,CAAC,KAAK,IAAI,EAAE;YAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,OAAO,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACzD,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,2CAAoB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACzD,CAAC;IAED,SAAS,CAAC,MAAc;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACJ;AA/BD,4CA+BC"}
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatModelsInteractor } from "./chatModelsInteractor.mjs";
|
|
2
2
|
export class EngineInteractor {
|
|
3
|
-
constructor(engine, modelTypeFilter = null
|
|
3
|
+
constructor(engine, modelTypeFilter = null) {
|
|
4
4
|
this.entity = engine;
|
|
5
5
|
this.modelTypeFilter = modelTypeFilter;
|
|
6
|
-
this.modelKindFilter = modelKindFilter;
|
|
7
6
|
}
|
|
8
7
|
async finalize() {
|
|
9
8
|
return await this.entity;
|
|
10
9
|
}
|
|
11
10
|
/* Models */
|
|
12
11
|
filterTypes(types) {
|
|
13
|
-
return new EngineInteractor(this.entity, types
|
|
12
|
+
return new EngineInteractor(this.entity, types);
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
return new EngineInteractor(this.entity, this.modelTypeFilter, kinds);
|
|
17
|
-
}
|
|
18
|
-
models() {
|
|
14
|
+
chatModels() {
|
|
19
15
|
const modelsPromise = (async () => {
|
|
20
16
|
const engine = await this.finalize();
|
|
21
|
-
return await engine.
|
|
17
|
+
return await engine.chatModels(this.modelTypeFilter);
|
|
22
18
|
})();
|
|
23
|
-
return new
|
|
19
|
+
return new ChatModelsInteractor(this, modelsPromise);
|
|
24
20
|
}
|
|
25
|
-
|
|
26
|
-
const models = this.
|
|
21
|
+
chatModel(repoId) {
|
|
22
|
+
const models = this.chatModels();
|
|
27
23
|
return models.get(repoId);
|
|
28
24
|
}
|
|
29
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engineInteractor.mjs","sourceRoot":"","sources":["../src/interactors/engineInteractor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engineInteractor.mjs","sourceRoot":"","sources":["../src/interactors/engineInteractor.ts"],"names":[],"mappings":"OAGO,EAAE,oBAAoB,EAAE;AAG/B,MAAM,OAAO,gBAAgB;IAIzB,YAAY,MAAgC,EAAE,kBAAsC,IAAI;QACpF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IAC3C,CAAC;IAED,KAAK,CAAC,QAAQ;QACV,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC;IAC7B,CAAC;IAED,YAAY;IAEZ,WAAW,CAAC,KAAyB;QACjC,OAAO,IAAI,gBAAgB,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,UAAU;QACN,MAAM,aAAa,GAAG,CAAC,KAAK,IAAI,EAAE;YAC9B,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;YACrC,OAAO,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACzD,CAAC,CAAC,EAAE,CAAC;QACL,OAAO,IAAI,oBAAoB,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IACzD,CAAC;IAED,SAAS,CAAC,MAAc;QACpB,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,CAAC;CACJ"}
|
package/napi/uzu.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
/* auto-generated by NAPI-RS */
|
|
2
2
|
/* eslint-disable */
|
|
3
|
-
|
|
3
|
+
export declare class ChatSession {
|
|
4
|
+
run(input: Input, config: RunConfig, progress?: (arg: Output) => boolean | undefined | null): Output
|
|
5
|
+
}
|
|
6
|
+
|
|
4
7
|
export declare class Engine {
|
|
5
|
-
getCloudModels(): Promise<Array<CloudModel>>
|
|
6
|
-
fetchCloudModels(): Promise<Array<CloudModel>>
|
|
7
|
-
/** Returns a `DownloadHandle` for the given model identifier. */
|
|
8
|
-
downloadHandle(repoId: string): ModelDownloadHandle
|
|
9
|
-
getLocalModels(): Array<LocalModel>
|
|
10
|
-
getState(repoId: string): ModelDownloadState
|
|
11
8
|
activate(apiKey: string): Promise<LicenseStatus>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
getChatModels(types: Array<ModelType>): Promise<Array<ChatModel>>
|
|
10
|
+
getModelDownloadState(repoId: string): ModelDownloadState
|
|
11
|
+
createModelDownloadHandle(repoId: string): ModelDownloadHandle
|
|
15
12
|
constructor()
|
|
16
|
-
|
|
13
|
+
createChatSession(model: ChatModel, config: Config): ChatSession
|
|
14
|
+
registerLicenseStatusHandler(callback?: (arg: LicenseStatus) => void | undefined | null): void
|
|
15
|
+
registerModelDownloadStateHandler(callback?: (arg0: string, arg1: ModelDownloadState) => void | undefined | null): void
|
|
16
|
+
registerChatModelsHandler(callback?: (arg: Array<ChatModel>) => void | undefined | null): void
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export declare class ModelDownloadHandle {
|
|
@@ -38,8 +38,13 @@ export declare class ProgressUpdate {
|
|
|
38
38
|
progress: number
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export
|
|
42
|
-
|
|
41
|
+
export interface ChatModel {
|
|
42
|
+
readonly repoId: string
|
|
43
|
+
readonly type: ModelType
|
|
44
|
+
readonly name: string
|
|
45
|
+
readonly vendor: string
|
|
46
|
+
readonly quantization?: string
|
|
47
|
+
readonly outputParserRegex?: string
|
|
43
48
|
}
|
|
44
49
|
|
|
45
50
|
export interface ClassificationFeature {
|
|
@@ -47,13 +52,6 @@ export interface ClassificationFeature {
|
|
|
47
52
|
values: Array<string>
|
|
48
53
|
}
|
|
49
54
|
|
|
50
|
-
export interface CloudModel {
|
|
51
|
-
readonly repoId: string
|
|
52
|
-
readonly name: string
|
|
53
|
-
readonly vendor: string
|
|
54
|
-
readonly outputParserRegex?: string
|
|
55
|
-
}
|
|
56
|
-
|
|
57
55
|
export interface Config {
|
|
58
56
|
preset: Preset
|
|
59
57
|
prefillStepSize: PrefillStepSize
|
|
@@ -88,18 +86,6 @@ export type LicenseStatus =
|
|
|
88
86
|
| { type: 'Timeout' }
|
|
89
87
|
| { type: 'HttpError', code: number }
|
|
90
88
|
|
|
91
|
-
export interface LocalModel {
|
|
92
|
-
readonly identifier: string
|
|
93
|
-
readonly repoId: string
|
|
94
|
-
readonly family: string
|
|
95
|
-
readonly vendor: string
|
|
96
|
-
readonly name: string
|
|
97
|
-
readonly size: string
|
|
98
|
-
readonly quantization?: string
|
|
99
|
-
readonly outputParserRegex?: string
|
|
100
|
-
readonly state: ModelDownloadState
|
|
101
|
-
}
|
|
102
|
-
|
|
103
89
|
export interface Message {
|
|
104
90
|
role: Role
|
|
105
91
|
content: string
|
package/napi/uzu.js
CHANGED
|
@@ -21,20 +21,19 @@ try {
|
|
|
21
21
|
|
|
22
22
|
// Re-export all runtime exports
|
|
23
23
|
const {
|
|
24
|
+
ChatSession,
|
|
24
25
|
Engine,
|
|
25
26
|
ModelDownloadHandle,
|
|
26
27
|
ProgressStream,
|
|
27
28
|
ProgressUpdate,
|
|
28
|
-
Session,
|
|
29
29
|
FinishReason,
|
|
30
30
|
ModelDownloadPhase,
|
|
31
31
|
ModelType,
|
|
32
32
|
Role,
|
|
33
33
|
version,
|
|
34
|
+
ChatModel,
|
|
34
35
|
ClassificationFeature,
|
|
35
|
-
CloudModel,
|
|
36
36
|
Config,
|
|
37
|
-
LocalModel,
|
|
38
37
|
Message,
|
|
39
38
|
ModelDownloadState,
|
|
40
39
|
Output,
|
|
@@ -58,20 +57,19 @@ const {
|
|
|
58
57
|
} = nativeBinding;
|
|
59
58
|
|
|
60
59
|
module.exports = {
|
|
60
|
+
ChatSession,
|
|
61
61
|
Engine,
|
|
62
62
|
ModelDownloadHandle,
|
|
63
63
|
ProgressStream,
|
|
64
64
|
ProgressUpdate,
|
|
65
|
-
Session,
|
|
66
65
|
FinishReason,
|
|
67
66
|
ModelDownloadPhase,
|
|
68
67
|
ModelType,
|
|
69
68
|
Role,
|
|
70
69
|
version,
|
|
70
|
+
ChatModel,
|
|
71
71
|
ClassificationFeature,
|
|
72
|
-
CloudModel,
|
|
73
72
|
Config,
|
|
74
|
-
LocalModel,
|
|
75
73
|
Message,
|
|
76
74
|
ModelDownloadState,
|
|
77
75
|
Output,
|
package/napi/uzu.mjs
CHANGED
|
@@ -21,20 +21,19 @@ try {
|
|
|
21
21
|
|
|
22
22
|
// Re-export all runtime exports as named exports
|
|
23
23
|
export const {
|
|
24
|
+
ChatSession,
|
|
24
25
|
Engine,
|
|
25
26
|
ModelDownloadHandle,
|
|
26
27
|
ProgressStream,
|
|
27
28
|
ProgressUpdate,
|
|
28
|
-
Session,
|
|
29
29
|
FinishReason,
|
|
30
30
|
ModelDownloadPhase,
|
|
31
31
|
ModelType,
|
|
32
32
|
Role,
|
|
33
33
|
version,
|
|
34
|
+
ChatModel,
|
|
34
35
|
ClassificationFeature,
|
|
35
|
-
CloudModel,
|
|
36
36
|
Config,
|
|
37
|
-
LocalModel,
|
|
38
37
|
Message,
|
|
39
38
|
ModelDownloadState,
|
|
40
39
|
Output,
|
package/napi/uzu.node
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ChatModel as NapiChatModel } from '../napi/uzu';
|
|
2
|
+
import { ModelType, modelTypeFromNapiModelType, modelTypeToNapiModelType } from './modelType';
|
|
3
|
+
|
|
4
|
+
export class ChatModel {
|
|
5
|
+
readonly repoId: string;
|
|
6
|
+
readonly type: ModelType;
|
|
7
|
+
readonly name: string;
|
|
8
|
+
readonly vendor: string;
|
|
9
|
+
readonly quantization: string | null;
|
|
10
|
+
readonly outputParserRegex: string | null;
|
|
11
|
+
|
|
12
|
+
get isThinking(): boolean {
|
|
13
|
+
return this.outputParserRegex !== null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private constructor(
|
|
17
|
+
repoId: string,
|
|
18
|
+
type: ModelType,
|
|
19
|
+
name: string,
|
|
20
|
+
vendor: string,
|
|
21
|
+
quantization: string | null,
|
|
22
|
+
outputParserRegex: string | null,
|
|
23
|
+
) {
|
|
24
|
+
this.repoId = repoId;
|
|
25
|
+
this.type = type;
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.vendor = vendor;
|
|
28
|
+
this.quantization = quantization;
|
|
29
|
+
this.outputParserRegex = outputParserRegex;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromNapiChatModel(napiChatModel: NapiChatModel): ChatModel {
|
|
33
|
+
return new ChatModel(
|
|
34
|
+
napiChatModel.repoId,
|
|
35
|
+
modelTypeFromNapiModelType(napiChatModel.type),
|
|
36
|
+
napiChatModel.name,
|
|
37
|
+
napiChatModel.vendor,
|
|
38
|
+
napiChatModel.quantization ?? null,
|
|
39
|
+
napiChatModel.outputParserRegex ?? null,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
toNapi(): NapiChatModel {
|
|
44
|
+
const napiChatModel: NapiChatModel = {
|
|
45
|
+
repoId: this.repoId,
|
|
46
|
+
type: modelTypeToNapiModelType(this.type),
|
|
47
|
+
name: this.name,
|
|
48
|
+
vendor: this.vendor,
|
|
49
|
+
...(this.quantization !== null && { quantization: this.quantization }),
|
|
50
|
+
...(this.outputParserRegex !== null && { outputParserRegex: this.outputParserRegex }),
|
|
51
|
+
};
|
|
52
|
+
return napiChatModel;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ChatSession as NapiChatSession, Output as NapiOutput } from '../napi/uzu';
|
|
2
2
|
import { Input } from './input';
|
|
3
3
|
import { Output } from './output';
|
|
4
4
|
import { RunConfig } from './runConfig';
|
|
5
5
|
|
|
6
|
-
export class
|
|
7
|
-
private readonly
|
|
6
|
+
export class ChatSession {
|
|
7
|
+
private readonly napiChatSession: NapiChatSession;
|
|
8
8
|
|
|
9
|
-
constructor(
|
|
10
|
-
this.
|
|
9
|
+
constructor(napiChatSession: NapiChatSession) {
|
|
10
|
+
this.napiChatSession = napiChatSession;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
run(
|
|
@@ -18,7 +18,7 @@ export class Session {
|
|
|
18
18
|
const napiInput = input.toNapi();
|
|
19
19
|
const napiConfig = config.toNapi();
|
|
20
20
|
const napiProgress = (partialOutput: NapiOutput) => progress(Output.fromNapi(partialOutput));
|
|
21
|
-
const napiOutput = this.
|
|
21
|
+
const napiOutput = this.napiChatSession.run(napiInput, napiConfig, napiProgress);
|
|
22
22
|
return Output.fromNapi(napiOutput);
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/bridging/engine.ts
CHANGED
|
@@ -2,12 +2,14 @@ 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
|
+
import { ChatSession } from './chatSession';
|
|
5
7
|
import { Config } from './config';
|
|
6
8
|
import { DownloadHandle } from './downloadHandle';
|
|
9
|
+
import { DownloadProgressUpdate } from './downloadProgressUpdate';
|
|
10
|
+
import { DownloadPhase, DownloadState } from './downloadState';
|
|
7
11
|
import { LicenseStatus, licenseStatusFromNapiLicenseStatus } from './licenseStatus';
|
|
8
|
-
import {
|
|
9
|
-
import { ModelType, modelTypeToNapi } from './modelType';
|
|
10
|
-
import { Session } from './session';
|
|
12
|
+
import { ModelType, modelTypeToNapiModelType } from './modelType';
|
|
11
13
|
|
|
12
14
|
export class Engine {
|
|
13
15
|
private readonly napiEngine: NapiEngine;
|
|
@@ -44,62 +46,60 @@ export class Engine {
|
|
|
44
46
|
return new EngineInteractor(enginePromise);
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
getDownloadState(repoId: string): DownloadState {
|
|
50
|
+
let downloadState = this.napiEngine.getModelDownloadState(repoId);
|
|
51
|
+
return DownloadState.fromNapi(downloadState);
|
|
52
|
+
}
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
54
|
+
downloadHandle(repoId: string): DownloadHandle {
|
|
55
|
+
return new DownloadHandle(this.napiEngine.createModelDownloadHandle(repoId));
|
|
56
|
+
}
|
|
55
57
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (isTypeAllowed(ModelType.Cloud) && isKindAllowed(ModelKind.Text)) {
|
|
62
|
-
const napiCloudModels = await this.napiEngine.getCloudModels();
|
|
63
|
-
results.push(...napiCloudModels.map(Model.fromNapiCloudModel));
|
|
64
|
-
}
|
|
58
|
+
async chatModels(types: ModelType[] | null = null): Promise<ChatModel[]> {
|
|
59
|
+
let typesToFilter: ModelType[] = types ?? [ModelType.Local, ModelType.Cloud];
|
|
60
|
+
let napiModelTypes = typesToFilter.map(modelTypeToNapiModelType);
|
|
61
|
+
let napiChatModels = await this.napiEngine.getChatModels(napiModelTypes);
|
|
62
|
+
let results: ChatModel[] = napiChatModels.map(ChatModel.fromNapiChatModel);
|
|
65
63
|
return results;
|
|
66
64
|
}
|
|
67
65
|
|
|
68
|
-
async
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
return unwrapOrThrow(
|
|
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);
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
async downloadChatModel(
|
|
73
|
+
chatModel: ChatModel,
|
|
74
|
+
progress: (progressUpdate: DownloadProgressUpdate) => void = () => {},
|
|
75
|
+
): Promise<DownloadState> {
|
|
76
|
+
switch (chatModel.type) {
|
|
77
|
+
case ModelType.Local:
|
|
78
|
+
break;
|
|
79
|
+
case ModelType.Cloud:
|
|
80
|
+
throw new EngineError(EngineErrorCode.UnexpectedModelType);
|
|
77
81
|
}
|
|
78
|
-
return new DownloadHandle(this.napiEngine.downloadHandle(model.repoId));
|
|
79
|
-
}
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
const downloadHandle = this.downloadHandle(chatModel.repoId);
|
|
84
|
+
const state = await downloadHandle.state();
|
|
85
|
+
switch (state.phase) {
|
|
86
|
+
case DownloadPhase.Downloaded:
|
|
87
|
+
break;
|
|
88
|
+
default:
|
|
89
|
+
await downloadHandle.download();
|
|
90
|
+
for await (const progressUpdate of downloadHandle.progressUpdate()) {
|
|
91
|
+
progress(progressUpdate);
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
84
94
|
}
|
|
85
|
-
const napiModelType = modelTypeToNapi(model.type);
|
|
86
|
-
const napiConfig = config.toNapi();
|
|
87
|
-
return new Session(this.napiEngine.createSession(model.repoId, napiModelType, napiConfig));
|
|
88
|
-
}
|
|
89
95
|
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
const finalState = await downloadHandle.state();
|
|
97
|
+
return finalState;
|
|
92
98
|
}
|
|
93
99
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
async deleteModel(repoId: string): Promise<void> {
|
|
99
|
-
await this.napiEngine.deleteModel(repoId);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
getState(repoId: string) {
|
|
103
|
-
return this.napiEngine.getState(repoId);
|
|
100
|
+
chatSession(chatModel: ChatModel, config: Config = Config.default()): ChatSession {
|
|
101
|
+
const napiChatModel = chatModel.toNapi();
|
|
102
|
+
const napiConfig = config.toNapi();
|
|
103
|
+
return new ChatSession(this.napiEngine.createChatSession(napiChatModel, napiConfig));
|
|
104
104
|
}
|
|
105
105
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '../error';
|
|
1
2
|
import { ModelType as NapiModelType } from '../napi/uzu';
|
|
2
3
|
|
|
3
4
|
export enum ModelType {
|
|
@@ -5,7 +6,18 @@ export enum ModelType {
|
|
|
5
6
|
Cloud = 'Cloud',
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export function
|
|
9
|
+
export function modelTypeFromNapiModelType(napiModelType: NapiModelType): ModelType {
|
|
10
|
+
switch (napiModelType) {
|
|
11
|
+
case 0:
|
|
12
|
+
return ModelType.Local;
|
|
13
|
+
case 1:
|
|
14
|
+
return ModelType.Cloud;
|
|
15
|
+
default:
|
|
16
|
+
throw new EngineError(EngineErrorCode.UnexpectedModelType);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function modelTypeToNapiModelType(modelType: ModelType): NapiModelType {
|
|
9
21
|
switch (modelType) {
|
|
10
22
|
case ModelType.Local:
|
|
11
23
|
return 0;
|
package/src/error.ts
CHANGED
|
@@ -2,10 +2,10 @@ export enum EngineErrorCode {
|
|
|
2
2
|
APIKeyNotFound = 'apiKeyNotFound',
|
|
3
3
|
ModelNotFound = 'modelNotFound',
|
|
4
4
|
ExpectedLocalModel = 'expectedLocalModel',
|
|
5
|
-
ExpectedTextModel = 'expectedTextModel',
|
|
6
5
|
UnexpectedDownloadPhase = 'unexpectedDownloadPhase',
|
|
7
6
|
UnexpectedFinishReason = 'unexpectedFinishReason',
|
|
8
7
|
UnexpectedLicenseStatus = 'unexpectedLicenseStatus',
|
|
8
|
+
UnexpectedModelType = 'unexpectedModelType',
|
|
9
9
|
LicenseNotActivated = 'licenseNotActivated',
|
|
10
10
|
Unknown = 'unknown',
|
|
11
11
|
}
|
|
@@ -14,10 +14,10 @@ const errorCodeToMessage = {
|
|
|
14
14
|
[EngineErrorCode.APIKeyNotFound]: 'API key not found',
|
|
15
15
|
[EngineErrorCode.ModelNotFound]: 'Model not found',
|
|
16
16
|
[EngineErrorCode.ExpectedLocalModel]: 'Expected local model',
|
|
17
|
-
[EngineErrorCode.ExpectedTextModel]: 'Expected text model',
|
|
18
17
|
[EngineErrorCode.UnexpectedDownloadPhase]: 'Unexpected download phase',
|
|
19
18
|
[EngineErrorCode.UnexpectedFinishReason]: 'Unexpected finish reason',
|
|
20
19
|
[EngineErrorCode.UnexpectedLicenseStatus]: 'Unexpected license status',
|
|
20
|
+
[EngineErrorCode.UnexpectedModelType]: 'Unexpected model type',
|
|
21
21
|
[EngineErrorCode.LicenseNotActivated]: 'License not activated',
|
|
22
22
|
[EngineErrorCode.Unknown]: 'Unknown error',
|
|
23
23
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { ChatModel } from './bridging/chatModel';
|
|
2
|
+
export { ChatSession } from './bridging/chatSession';
|
|
1
3
|
export { ClassificationFeature } from './bridging/classificationFeature';
|
|
2
4
|
export { Config } from './bridging/config';
|
|
3
5
|
export { ContextLength } from './bridging/contextLength';
|
|
@@ -8,7 +10,6 @@ export { Engine as default } from './bridging/engine';
|
|
|
8
10
|
export { FinishReason } from './bridging/finishReason';
|
|
9
11
|
export { Input } from './bridging/input';
|
|
10
12
|
export { Message } from './bridging/message';
|
|
11
|
-
export { Model, ModelKind } from './bridging/model';
|
|
12
13
|
export { ModelType } from './bridging/modelType';
|
|
13
14
|
export { Output } from './bridging/output';
|
|
14
15
|
export { ParsedText } from './bridging/parsedText';
|
|
@@ -20,14 +21,13 @@ export { RunStats } from './bridging/runStats';
|
|
|
20
21
|
export { SamplingMethod } from './bridging/samplingMethod';
|
|
21
22
|
export { SamplingPolicy } from './bridging/samplingPolicy';
|
|
22
23
|
export { SamplingSeed } from './bridging/samplingSeed';
|
|
23
|
-
export { Session } from './bridging/session';
|
|
24
24
|
export { Stats } from './bridging/stats';
|
|
25
25
|
export { StepStats } from './bridging/stepStats';
|
|
26
26
|
export { Text } from './bridging/text';
|
|
27
27
|
export { TotalStats } from './bridging/totalStats';
|
|
28
28
|
export { EngineError } from './error';
|
|
29
|
+
export { ChatModelInteractor } from './interactors/chatModelInteractor';
|
|
30
|
+
export { ChatModelsInteractor } from './interactors/chatModelsInteractor';
|
|
31
|
+
export { ChatSessionInteractor } from './interactors/chatSessionInteractor';
|
|
29
32
|
export { DownloadInteractor } from './interactors/downloadInteractor';
|
|
30
33
|
export { EngineInteractor } from './interactors/engineInteractor';
|
|
31
|
-
export { ModelInteractor } from './interactors/modelInteractor';
|
|
32
|
-
export { ModelsInteractor } from './interactors/modelsInteractor';
|
|
33
|
-
export { SessionInteractor } from './interactors/sessionInteractor';
|