@trymirai/uzu 0.1.38 → 0.1.40

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.
Files changed (143) hide show
  1. package/README.md +5 -5
  2. package/bridging/chatModel.d.mts +15 -0
  3. package/bridging/chatModel.d.mts.map +1 -0
  4. package/bridging/chatModel.d.ts +15 -0
  5. package/bridging/chatModel.d.ts.map +1 -0
  6. package/bridging/chatModel.js +33 -0
  7. package/bridging/chatModel.js.map +1 -0
  8. package/bridging/chatModel.mjs +29 -0
  9. package/bridging/chatModel.mjs.map +1 -0
  10. package/bridging/chatSession.d.mts +10 -0
  11. package/bridging/chatSession.d.mts.map +1 -0
  12. package/bridging/chatSession.d.ts +10 -0
  13. package/bridging/chatSession.d.ts.map +1 -0
  14. package/bridging/{session.js → chatSession.js} +7 -7
  15. package/bridging/chatSession.js.map +1 -0
  16. package/bridging/{session.mjs → chatSession.mjs} +5 -5
  17. package/bridging/chatSession.mjs.map +1 -0
  18. package/bridging/engine.d.mts +10 -10
  19. package/bridging/engine.d.mts.map +1 -1
  20. package/bridging/engine.d.ts +10 -10
  21. package/bridging/engine.d.ts.map +1 -1
  22. package/bridging/engine.js +42 -44
  23. package/bridging/engine.js.map +1 -1
  24. package/bridging/engine.mjs +43 -45
  25. package/bridging/engine.mjs.map +1 -1
  26. package/bridging/modelType.d.mts +2 -1
  27. package/bridging/modelType.d.mts.map +1 -1
  28. package/bridging/modelType.d.ts +2 -1
  29. package/bridging/modelType.d.ts.map +1 -1
  30. package/bridging/modelType.js +14 -2
  31. package/bridging/modelType.js.map +1 -1
  32. package/bridging/modelType.mjs +12 -1
  33. package/bridging/modelType.mjs.map +1 -1
  34. package/error.d.mts +1 -1
  35. package/error.d.mts.map +1 -1
  36. package/error.d.ts +1 -1
  37. package/error.d.ts.map +1 -1
  38. package/error.js +2 -2
  39. package/error.js.map +1 -1
  40. package/error.mjs +2 -2
  41. package/error.mjs.map +1 -1
  42. package/index.d.mts +5 -5
  43. package/index.d.mts.map +1 -1
  44. package/index.d.ts +5 -5
  45. package/index.d.ts.map +1 -1
  46. package/index.js +11 -12
  47. package/index.js.map +1 -1
  48. package/index.mjs +5 -5
  49. package/index.mjs.map +1 -1
  50. package/interactors/{modelInteractor.d.mts → chatModelInteractor.d.mts} +15 -15
  51. package/interactors/chatModelInteractor.d.mts.map +1 -0
  52. package/interactors/{modelInteractor.d.ts → chatModelInteractor.d.ts} +15 -15
  53. package/interactors/chatModelInteractor.d.ts.map +1 -0
  54. package/interactors/{modelInteractor.js → chatModelInteractor.js} +13 -13
  55. package/interactors/chatModelInteractor.js.map +1 -0
  56. package/interactors/{modelInteractor.mjs → chatModelInteractor.mjs} +11 -11
  57. package/interactors/chatModelInteractor.mjs.map +1 -0
  58. package/interactors/chatModelsInteractor.d.mts +12 -0
  59. package/interactors/chatModelsInteractor.d.mts.map +1 -0
  60. package/interactors/chatModelsInteractor.d.ts +12 -0
  61. package/interactors/chatModelsInteractor.d.ts.map +1 -0
  62. package/interactors/{modelsInteractor.js → chatModelsInteractor.js} +6 -6
  63. package/interactors/chatModelsInteractor.js.map +1 -0
  64. package/interactors/{modelsInteractor.mjs → chatModelsInteractor.mjs} +4 -4
  65. package/interactors/chatModelsInteractor.mjs.map +1 -0
  66. package/interactors/chatSessionInteractor.d.mts +24 -0
  67. package/interactors/chatSessionInteractor.d.mts.map +1 -0
  68. package/interactors/chatSessionInteractor.d.ts +24 -0
  69. package/interactors/chatSessionInteractor.d.ts.map +1 -0
  70. package/interactors/{sessionInteractor.js → chatSessionInteractor.js} +8 -8
  71. package/interactors/chatSessionInteractor.js.map +1 -0
  72. package/interactors/{sessionInteractor.mjs → chatSessionInteractor.mjs} +6 -6
  73. package/interactors/chatSessionInteractor.mjs.map +1 -0
  74. package/interactors/downloadInteractor.d.mts +3 -3
  75. package/interactors/downloadInteractor.d.mts.map +1 -1
  76. package/interactors/downloadInteractor.d.ts +3 -3
  77. package/interactors/downloadInteractor.d.ts.map +1 -1
  78. package/interactors/downloadInteractor.js.map +1 -1
  79. package/interactors/downloadInteractor.mjs.map +1 -1
  80. package/interactors/engineInteractor.d.mts +5 -8
  81. package/interactors/engineInteractor.d.mts.map +1 -1
  82. package/interactors/engineInteractor.d.ts +5 -8
  83. package/interactors/engineInteractor.d.ts.map +1 -1
  84. package/interactors/engineInteractor.js +8 -12
  85. package/interactors/engineInteractor.js.map +1 -1
  86. package/interactors/engineInteractor.mjs +8 -12
  87. package/interactors/engineInteractor.mjs.map +1 -1
  88. package/napi/uzu.d.ts +18 -32
  89. package/napi/uzu.js +4 -6
  90. package/napi/uzu.mjs +2 -3
  91. package/napi/uzu.node +0 -0
  92. package/package.json +1 -1
  93. package/src/bridging/chatModel.ts +54 -0
  94. package/src/bridging/{session.ts → chatSession.ts} +6 -6
  95. package/src/bridging/engine.ts +47 -47
  96. package/src/bridging/modelType.ts +13 -1
  97. package/src/error.ts +2 -2
  98. package/src/index.ts +5 -5
  99. package/src/interactors/{modelInteractor.ts → chatModelInteractor.ts} +22 -22
  100. package/src/interactors/{modelsInteractor.ts → chatModelsInteractor.ts} +8 -8
  101. package/src/interactors/{sessionInteractor.ts → chatSessionInteractor.ts} +19 -15
  102. package/src/interactors/downloadInteractor.ts +3 -3
  103. package/src/interactors/engineInteractor.ts +9 -20
  104. package/src/napi/uzu.d.ts +18 -32
  105. package/src/napi/uzu.js +4 -6
  106. package/src/napi/uzu.mjs +2 -3
  107. package/src/napi/uzu.node +0 -0
  108. package/src/version.ts +1 -1
  109. package/version.d.mts +1 -1
  110. package/version.d.ts +1 -1
  111. package/version.js +1 -1
  112. package/version.mjs +1 -1
  113. package/bridging/model.d.mts +0 -18
  114. package/bridging/model.d.mts.map +0 -1
  115. package/bridging/model.d.ts +0 -18
  116. package/bridging/model.d.ts.map +0 -1
  117. package/bridging/model.js +0 -27
  118. package/bridging/model.js.map +0 -1
  119. package/bridging/model.mjs +0 -23
  120. package/bridging/model.mjs.map +0 -1
  121. package/bridging/session.d.mts +0 -10
  122. package/bridging/session.d.mts.map +0 -1
  123. package/bridging/session.d.ts +0 -10
  124. package/bridging/session.d.ts.map +0 -1
  125. package/bridging/session.js.map +0 -1
  126. package/bridging/session.mjs.map +0 -1
  127. package/interactors/modelInteractor.d.mts.map +0 -1
  128. package/interactors/modelInteractor.d.ts.map +0 -1
  129. package/interactors/modelInteractor.js.map +0 -1
  130. package/interactors/modelInteractor.mjs.map +0 -1
  131. package/interactors/modelsInteractor.d.mts +0 -12
  132. package/interactors/modelsInteractor.d.mts.map +0 -1
  133. package/interactors/modelsInteractor.d.ts +0 -12
  134. package/interactors/modelsInteractor.d.ts.map +0 -1
  135. package/interactors/modelsInteractor.js.map +0 -1
  136. package/interactors/modelsInteractor.mjs.map +0 -1
  137. package/interactors/sessionInteractor.d.mts +0 -24
  138. package/interactors/sessionInteractor.d.mts.map +0 -1
  139. package/interactors/sessionInteractor.d.ts +0 -24
  140. package/interactors/sessionInteractor.d.ts.map +0 -1
  141. package/interactors/sessionInteractor.js.map +0 -1
  142. package/interactors/sessionInteractor.mjs.map +0 -1
  143. package/src/bridging/model.ts +0 -58
package/napi/uzu.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /* auto-generated by NAPI-RS */
2
2
  /* eslint-disable */
3
- /** Thin FFI wrapper around `ModelStorage`. */
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
- downloadModel(repoId: string): Promise<void>
13
- pauseModel(repoId: string): Promise<void>
14
- deleteModel(repoId: string): Promise<void>
9
+ getChatModels(types: Array<ModelType>): Promise<Array<ChatModel>>
10
+ getModelDownloadState(repoId: string): ModelDownloadState
11
+ createModelDownloadHandle(repoId: string): ModelDownloadHandle
15
12
  constructor()
16
- createSession(repoId: string, modelType: ModelType, config: Config): Session
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 declare class Session {
42
- run(input: Input, config: RunConfig, progress?: (arg: Output) => boolean | undefined | null): Output
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
@@ -98,5 +98,5 @@
98
98
  },
99
99
  "type": "commonjs",
100
100
  "types": "./index.d.ts",
101
- "version": "0.1.38"
101
+ "version": "0.1.40"
102
102
  }
@@ -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 { Output as NapiOutput, Session as NapiSession } from '../napi/uzu';
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 Session {
7
- private readonly napiSession: NapiSession;
6
+ export class ChatSession {
7
+ private readonly napiChatSession: NapiChatSession;
8
8
 
9
- constructor(napiSession: NapiSession) {
10
- this.napiSession = napiSession;
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.napiSession.run(napiInput, napiConfig, napiProgress);
21
+ const napiOutput = this.napiChatSession.run(napiInput, napiConfig, napiProgress);
22
22
  return Output.fromNapi(napiOutput);
23
23
  }
24
24
  }
@@ -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 { Model, ModelKind } from './model';
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
- async models(types: ModelType[] | null = null, kinds: ModelKind[] | null = null): Promise<Model[]> {
48
- function isTypeAllowed(type: ModelType): boolean {
49
- return types === null || types.includes(type);
50
- }
49
+ getDownloadState(repoId: string): DownloadState {
50
+ let downloadState = this.napiEngine.getModelDownloadState(repoId);
51
+ return DownloadState.fromNapi(downloadState);
52
+ }
51
53
 
52
- function isKindAllowed(kind: ModelKind): boolean {
53
- return kinds === null || kinds.includes(kind);
54
- }
54
+ downloadHandle(repoId: string): DownloadHandle {
55
+ return new DownloadHandle(this.napiEngine.createModelDownloadHandle(repoId));
56
+ }
55
57
 
56
- let results: Model[] = [];
57
- if (isTypeAllowed(ModelType.Local) && isKindAllowed(ModelKind.Text)) {
58
- const napiLocalModels = this.napiEngine.getLocalModels();
59
- results.push(...napiLocalModels.map(Model.fromNapiLocalModel));
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 model(repoId: string): Promise<Model> {
69
- const models = await this.models();
70
- const model = models.find((model) => model.repoId === repoId);
71
- return unwrapOrThrow(model, EngineErrorCode.ModelNotFound);
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
- downloadHandle(model: Model): DownloadHandle {
75
- if (model.type !== ModelType.Local) {
76
- throw new EngineError(EngineErrorCode.ExpectedLocalModel);
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
- session(model: Model, config: Config = Config.default()): Session {
82
- if (model.kind !== ModelKind.Text) {
83
- throw new EngineError(EngineErrorCode.ExpectedTextModel);
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
- async downloadModel(repoId: string): Promise<void> {
91
- await this.napiEngine.downloadModel(repoId);
96
+ const finalState = await downloadHandle.state();
97
+ return finalState;
92
98
  }
93
99
 
94
- async pauseModel(repoId: string): Promise<void> {
95
- await this.napiEngine.pauseModel(repoId);
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 modelTypeToNapi(modelType: ModelType): NapiModelType {
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';
@@ -1,32 +1,32 @@
1
+ import { ChatModel } from '../bridging/chatModel';
1
2
  import { Config } from '../bridging/config';
2
3
  import { ContextLength } from '../bridging/contextLength';
3
4
  import { DownloadProgressUpdate } from '../bridging/downloadProgressUpdate';
4
5
  import { DownloadPhase } from '../bridging/downloadState';
5
6
  import { Message } from '../bridging/message';
6
- import { Model } from '../bridging/model';
7
7
  import { ModelType } from '../bridging/modelType';
8
8
  import { Output } from '../bridging/output';
9
9
  import { PrefillStepSize } from '../bridging/prefillStepSize';
10
10
  import { Preset } from '../bridging/preset';
11
11
  import { RunConfig } from '../bridging/runConfig';
12
12
  import { SamplingSeed } from '../bridging/samplingSeed';
13
+ import { ChatModelsInteractor } from './chatModelsInteractor';
14
+ import { ChatSessionInteractor } from './chatSessionInteractor';
13
15
  import { DownloadInteractor } from './downloadInteractor';
14
16
  import { Interactor, InteractorEntity } from './interactor';
15
- import { ModelsInteractor } from './modelsInteractor';
16
- import { SessionInteractor } from './sessionInteractor';
17
17
 
18
- export class ModelInteractor implements Interactor<Model> {
19
- readonly modelsInteractor: ModelsInteractor;
20
- readonly entity: InteractorEntity<Model>;
18
+ export class ChatModelInteractor implements Interactor<ChatModel> {
19
+ readonly modelsInteractor: ChatModelsInteractor;
20
+ readonly entity: InteractorEntity<ChatModel>;
21
21
  readonly config: Config;
22
22
 
23
- constructor(modelsInteractor: ModelsInteractor, model: InteractorEntity<Model>, config: Config) {
23
+ constructor(modelsInteractor: ChatModelsInteractor, model: InteractorEntity<ChatModel>, config: Config) {
24
24
  this.modelsInteractor = modelsInteractor;
25
25
  this.entity = model;
26
26
  this.config = config;
27
27
  }
28
28
 
29
- async finalize(): Promise<Model> {
29
+ async finalize(): Promise<ChatModel> {
30
30
  return await this.entity;
31
31
  }
32
32
 
@@ -36,13 +36,13 @@ export class ModelInteractor implements Interactor<Model> {
36
36
  const handlePromise = (async () => {
37
37
  const model = await this.finalize();
38
38
  const engine = await this.modelsInteractor.engineInteractor.finalize();
39
- const handle = engine.downloadHandle(model);
39
+ const handle = engine.downloadHandle(model.repoId);
40
40
  return handle;
41
41
  })();
42
42
  return new DownloadInteractor(this, handlePromise);
43
43
  }
44
44
 
45
- download(callback?: (progressUpdate: DownloadProgressUpdate) => void): ModelInteractor {
45
+ download(callback?: (progressUpdate: DownloadProgressUpdate) => void): ChatModelInteractor {
46
46
  const modelPromise = (async () => {
47
47
  const downloadInteractor = this.downloading();
48
48
  const handle = await downloadInteractor.finalize();
@@ -59,34 +59,34 @@ export class ModelInteractor implements Interactor<Model> {
59
59
  }
60
60
  return this.finalize();
61
61
  })();
62
- return new ModelInteractor(this.modelsInteractor, modelPromise, this.config);
62
+ return new ChatModelInteractor(this.modelsInteractor, modelPromise, this.config);
63
63
  }
64
64
 
65
65
  /* Config */
66
66
 
67
- preset(preset: Preset): ModelInteractor {
67
+ preset(preset: Preset): ChatModelInteractor {
68
68
  const config = this.config.withPreset(preset);
69
- return new ModelInteractor(this.modelsInteractor, this.entity, config);
69
+ return new ChatModelInteractor(this.modelsInteractor, this.entity, config);
70
70
  }
71
71
 
72
- prefillStepSize(prefillStepSize: PrefillStepSize): ModelInteractor {
72
+ prefillStepSize(prefillStepSize: PrefillStepSize): ChatModelInteractor {
73
73
  const config = this.config.withPrefillStepSize(prefillStepSize);
74
- return new ModelInteractor(this.modelsInteractor, this.entity, config);
74
+ return new ChatModelInteractor(this.modelsInteractor, this.entity, config);
75
75
  }
76
76
 
77
- contextLength(contextLength: ContextLength): ModelInteractor {
77
+ contextLength(contextLength: ContextLength): ChatModelInteractor {
78
78
  const config = this.config.withContextLength(contextLength);
79
- return new ModelInteractor(this.modelsInteractor, this.entity, config);
79
+ return new ChatModelInteractor(this.modelsInteractor, this.entity, config);
80
80
  }
81
81
 
82
- samplingSeed(samplingSeed: SamplingSeed): ModelInteractor {
82
+ samplingSeed(samplingSeed: SamplingSeed): ChatModelInteractor {
83
83
  const config = this.config.withSamplingSeed(samplingSeed);
84
- return new ModelInteractor(this.modelsInteractor, this.entity, config);
84
+ return new ChatModelInteractor(this.modelsInteractor, this.entity, config);
85
85
  }
86
86
 
87
87
  /* Session */
88
88
 
89
- session(): SessionInteractor {
89
+ session(): ChatSessionInteractor {
90
90
  const sessionPromise = (async () => {
91
91
  const engine = await this.modelsInteractor.engineInteractor.finalize();
92
92
 
@@ -95,10 +95,10 @@ export class ModelInteractor implements Interactor<Model> {
95
95
  model = await this.download().finalize();
96
96
  }
97
97
 
98
- const session = engine.session(model, this.config);
98
+ const session = engine.chatSession(model, this.config);
99
99
  return session;
100
100
  })();
101
- return new SessionInteractor(this, sessionPromise, RunConfig.default());
101
+ return new ChatSessionInteractor(this, sessionPromise, RunConfig.default());
102
102
  }
103
103
 
104
104
  async reply(text: string, progress: (partialOutput: Output) => boolean = () => true): Promise<Output> {
@@ -1,29 +1,29 @@
1
+ import { ChatModel } from '../bridging/chatModel';
1
2
  import { Config } from '../bridging/config';
2
- import { Model } from '../bridging/model';
3
3
  import { EngineErrorCode, unwrapOrThrow } from '../error';
4
+ import { ChatModelInteractor } from './chatModelInteractor';
4
5
  import { EngineInteractor } from './engineInteractor';
5
6
  import { Interactor, InteractorEntity } from './interactor';
6
- import { ModelInteractor } from './modelInteractor';
7
7
 
8
- export class ModelsInteractor implements Interactor<Model[]> {
8
+ export class ChatModelsInteractor implements Interactor<ChatModel[]> {
9
9
  readonly engineInteractor: EngineInteractor;
10
- readonly entity: InteractorEntity<Model[]>;
10
+ readonly entity: InteractorEntity<ChatModel[]>;
11
11
 
12
- constructor(engineInteractor: EngineInteractor, models: InteractorEntity<Model[]>) {
12
+ constructor(engineInteractor: EngineInteractor, models: InteractorEntity<ChatModel[]>) {
13
13
  this.engineInteractor = engineInteractor;
14
14
  this.entity = models;
15
15
  }
16
16
 
17
- async finalize(): Promise<Model[]> {
17
+ async finalize(): Promise<ChatModel[]> {
18
18
  return await this.entity;
19
19
  }
20
20
 
21
- get(repoId: string): ModelInteractor {
21
+ get(repoId: string): ChatModelInteractor {
22
22
  const modelPromise = (async () => {
23
23
  const models = await this.finalize();
24
24
  const model = models.find((model) => model.repoId === repoId);
25
25
  return unwrapOrThrow(model, EngineErrorCode.ModelNotFound);
26
26
  })();
27
- return new ModelInteractor(this, modelPromise, Config.default());
27
+ return new ChatModelInteractor(this, modelPromise, Config.default());
28
28
  }
29
29
  }