@trymirai/uzu 0.1.21 → 0.1.23
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/LICENSE +21 -0
- package/README.md +103 -136
- package/bridging/classificationFeature.d.mts +9 -0
- package/bridging/classificationFeature.d.mts.map +1 -0
- package/bridging/classificationFeature.d.ts +9 -0
- package/bridging/classificationFeature.d.ts.map +1 -0
- package/bridging/classificationFeature.js +18 -0
- package/bridging/classificationFeature.js.map +1 -0
- package/bridging/classificationFeature.mjs +14 -0
- package/bridging/classificationFeature.mjs.map +1 -0
- package/bridging/config.d.mts +20 -0
- package/bridging/config.d.mts.map +1 -0
- package/bridging/config.d.ts +20 -0
- package/bridging/config.d.ts.map +1 -0
- package/bridging/config.js +41 -0
- package/bridging/config.js.map +1 -0
- package/bridging/config.mjs +37 -0
- package/bridging/config.mjs.map +1 -0
- package/bridging/contextLength.d.mts +11 -0
- package/bridging/contextLength.d.mts.map +1 -0
- package/bridging/contextLength.d.ts +11 -0
- package/bridging/contextLength.d.ts.map +1 -0
- package/bridging/contextLength.js +25 -0
- package/bridging/contextLength.js.map +1 -0
- package/bridging/contextLength.mjs +21 -0
- package/bridging/contextLength.mjs.map +1 -0
- package/bridging/downloadHandle.d.mts +14 -0
- package/bridging/downloadHandle.d.mts.map +1 -0
- package/bridging/downloadHandle.d.ts +14 -0
- package/bridging/downloadHandle.d.ts.map +1 -0
- package/bridging/downloadHandle.js +36 -0
- package/bridging/downloadHandle.js.map +1 -0
- package/bridging/downloadHandle.mjs +32 -0
- package/bridging/downloadHandle.mjs.map +1 -0
- package/bridging/downloadProgressUpdate.d.mts +9 -0
- package/bridging/downloadProgressUpdate.d.mts.map +1 -0
- package/bridging/downloadProgressUpdate.d.ts +9 -0
- package/bridging/downloadProgressUpdate.d.ts.map +1 -0
- package/bridging/downloadProgressUpdate.js +15 -0
- package/bridging/downloadProgressUpdate.js.map +1 -0
- package/bridging/downloadProgressUpdate.mjs +11 -0
- package/bridging/downloadProgressUpdate.mjs.map +1 -0
- package/bridging/downloadState.d.mts +18 -0
- package/bridging/downloadState.d.mts.map +1 -0
- package/bridging/downloadState.d.ts +18 -0
- package/bridging/downloadState.d.ts.map +1 -0
- package/bridging/downloadState.js +42 -0
- package/bridging/downloadState.js.map +1 -0
- package/bridging/downloadState.mjs +38 -0
- package/bridging/downloadState.mjs.map +1 -0
- package/bridging/engine.d.mts +17 -0
- package/bridging/engine.d.mts.map +1 -0
- package/bridging/engine.d.ts +17 -0
- package/bridging/engine.d.ts.map +1 -0
- package/bridging/engine.js +84 -0
- package/bridging/engine.js.map +1 -0
- package/bridging/engine.mjs +80 -0
- package/bridging/engine.mjs.map +1 -0
- package/bridging/finishReason.d.mts +7 -0
- package/bridging/finishReason.d.mts.map +1 -0
- package/bridging/finishReason.d.ts +7 -0
- package/bridging/finishReason.d.ts.map +1 -0
- package/bridging/finishReason.js +11 -0
- package/bridging/finishReason.js.map +1 -0
- package/bridging/finishReason.mjs +8 -0
- package/bridging/finishReason.mjs.map +1 -0
- package/bridging/input.d.mts +11 -0
- package/bridging/input.d.mts.map +1 -0
- package/bridging/input.d.ts +11 -0
- package/bridging/input.d.ts.map +1 -0
- package/bridging/input.js +25 -0
- package/bridging/input.js.map +1 -0
- package/bridging/input.mjs +21 -0
- package/bridging/input.mjs.map +1 -0
- package/bridging/licenseStatus.d.mts +14 -0
- package/bridging/licenseStatus.d.mts.map +1 -0
- package/bridging/licenseStatus.d.ts +14 -0
- package/bridging/licenseStatus.d.ts.map +1 -0
- package/bridging/licenseStatus.js +42 -0
- package/bridging/licenseStatus.js.map +1 -0
- package/bridging/licenseStatus.mjs +38 -0
- package/bridging/licenseStatus.mjs.map +1 -0
- package/bridging/message.d.mts +15 -0
- package/bridging/message.d.mts.map +1 -0
- package/bridging/message.d.ts +15 -0
- package/bridging/message.d.ts.map +1 -0
- package/bridging/message.js +43 -0
- package/bridging/message.js.map +1 -0
- package/bridging/message.mjs +39 -0
- package/bridging/message.mjs.map +1 -0
- package/bridging/model.d.mts +18 -0
- package/bridging/model.d.mts.map +1 -0
- package/bridging/model.d.ts +18 -0
- package/bridging/model.d.ts.map +1 -0
- package/bridging/model.js +28 -0
- package/bridging/model.js.map +1 -0
- package/bridging/model.mjs +24 -0
- package/bridging/model.mjs.map +1 -0
- package/bridging/napi.d.mts +4 -0
- package/bridging/napi.d.mts.map +1 -0
- package/bridging/napi.d.ts +4 -0
- package/bridging/napi.d.ts.map +1 -0
- package/bridging/napi.js +3 -0
- package/bridging/napi.js.map +1 -0
- package/bridging/napi.mjs +2 -0
- package/bridging/napi.mjs.map +1 -0
- package/bridging/output.d.mts +13 -0
- package/bridging/output.d.mts.map +1 -0
- package/bridging/output.d.ts +13 -0
- package/bridging/output.d.ts.map +1 -0
- package/bridging/output.js +36 -0
- package/bridging/output.js.map +1 -0
- package/bridging/output.mjs +32 -0
- package/bridging/output.mjs.map +1 -0
- package/bridging/parsedText.d.mts +8 -0
- package/bridging/parsedText.d.mts.map +1 -0
- package/bridging/parsedText.d.ts +8 -0
- package/bridging/parsedText.d.ts.map +1 -0
- package/bridging/parsedText.js +16 -0
- package/bridging/parsedText.js.map +1 -0
- package/bridging/parsedText.mjs +12 -0
- package/bridging/parsedText.mjs.map +1 -0
- package/bridging/prefillStepSize.d.mts +11 -0
- package/bridging/prefillStepSize.d.mts.map +1 -0
- package/bridging/prefillStepSize.d.ts +11 -0
- package/bridging/prefillStepSize.d.ts.map +1 -0
- package/bridging/prefillStepSize.js +28 -0
- package/bridging/prefillStepSize.js.map +1 -0
- package/bridging/prefillStepSize.mjs +24 -0
- package/bridging/prefillStepSize.mjs.map +1 -0
- package/bridging/preset.d.mts +12 -0
- package/bridging/preset.d.mts.map +1 -0
- package/bridging/preset.d.ts +12 -0
- package/bridging/preset.d.ts.map +1 -0
- package/bridging/preset.js +29 -0
- package/bridging/preset.js.map +1 -0
- package/bridging/preset.mjs +25 -0
- package/bridging/preset.mjs.map +1 -0
- package/bridging/role.d.mts +6 -0
- package/bridging/role.d.mts.map +1 -0
- package/bridging/role.d.ts +6 -0
- package/bridging/role.d.ts.map +1 -0
- package/bridging/role.js +10 -0
- package/bridging/role.js.map +1 -0
- package/bridging/role.mjs +7 -0
- package/bridging/role.mjs.map +1 -0
- package/bridging/runConfig.d.mts +15 -0
- package/bridging/runConfig.d.mts.map +1 -0
- package/bridging/runConfig.d.ts +15 -0
- package/bridging/runConfig.d.ts.map +1 -0
- package/bridging/runConfig.js +34 -0
- package/bridging/runConfig.js.map +1 -0
- package/bridging/runConfig.mjs +30 -0
- package/bridging/runConfig.mjs.map +1 -0
- package/bridging/runStats.d.mts +8 -0
- package/bridging/runStats.d.mts.map +1 -0
- package/bridging/runStats.d.ts +8 -0
- package/bridging/runStats.d.ts.map +1 -0
- package/bridging/runStats.js +16 -0
- package/bridging/runStats.js.map +1 -0
- package/bridging/runStats.mjs +12 -0
- package/bridging/runStats.mjs.map +1 -0
- package/bridging/samplingMethod.d.mts +11 -0
- package/bridging/samplingMethod.d.mts.map +1 -0
- package/bridging/samplingMethod.d.ts +11 -0
- package/bridging/samplingMethod.d.ts.map +1 -0
- package/bridging/samplingMethod.js +28 -0
- package/bridging/samplingMethod.js.map +1 -0
- package/bridging/samplingMethod.mjs +24 -0
- package/bridging/samplingMethod.mjs.map +1 -0
- package/bridging/samplingPolicy.d.mts +11 -0
- package/bridging/samplingPolicy.d.mts.map +1 -0
- package/bridging/samplingPolicy.d.ts +11 -0
- package/bridging/samplingPolicy.d.ts.map +1 -0
- package/bridging/samplingPolicy.js +25 -0
- package/bridging/samplingPolicy.js.map +1 -0
- package/bridging/samplingPolicy.mjs +21 -0
- package/bridging/samplingPolicy.mjs.map +1 -0
- package/bridging/samplingSeed.d.mts +10 -0
- package/bridging/samplingSeed.d.mts.map +1 -0
- package/bridging/samplingSeed.d.ts +10 -0
- package/bridging/samplingSeed.d.ts.map +1 -0
- package/bridging/samplingSeed.js +21 -0
- package/bridging/samplingSeed.js.map +1 -0
- package/bridging/samplingSeed.mjs +17 -0
- package/bridging/samplingSeed.mjs.map +1 -0
- package/bridging/session.d.mts +10 -0
- package/bridging/session.d.mts.map +1 -0
- package/bridging/session.d.ts +10 -0
- package/bridging/session.d.ts.map +1 -0
- package/bridging/session.js +19 -0
- package/bridging/session.js.map +1 -0
- package/bridging/session.mjs +15 -0
- package/bridging/session.mjs.map +1 -0
- package/bridging/stats.d.mts +11 -0
- package/bridging/stats.d.mts.map +1 -0
- package/bridging/stats.d.ts +11 -0
- package/bridging/stats.d.ts.map +1 -0
- package/bridging/stats.js +20 -0
- package/bridging/stats.js.map +1 -0
- package/bridging/stats.mjs +16 -0
- package/bridging/stats.mjs.map +1 -0
- package/bridging/stepStats.d.mts +13 -0
- package/bridging/stepStats.d.mts.map +1 -0
- package/bridging/stepStats.d.ts +13 -0
- package/bridging/stepStats.d.ts.map +1 -0
- package/bridging/stepStats.js +25 -0
- package/bridging/stepStats.js.map +1 -0
- package/bridging/stepStats.mjs +21 -0
- package/bridging/stepStats.mjs.map +1 -0
- package/bridging/text.d.mts +9 -0
- package/bridging/text.d.mts.map +1 -0
- package/bridging/text.d.ts +9 -0
- package/bridging/text.d.ts.map +1 -0
- package/bridging/text.js +17 -0
- package/bridging/text.js.map +1 -0
- package/bridging/text.mjs +13 -0
- package/bridging/text.mjs.map +1 -0
- package/bridging/totalStats.d.mts +9 -0
- package/bridging/totalStats.d.mts.map +1 -0
- package/bridging/totalStats.d.ts +9 -0
- package/bridging/totalStats.d.ts.map +1 -0
- package/bridging/totalStats.js +18 -0
- package/bridging/totalStats.js.map +1 -0
- package/bridging/totalStats.mjs +14 -0
- package/bridging/totalStats.mjs.map +1 -0
- package/error.d.mts +16 -0
- package/error.d.mts.map +1 -0
- package/error.d.ts +16 -0
- package/error.d.ts.map +1 -0
- package/error.js +42 -0
- package/error.js.map +1 -0
- package/error.mjs +37 -0
- package/error.mjs.map +1 -0
- package/index.d.mts +33 -0
- package/index.d.mts.map +1 -0
- package/index.d.ts +33 -0
- package/index.d.ts.map +1 -0
- package/index.js +74 -0
- package/index.js.map +1 -0
- package/index.mjs +33 -0
- package/index.mjs.map +1 -0
- package/interactors/downloadInteractor.d.mts +16 -0
- package/interactors/downloadInteractor.d.mts.map +1 -0
- package/interactors/downloadInteractor.d.ts +16 -0
- package/interactors/downloadInteractor.d.ts.map +1 -0
- package/interactors/downloadInteractor.js +38 -0
- package/interactors/downloadInteractor.js.map +1 -0
- package/interactors/downloadInteractor.mjs +34 -0
- package/interactors/downloadInteractor.mjs.map +1 -0
- package/interactors/engineInteractor.d.mts +17 -0
- package/interactors/engineInteractor.d.mts.map +1 -0
- package/interactors/engineInteractor.d.ts +17 -0
- package/interactors/engineInteractor.d.ts.map +1 -0
- package/interactors/engineInteractor.js +34 -0
- package/interactors/engineInteractor.js.map +1 -0
- package/interactors/engineInteractor.mjs +30 -0
- package/interactors/engineInteractor.mjs.map +1 -0
- package/interactors/interactor.d.mts +6 -0
- package/interactors/interactor.d.mts.map +1 -0
- package/interactors/interactor.d.ts +6 -0
- package/interactors/interactor.d.ts.map +1 -0
- package/interactors/interactor.js +3 -0
- package/interactors/interactor.js.map +1 -0
- package/interactors/interactor.mjs +2 -0
- package/interactors/interactor.mjs.map +1 -0
- package/interactors/modelInteractor.d.mts +30 -0
- package/interactors/modelInteractor.d.mts.map +1 -0
- package/interactors/modelInteractor.d.ts +30 -0
- package/interactors/modelInteractor.d.ts.map +1 -0
- package/interactors/modelInteractor.js +85 -0
- package/interactors/modelInteractor.js.map +1 -0
- package/interactors/modelInteractor.mjs +81 -0
- package/interactors/modelInteractor.mjs.map +1 -0
- package/interactors/modelsInteractor.d.mts +12 -0
- package/interactors/modelsInteractor.d.mts.map +1 -0
- package/interactors/modelsInteractor.d.ts +12 -0
- package/interactors/modelsInteractor.d.ts.map +1 -0
- package/interactors/modelsInteractor.js +25 -0
- package/interactors/modelsInteractor.js.map +1 -0
- package/interactors/modelsInteractor.mjs +21 -0
- package/interactors/modelsInteractor.mjs.map +1 -0
- package/interactors/sessionInteractor.d.mts +24 -0
- package/interactors/sessionInteractor.d.mts.map +1 -0
- package/interactors/sessionInteractor.d.ts +24 -0
- package/interactors/sessionInteractor.d.ts.map +1 -0
- package/interactors/sessionInteractor.js +50 -0
- package/interactors/sessionInteractor.js.map +1 -0
- package/interactors/sessionInteractor.mjs +46 -0
- package/interactors/sessionInteractor.mjs.map +1 -0
- package/internal/tslib.js +2 -0
- package/internal/tslib.mjs +1 -0
- package/{uzu.d.ts → napi/uzu.d.ts} +38 -37
- package/napi/uzu.js +95 -0
- package/napi/uzu.mjs +61 -0
- package/{uzu.node → napi/uzu.node} +0 -0
- package/package.json +96 -35
- package/src/bridging/classificationFeature.ts +20 -0
- package/src/bridging/config.ts +60 -0
- package/src/bridging/contextLength.ts +29 -0
- package/src/bridging/downloadHandle.ts +41 -0
- package/src/bridging/downloadProgressUpdate.ts +21 -0
- package/src/bridging/downloadState.ts +59 -0
- package/src/bridging/engine.ts +97 -0
- package/src/bridging/finishReason.ts +6 -0
- package/src/bridging/input.ts +29 -0
- package/src/bridging/licenseStatus.ts +39 -0
- package/src/bridging/message.ts +50 -0
- package/src/bridging/model.ts +32 -0
- package/src/bridging/napi.ts +3 -0
- package/src/bridging/output.ts +40 -0
- package/src/bridging/parsedText.ts +17 -0
- package/src/bridging/prefillStepSize.ts +32 -0
- package/src/bridging/preset.ts +34 -0
- package/src/bridging/role.ts +5 -0
- package/src/bridging/runConfig.ts +41 -0
- package/src/bridging/runStats.ts +17 -0
- package/src/bridging/samplingMethod.ts +32 -0
- package/src/bridging/samplingPolicy.ts +29 -0
- package/src/bridging/samplingSeed.ts +24 -0
- package/src/bridging/session.ts +24 -0
- package/src/bridging/stats.ts +22 -0
- package/src/bridging/stepStats.ts +37 -0
- package/src/bridging/text.ts +18 -0
- package/src/bridging/totalStats.ts +20 -0
- package/src/error.ts +38 -0
- package/src/index.ts +32 -0
- package/src/interactors/downloadInteractor.ts +47 -0
- package/src/interactors/engineInteractor.ts +48 -0
- package/src/interactors/interactor.ts +7 -0
- package/src/interactors/modelInteractor.ts +113 -0
- package/src/interactors/modelsInteractor.ts +29 -0
- package/src/interactors/sessionInteractor.ts +70 -0
- package/src/napi/uzu.d.ts +230 -0
- package/src/napi/uzu.js +95 -0
- package/src/napi/uzu.mjs +61 -0
- package/src/napi/uzu.node +0 -0
- package/src/tsconfig.json +11 -0
- package/src/utilities/env.ts +9 -0
- package/src/version.ts +1 -0
- package/utilities/env.d.mts +2 -0
- package/utilities/env.d.mts.map +1 -0
- package/utilities/env.d.ts +2 -0
- package/utilities/env.d.ts.map +1 -0
- package/utilities/env.js +14 -0
- package/utilities/env.js.map +1 -0
- package/utilities/env.mjs +10 -0
- package/utilities/env.mjs.map +1 -0
- package/version.d.mts +2 -0
- package/version.d.mts.map +1 -0
- package/version.d.ts +2 -0
- package/version.d.ts.map +1 -0
- package/version.js +5 -0
- package/version.js.map +1 -0
- package/version.mjs +2 -0
- package/version.mjs.map +1 -0
- package/README.orig.md +0 -213
- package/README.src.md +0 -124
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '../error';
|
|
2
|
+
import { LicenseStatus as NapiLicenseStatus } from '../napi/uzu';
|
|
3
|
+
|
|
4
|
+
export enum LicenseStatus {
|
|
5
|
+
NotActivated = 'NotActivated',
|
|
6
|
+
PaymentRequired = 'PaymentRequired',
|
|
7
|
+
GracePeriodActive = 'GracePeriodActive',
|
|
8
|
+
Activated = 'Activated',
|
|
9
|
+
NetworkError = 'NetworkError',
|
|
10
|
+
InvalidApiKey = 'InvalidApiKey',
|
|
11
|
+
SignatureMismatch = 'SignatureMismatch',
|
|
12
|
+
Timeout = 'Timeout',
|
|
13
|
+
HttpError = 'HttpError',
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function licenseStatusFromNapiLicenseStatus(napiLicenseStatus: NapiLicenseStatus): LicenseStatus {
|
|
17
|
+
switch (napiLicenseStatus.type) {
|
|
18
|
+
case 'NotActivated':
|
|
19
|
+
return LicenseStatus.NotActivated;
|
|
20
|
+
case 'PaymentRequired':
|
|
21
|
+
return LicenseStatus.PaymentRequired;
|
|
22
|
+
case 'GracePeriodActive':
|
|
23
|
+
return LicenseStatus.GracePeriodActive;
|
|
24
|
+
case 'Activated':
|
|
25
|
+
return LicenseStatus.Activated;
|
|
26
|
+
case 'NetworkError':
|
|
27
|
+
return LicenseStatus.NetworkError;
|
|
28
|
+
case 'InvalidApiKey':
|
|
29
|
+
return LicenseStatus.InvalidApiKey;
|
|
30
|
+
case 'SignatureMismatch':
|
|
31
|
+
return LicenseStatus.SignatureMismatch;
|
|
32
|
+
case 'Timeout':
|
|
33
|
+
return LicenseStatus.Timeout;
|
|
34
|
+
case 'HttpError':
|
|
35
|
+
return LicenseStatus.HttpError;
|
|
36
|
+
default:
|
|
37
|
+
throw new EngineError(EngineErrorCode.UnexpectedLicenseStatus);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Message as NapiMessage, Role as NapiRole } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
import { Role } from './role';
|
|
4
|
+
|
|
5
|
+
export class Message implements ToNapi<NapiMessage> {
|
|
6
|
+
readonly role: Role;
|
|
7
|
+
readonly content: string;
|
|
8
|
+
readonly reasoningContent: string | null;
|
|
9
|
+
|
|
10
|
+
private constructor(role: Role, content: string, reasoningContent: string | null = null) {
|
|
11
|
+
this.role = role;
|
|
12
|
+
this.content = content;
|
|
13
|
+
this.reasoningContent = reasoningContent;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static system(content: string): Message {
|
|
17
|
+
return new Message(Role.System, content);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static user(content: string): Message {
|
|
21
|
+
return new Message(Role.User, content);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static assistant(content: string, reasoningContent: string | null = null): Message {
|
|
25
|
+
return new Message(Role.Assistant, content, reasoningContent);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private static roleToNapiRole(role: Role): NapiRole {
|
|
29
|
+
switch (role) {
|
|
30
|
+
case Role.System:
|
|
31
|
+
return 0;
|
|
32
|
+
case Role.User:
|
|
33
|
+
return 1;
|
|
34
|
+
case Role.Assistant:
|
|
35
|
+
return 2;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
toNapi(): NapiMessage {
|
|
40
|
+
const napiRole: NapiRole = Message.roleToNapiRole(this.role);
|
|
41
|
+
const napiMessage: NapiMessage = {
|
|
42
|
+
role: napiRole,
|
|
43
|
+
content: this.content,
|
|
44
|
+
};
|
|
45
|
+
if (this.reasoningContent) {
|
|
46
|
+
napiMessage.reasoningContent = this.reasoningContent;
|
|
47
|
+
}
|
|
48
|
+
return napiMessage;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { CloudModel as NapiCloudModel, LocalModel as NapiLocalModel } from '../napi/uzu';
|
|
2
|
+
|
|
3
|
+
export enum ModelType {
|
|
4
|
+
Local = 'local',
|
|
5
|
+
Cloud = 'cloud',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export enum ModelKind {
|
|
9
|
+
Text = 'text',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class Model {
|
|
13
|
+
readonly repoId: string;
|
|
14
|
+
readonly type: ModelType;
|
|
15
|
+
readonly kind: ModelKind;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
|
|
18
|
+
private constructor(repoId: string, type: ModelType, kind: ModelKind, name: string) {
|
|
19
|
+
this.repoId = repoId;
|
|
20
|
+
this.type = type;
|
|
21
|
+
this.kind = kind;
|
|
22
|
+
this.name = name;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static fromNapiLocalModel(napiLocalModel: NapiLocalModel): Model {
|
|
26
|
+
return new Model(napiLocalModel.identifier, ModelType.Local, ModelKind.Text, napiLocalModel.name);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
static fromNapiCloudModel(napiCloudModel: NapiCloudModel): Model {
|
|
30
|
+
return new Model(napiCloudModel.repoId, ModelType.Cloud, ModelKind.Text, napiCloudModel.name);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '../error';
|
|
2
|
+
import { FinishReason as NapiFinishReason, Output as NapiOutput } from '../napi/uzu';
|
|
3
|
+
import { FinishReason } from './finishReason';
|
|
4
|
+
import { Stats } from './stats';
|
|
5
|
+
import { Text } from './text';
|
|
6
|
+
|
|
7
|
+
export class Output {
|
|
8
|
+
readonly text: Text;
|
|
9
|
+
readonly stats: Stats;
|
|
10
|
+
readonly finishReason: FinishReason | null;
|
|
11
|
+
|
|
12
|
+
private constructor(text: Text, stats: Stats, finishReason: FinishReason | null) {
|
|
13
|
+
this.text = text;
|
|
14
|
+
this.stats = stats;
|
|
15
|
+
this.finishReason = finishReason;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private static napiFinishReasonToFinishReason(napiFinishReason: NapiFinishReason): FinishReason {
|
|
19
|
+
switch (napiFinishReason) {
|
|
20
|
+
case 0:
|
|
21
|
+
return FinishReason.Stop;
|
|
22
|
+
case 1:
|
|
23
|
+
return FinishReason.Length;
|
|
24
|
+
case 2:
|
|
25
|
+
return FinishReason.Cancelled;
|
|
26
|
+
case 3:
|
|
27
|
+
return FinishReason.ContextLimitReached;
|
|
28
|
+
default:
|
|
29
|
+
throw new EngineError(EngineErrorCode.UnexpectedFinishReason);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static fromNapi(napiEntity: NapiOutput): Output {
|
|
34
|
+
const text = Text.fromNapi(napiEntity.text);
|
|
35
|
+
const stats = Stats.fromNapi(napiEntity.stats);
|
|
36
|
+
const finishReason =
|
|
37
|
+
napiEntity.finishReason ? Output.napiFinishReasonToFinishReason(napiEntity.finishReason) : null;
|
|
38
|
+
return new Output(text, stats, finishReason);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ParsedText as NapiParsedText } from '../napi/uzu';
|
|
2
|
+
|
|
3
|
+
export class ParsedText {
|
|
4
|
+
readonly chainOfThought: string | null;
|
|
5
|
+
readonly response: string | null;
|
|
6
|
+
|
|
7
|
+
private constructor(chainOfThought: string | null, response: string | null) {
|
|
8
|
+
this.chainOfThought = chainOfThought;
|
|
9
|
+
this.response = response;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static fromNapi(napiEntity: NapiParsedText): ParsedText {
|
|
13
|
+
const chainOfThought = napiEntity.chainOfThought ?? null;
|
|
14
|
+
const response = napiEntity.response ?? null;
|
|
15
|
+
return new ParsedText(chainOfThought, response);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PrefillStepSize as NapiPrefillStepSize } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
|
|
4
|
+
export class PrefillStepSize implements ToNapi<NapiPrefillStepSize> {
|
|
5
|
+
private readonly napiPrefillStepSize: NapiPrefillStepSize;
|
|
6
|
+
|
|
7
|
+
private constructor(napiPrefillStepSize: NapiPrefillStepSize) {
|
|
8
|
+
this.napiPrefillStepSize = napiPrefillStepSize;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static default(): PrefillStepSize {
|
|
12
|
+
const napiPrefillStepSize: NapiPrefillStepSize = { type: 'Default' };
|
|
13
|
+
return new PrefillStepSize(napiPrefillStepSize);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static maximal(): PrefillStepSize {
|
|
17
|
+
const napiPrefillStepSize: NapiPrefillStepSize = { type: 'Maximal' };
|
|
18
|
+
return new PrefillStepSize(napiPrefillStepSize);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static custom(length: number): PrefillStepSize {
|
|
22
|
+
const napiPrefillStepSize: NapiPrefillStepSize = {
|
|
23
|
+
type: 'Custom',
|
|
24
|
+
length,
|
|
25
|
+
};
|
|
26
|
+
return new PrefillStepSize(napiPrefillStepSize);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
toNapi(): NapiPrefillStepSize {
|
|
30
|
+
return this.napiPrefillStepSize;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Preset as NapiPreset } from '../napi/uzu';
|
|
2
|
+
import { ClassificationFeature } from './classificationFeature';
|
|
3
|
+
import { ToNapi } from './napi';
|
|
4
|
+
|
|
5
|
+
export class Preset implements ToNapi<NapiPreset> {
|
|
6
|
+
private readonly napiPreset: NapiPreset;
|
|
7
|
+
|
|
8
|
+
private constructor(napiPreset: NapiPreset) {
|
|
9
|
+
this.napiPreset = napiPreset;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static general(): Preset {
|
|
13
|
+
const napiPreset: NapiPreset = { type: 'General' };
|
|
14
|
+
return new Preset(napiPreset);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static classification(feature: ClassificationFeature): Preset {
|
|
18
|
+
const napiClassificationFeature = feature.toNapi();
|
|
19
|
+
const napiPreset: NapiPreset = {
|
|
20
|
+
type: 'Classification',
|
|
21
|
+
feature: napiClassificationFeature,
|
|
22
|
+
};
|
|
23
|
+
return new Preset(napiPreset);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static summarization(): Preset {
|
|
27
|
+
const napiPreset: NapiPreset = { type: 'Summarization' };
|
|
28
|
+
return new Preset(napiPreset);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toNapi(): NapiPreset {
|
|
32
|
+
return this.napiPreset;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RunConfig as NapiRunConfig } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
import { SamplingPolicy } from './samplingPolicy';
|
|
4
|
+
|
|
5
|
+
export class RunConfig implements ToNapi<NapiRunConfig> {
|
|
6
|
+
readonly tokensLimit: number;
|
|
7
|
+
readonly enableThinking: boolean;
|
|
8
|
+
readonly samplingPolicy: SamplingPolicy;
|
|
9
|
+
|
|
10
|
+
private constructor(tokensLimit: number, enableThinking: boolean, samplingPolicy: SamplingPolicy) {
|
|
11
|
+
this.tokensLimit = tokensLimit;
|
|
12
|
+
this.enableThinking = enableThinking;
|
|
13
|
+
this.samplingPolicy = samplingPolicy;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static default(): RunConfig {
|
|
17
|
+
return new RunConfig(1024, true, SamplingPolicy.default());
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
withTokensLimit(tokensLimit: number): RunConfig {
|
|
21
|
+
return new RunConfig(tokensLimit, this.enableThinking, this.samplingPolicy);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
withEnableThinking(enableThinking: boolean): RunConfig {
|
|
25
|
+
return new RunConfig(this.tokensLimit, enableThinking, this.samplingPolicy);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
withSamplingPolicy(samplingPolicy: SamplingPolicy): RunConfig {
|
|
29
|
+
return new RunConfig(this.tokensLimit, this.enableThinking, samplingPolicy);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toNapi(): NapiRunConfig {
|
|
33
|
+
const napiSamplingPolicy = this.samplingPolicy.toNapi();
|
|
34
|
+
const napiRunConfig: NapiRunConfig = {
|
|
35
|
+
tokensLimit: this.tokensLimit,
|
|
36
|
+
enableThinking: this.enableThinking,
|
|
37
|
+
samplingPolicy: napiSamplingPolicy,
|
|
38
|
+
};
|
|
39
|
+
return napiRunConfig;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RunStats as NapiRunStats } from '../napi/uzu';
|
|
2
|
+
|
|
3
|
+
export class RunStats {
|
|
4
|
+
readonly count: number;
|
|
5
|
+
readonly averageDuration: number;
|
|
6
|
+
|
|
7
|
+
private constructor(count: number, averageDuration: number) {
|
|
8
|
+
this.count = count;
|
|
9
|
+
this.averageDuration = averageDuration;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static fromNapi(napiEntity: NapiRunStats): RunStats {
|
|
13
|
+
const count = Number(napiEntity.count);
|
|
14
|
+
const averageDuration = napiEntity.averageDuration;
|
|
15
|
+
return new RunStats(count, averageDuration);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SamplingMethod as NapiSamplingMethod } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
|
|
4
|
+
export class SamplingMethod implements ToNapi<NapiSamplingMethod> {
|
|
5
|
+
private readonly napiSamplingMethod: NapiSamplingMethod;
|
|
6
|
+
|
|
7
|
+
private constructor(napiSamplingMethod: NapiSamplingMethod) {
|
|
8
|
+
this.napiSamplingMethod = napiSamplingMethod;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static greedy(): SamplingMethod {
|
|
12
|
+
const napiSamplingMethod: NapiSamplingMethod = { type: 'Greedy' };
|
|
13
|
+
return new SamplingMethod(napiSamplingMethod);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static temperature(temperature: number): SamplingMethod {
|
|
17
|
+
const napiSamplingMethod: NapiSamplingMethod = {
|
|
18
|
+
type: 'Temperature',
|
|
19
|
+
temperature,
|
|
20
|
+
};
|
|
21
|
+
return new SamplingMethod(napiSamplingMethod);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static topP(topP: number): SamplingMethod {
|
|
25
|
+
const napiSamplingMethod: NapiSamplingMethod = { type: 'TopP', topP };
|
|
26
|
+
return new SamplingMethod(napiSamplingMethod);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
toNapi(): NapiSamplingMethod {
|
|
30
|
+
return this.napiSamplingMethod;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { SamplingPolicy as NapiSamplingPolicy } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
import { SamplingMethod } from './samplingMethod';
|
|
4
|
+
|
|
5
|
+
export class SamplingPolicy implements ToNapi<NapiSamplingPolicy> {
|
|
6
|
+
private readonly napiSamplingPolicy: NapiSamplingPolicy;
|
|
7
|
+
|
|
8
|
+
private constructor(napiSamplingPolicy: NapiSamplingPolicy) {
|
|
9
|
+
this.napiSamplingPolicy = napiSamplingPolicy;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
static default(): SamplingPolicy {
|
|
13
|
+
const napiSamplingPolicy: NapiSamplingPolicy = { type: 'Default' };
|
|
14
|
+
return new SamplingPolicy(napiSamplingPolicy);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static custom(method: SamplingMethod): SamplingPolicy {
|
|
18
|
+
const napiSamplingMethod = method.toNapi();
|
|
19
|
+
const napiSamplingPolicy: NapiSamplingPolicy = {
|
|
20
|
+
type: 'Custom',
|
|
21
|
+
value: napiSamplingMethod,
|
|
22
|
+
};
|
|
23
|
+
return new SamplingPolicy(napiSamplingPolicy);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
toNapi(): NapiSamplingPolicy {
|
|
27
|
+
return this.napiSamplingPolicy;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SamplingSeed as NapiSamplingSeed } from '../napi/uzu';
|
|
2
|
+
import { ToNapi } from './napi';
|
|
3
|
+
|
|
4
|
+
export class SamplingSeed implements ToNapi<NapiSamplingSeed> {
|
|
5
|
+
private readonly napiSamplingSeed: NapiSamplingSeed;
|
|
6
|
+
|
|
7
|
+
private constructor(napiSamplingSeed: NapiSamplingSeed) {
|
|
8
|
+
this.napiSamplingSeed = napiSamplingSeed;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static default(): SamplingSeed {
|
|
12
|
+
const napiSamplingSeed: NapiSamplingSeed = { type: 'Default' };
|
|
13
|
+
return new SamplingSeed(napiSamplingSeed);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static custom(seed: number): SamplingSeed {
|
|
17
|
+
const napiSamplingSeed: NapiSamplingSeed = { type: 'Custom', seed };
|
|
18
|
+
return new SamplingSeed(napiSamplingSeed);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
toNapi(): NapiSamplingSeed {
|
|
22
|
+
return this.napiSamplingSeed;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Output as NapiOutput, Session as NapiSession } from '../napi/uzu';
|
|
2
|
+
import { Input } from './input';
|
|
3
|
+
import { Output } from './output';
|
|
4
|
+
import { RunConfig } from './runConfig';
|
|
5
|
+
|
|
6
|
+
export class Session {
|
|
7
|
+
private readonly napiSession: NapiSession;
|
|
8
|
+
|
|
9
|
+
constructor(napiSession: NapiSession) {
|
|
10
|
+
this.napiSession = napiSession;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
run(
|
|
14
|
+
input: Input,
|
|
15
|
+
config: RunConfig = RunConfig.default(),
|
|
16
|
+
progress: (partialOutput: Output) => boolean = () => true,
|
|
17
|
+
): Output {
|
|
18
|
+
const napiInput = input.toNapi();
|
|
19
|
+
const napiConfig = config.toNapi();
|
|
20
|
+
const napiProgress = (partialOutput: NapiOutput) => progress(Output.fromNapi(partialOutput));
|
|
21
|
+
const napiOutput = this.napiSession.run(napiInput, napiConfig, napiProgress);
|
|
22
|
+
return Output.fromNapi(napiOutput);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Stats as NapiStats } from '../napi/uzu';
|
|
2
|
+
import { StepStats } from './stepStats';
|
|
3
|
+
import { TotalStats } from './totalStats';
|
|
4
|
+
|
|
5
|
+
export class Stats {
|
|
6
|
+
readonly prefillStats: StepStats;
|
|
7
|
+
readonly generateStats: StepStats | null;
|
|
8
|
+
readonly totalStats: TotalStats;
|
|
9
|
+
|
|
10
|
+
private constructor(prefillStats: StepStats, generateStats: StepStats | null, totalStats: TotalStats) {
|
|
11
|
+
this.prefillStats = prefillStats;
|
|
12
|
+
this.generateStats = generateStats;
|
|
13
|
+
this.totalStats = totalStats;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static fromNapi(napiEntity: NapiStats): Stats {
|
|
17
|
+
const prefillStats = StepStats.fromNapi(napiEntity.prefillStats);
|
|
18
|
+
const generateStats = napiEntity.generateStats ? StepStats.fromNapi(napiEntity.generateStats) : null;
|
|
19
|
+
const totalStats = TotalStats.fromNapi(napiEntity.totalStats);
|
|
20
|
+
return new Stats(prefillStats, generateStats, totalStats);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { StepStats as NapiStepStats } from '../napi/uzu';
|
|
2
|
+
import { RunStats } from './runStats';
|
|
3
|
+
|
|
4
|
+
export class StepStats {
|
|
5
|
+
readonly duration: number;
|
|
6
|
+
readonly suffixLength: number;
|
|
7
|
+
readonly tokensCount: number;
|
|
8
|
+
readonly tokensPerSecond: number;
|
|
9
|
+
readonly modelRun: RunStats;
|
|
10
|
+
readonly run: RunStats | null;
|
|
11
|
+
|
|
12
|
+
private constructor(
|
|
13
|
+
duration: number,
|
|
14
|
+
suffixLength: number,
|
|
15
|
+
tokensCount: number,
|
|
16
|
+
tokensPerSecond: number,
|
|
17
|
+
modelRun: RunStats,
|
|
18
|
+
run: RunStats | null,
|
|
19
|
+
) {
|
|
20
|
+
this.duration = duration;
|
|
21
|
+
this.suffixLength = suffixLength;
|
|
22
|
+
this.tokensCount = tokensCount;
|
|
23
|
+
this.tokensPerSecond = tokensPerSecond;
|
|
24
|
+
this.modelRun = modelRun;
|
|
25
|
+
this.run = run;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static fromNapi(napiEntity: NapiStepStats): StepStats {
|
|
29
|
+
const duration = napiEntity.duration;
|
|
30
|
+
const suffixLength = Number(napiEntity.suffixLength);
|
|
31
|
+
const tokensCount = Number(napiEntity.tokensCount);
|
|
32
|
+
const tokensPerSecond = napiEntity.tokensPerSecond;
|
|
33
|
+
const modelRun = RunStats.fromNapi(napiEntity.modelRun);
|
|
34
|
+
const run = napiEntity.run ? RunStats.fromNapi(napiEntity.run) : null;
|
|
35
|
+
return new StepStats(duration, suffixLength, tokensCount, tokensPerSecond, modelRun, run);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Text as NapiText } from '../napi/uzu';
|
|
2
|
+
import { ParsedText } from './parsedText';
|
|
3
|
+
|
|
4
|
+
export class Text {
|
|
5
|
+
readonly original: string;
|
|
6
|
+
readonly parsed: ParsedText;
|
|
7
|
+
|
|
8
|
+
private constructor(original: string, parsed: ParsedText) {
|
|
9
|
+
this.original = original;
|
|
10
|
+
this.parsed = parsed;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
static fromNapi(napiEntity: NapiText): Text {
|
|
14
|
+
const original = napiEntity.original;
|
|
15
|
+
const parsed = ParsedText.fromNapi(napiEntity.parsed);
|
|
16
|
+
return new Text(original, parsed);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TotalStats as NapiTotalStats } from '../napi/uzu';
|
|
2
|
+
|
|
3
|
+
export class TotalStats {
|
|
4
|
+
readonly duration: number;
|
|
5
|
+
readonly tokensCountInput: number;
|
|
6
|
+
readonly tokensCountOutput: number;
|
|
7
|
+
|
|
8
|
+
private constructor(duration: number, tokensCountInput: number, tokensCountOutput: number) {
|
|
9
|
+
this.duration = duration;
|
|
10
|
+
this.tokensCountInput = tokensCountInput;
|
|
11
|
+
this.tokensCountOutput = tokensCountOutput;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static fromNapi(napiEntity: NapiTotalStats): TotalStats {
|
|
15
|
+
const duration = napiEntity.duration;
|
|
16
|
+
const tokensCountInput = Number(napiEntity.tokensCountInput);
|
|
17
|
+
const tokensCountOutput = Number(napiEntity.tokensCountOutput);
|
|
18
|
+
return new TotalStats(duration, tokensCountInput, tokensCountOutput);
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/error.ts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export enum EngineErrorCode {
|
|
2
|
+
APIKeyNotFound = 'apiKeyNotFound',
|
|
3
|
+
ModelNotFound = 'modelNotFound',
|
|
4
|
+
ExpectedLocalModel = 'expectedLocalModel',
|
|
5
|
+
ExpectedTextModel = 'expectedTextModel',
|
|
6
|
+
UnexpectedDownloadPhase = 'unexpectedDownloadPhase',
|
|
7
|
+
UnexpectedFinishReason = 'unexpectedFinishReason',
|
|
8
|
+
UnexpectedLicenseStatus = 'unexpectedLicenseStatus',
|
|
9
|
+
LicenseNotActivated = 'licenseNotActivated',
|
|
10
|
+
Unknown = 'unknown',
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const errorCodeToMessage = {
|
|
14
|
+
[EngineErrorCode.APIKeyNotFound]: 'API key not found',
|
|
15
|
+
[EngineErrorCode.ModelNotFound]: 'Model not found',
|
|
16
|
+
[EngineErrorCode.ExpectedLocalModel]: 'Expected local model',
|
|
17
|
+
[EngineErrorCode.ExpectedTextModel]: 'Expected text model',
|
|
18
|
+
[EngineErrorCode.UnexpectedDownloadPhase]: 'Unexpected download phase',
|
|
19
|
+
[EngineErrorCode.UnexpectedFinishReason]: 'Unexpected finish reason',
|
|
20
|
+
[EngineErrorCode.UnexpectedLicenseStatus]: 'Unexpected license status',
|
|
21
|
+
[EngineErrorCode.LicenseNotActivated]: 'License not activated',
|
|
22
|
+
[EngineErrorCode.Unknown]: 'Unknown error',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export class EngineError extends Error {
|
|
26
|
+
constructor(code: EngineErrorCode) {
|
|
27
|
+
const message = errorCodeToMessage[code] ?? errorCodeToMessage[EngineErrorCode.Unknown];
|
|
28
|
+
super(message);
|
|
29
|
+
this.name = 'EngineError';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function unwrapOrThrow<T>(value: T | null | undefined, errorCode: EngineErrorCode): T {
|
|
34
|
+
if (value === null || value === undefined) {
|
|
35
|
+
throw new EngineError(errorCode);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export { ClassificationFeature } from './bridging/classificationFeature';
|
|
2
|
+
export { Config } from './bridging/config';
|
|
3
|
+
export { ContextLength } from './bridging/contextLength';
|
|
4
|
+
export { DownloadHandle } from './bridging/downloadHandle';
|
|
5
|
+
export { DownloadProgressUpdate } from './bridging/downloadProgressUpdate';
|
|
6
|
+
export { DownloadPhase, DownloadState } from './bridging/downloadState';
|
|
7
|
+
export { Engine as default } from './bridging/engine';
|
|
8
|
+
export { FinishReason } from './bridging/finishReason';
|
|
9
|
+
export { Input } from './bridging/input';
|
|
10
|
+
export { Message } from './bridging/message';
|
|
11
|
+
export { Model, ModelKind, ModelType } from './bridging/model';
|
|
12
|
+
export { Output } from './bridging/output';
|
|
13
|
+
export { ParsedText } from './bridging/parsedText';
|
|
14
|
+
export { PrefillStepSize } from './bridging/prefillStepSize';
|
|
15
|
+
export { Preset } from './bridging/preset';
|
|
16
|
+
export { Role } from './bridging/role';
|
|
17
|
+
export { RunConfig } from './bridging/runConfig';
|
|
18
|
+
export { RunStats } from './bridging/runStats';
|
|
19
|
+
export { SamplingMethod } from './bridging/samplingMethod';
|
|
20
|
+
export { SamplingPolicy } from './bridging/samplingPolicy';
|
|
21
|
+
export { SamplingSeed } from './bridging/samplingSeed';
|
|
22
|
+
export { Session } from './bridging/session';
|
|
23
|
+
export { Stats } from './bridging/stats';
|
|
24
|
+
export { StepStats } from './bridging/stepStats';
|
|
25
|
+
export { Text } from './bridging/text';
|
|
26
|
+
export { TotalStats } from './bridging/totalStats';
|
|
27
|
+
export { EngineError } from './error';
|
|
28
|
+
export { DownloadInteractor } from './interactors/downloadInteractor';
|
|
29
|
+
export { EngineInteractor } from './interactors/engineInteractor';
|
|
30
|
+
export { ModelInteractor } from './interactors/modelInteractor';
|
|
31
|
+
export { ModelsInteractor } from './interactors/modelsInteractor';
|
|
32
|
+
export { SessionInteractor } from './interactors/sessionInteractor';
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { DownloadHandle } from '../bridging/downloadHandle';
|
|
2
|
+
import { DownloadProgressUpdate } from '../bridging/downloadProgressUpdate';
|
|
3
|
+
import { Interactor, InteractorEntity } from './interactor';
|
|
4
|
+
import { ModelInteractor } from './modelInteractor';
|
|
5
|
+
|
|
6
|
+
export class DownloadInteractor implements Interactor<DownloadHandle> {
|
|
7
|
+
readonly modelInteractor: ModelInteractor;
|
|
8
|
+
readonly entity: InteractorEntity<DownloadHandle>;
|
|
9
|
+
|
|
10
|
+
constructor(modelInteractor: ModelInteractor, handle: InteractorEntity<DownloadHandle>) {
|
|
11
|
+
this.modelInteractor = modelInteractor;
|
|
12
|
+
this.entity = handle;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async finalize(): Promise<DownloadHandle> {
|
|
16
|
+
return await this.entity;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
resume() {
|
|
20
|
+
return this.proxyHandleCall(async (handle) => await handle.download());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
pause() {
|
|
24
|
+
return this.proxyHandleCall(async (handle) => await handle.pause());
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
delete() {
|
|
28
|
+
return this.proxyHandleCall(async (handle) => await handle.delete());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
onProgressUpdate(callback: (progressUpdate: DownloadProgressUpdate) => void) {
|
|
32
|
+
return this.proxyHandleCall(async (handle) => {
|
|
33
|
+
for await (const update of handle.progressUpdate()) {
|
|
34
|
+
callback(update);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
private proxyHandleCall(callback: (handle: DownloadHandle) => Promise<void>): DownloadInteractor {
|
|
40
|
+
const handlePromise = (async () => {
|
|
41
|
+
const handle = await this.finalize();
|
|
42
|
+
await callback(handle);
|
|
43
|
+
return handle;
|
|
44
|
+
})();
|
|
45
|
+
return new DownloadInteractor(this.modelInteractor, handlePromise);
|
|
46
|
+
}
|
|
47
|
+
}
|