assistant-robot 0.0.1-alpha → 0.0.1
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/.eslintrc.json +10 -0
- package/dist/AssistantModel.d.ts +31 -0
- package/dist/LanguageModel.d.ts +23 -0
- package/dist/LanguageModel.js +1 -66
- package/dist/LanguageModel.mjs +37 -34
- package/dist/QuestionManager.d.ts +9 -0
- package/dist/UserDetector.d.ts +18 -0
- package/dist/constants.d.ts +29 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +1 -325
- package/dist/index.mjs +1779 -227
- package/dist/type.d.ts +57 -0
- package/dist/utils-ePOYkfFK.js +64 -0
- package/dist/utils-vFpckT4x.mjs +136 -0
- package/dist/utils.d.ts +6 -0
- package/index.d.ts +3 -0
- package/package.json +12 -3
- package/tsconfig.json +26 -0
- package/dist/utils-1rt7_Dvg.js +0 -153
- package/dist/utils-7giLo_Tq.mjs +0 -154
package/.eslintrc.json
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
{
|
2
|
+
"root": true,
|
3
|
+
"env": { "browser": true, "es2020": true },
|
4
|
+
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
|
5
|
+
"ignorePatterns": ["dist", ".eslintrc.cjs"],
|
6
|
+
"parser": "@typescript-eslint/parser",
|
7
|
+
"rules": {
|
8
|
+
"@typescript-eslint/no-explicit-any": "off"
|
9
|
+
}
|
10
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import { PerspectiveCamera, Scene, WebGL1Renderer, Object3D, AnimationMixer, AnimationClip, AnimationAction, Clock } from "three";
|
2
|
+
import type { TRobotModelConfig, IModelConfig } from "./type";
|
3
|
+
export declare class AssistantModel {
|
4
|
+
clock: Clock;
|
5
|
+
container: Element;
|
6
|
+
tip: HTMLElement;
|
7
|
+
scene: Scene;
|
8
|
+
renderer: WebGL1Renderer | undefined;
|
9
|
+
model: Object3D | undefined;
|
10
|
+
camera: PerspectiveCamera | undefined;
|
11
|
+
mixer: AnimationMixer | undefined;
|
12
|
+
clips: AnimationClip[] | undefined;
|
13
|
+
timer: number | undefined;
|
14
|
+
options: TRobotModelConfig;
|
15
|
+
idleAction: AnimationAction | undefined;
|
16
|
+
constructor(container: Element, options: TRobotModelConfig);
|
17
|
+
init(options?: TRobotModelConfig): void;
|
18
|
+
loadModel(modelUrl: string, { position, rotation }?: Partial<IModelConfig>): void;
|
19
|
+
startIdleAction(): void;
|
20
|
+
haltIdleAction(durationInSeconds: number): void;
|
21
|
+
hello(): void;
|
22
|
+
play(name: string, { loop, weight, timeScale, }?: {
|
23
|
+
loop?: boolean;
|
24
|
+
weight?: number;
|
25
|
+
timeScale?: number;
|
26
|
+
}): void;
|
27
|
+
hideTip(): void;
|
28
|
+
say(text: string): void;
|
29
|
+
animate(): void;
|
30
|
+
rotate(x?: number, y?: number): void;
|
31
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { QuestionAndAnswer } from "@tensorflow-models/qna";
|
2
|
+
import "@tensorflow/tfjs-core";
|
3
|
+
import "@tensorflow/tfjs-backend-cpu";
|
4
|
+
import "@tensorflow/tfjs-backend-webgl";
|
5
|
+
import { ELanguageModelStatus } from "./constants";
|
6
|
+
import type { TCallback, ILanguageModelOptions } from "./type";
|
7
|
+
export declare abstract class LanguageModel {
|
8
|
+
status: ELanguageModelStatus;
|
9
|
+
onLoadList: TCallback[];
|
10
|
+
loaded(): void;
|
11
|
+
onLoad(fn: TCallback): void;
|
12
|
+
removeLoadCb(fn: TCallback): void;
|
13
|
+
abstract findAnswers(question: string): Promise<string>;
|
14
|
+
constructor();
|
15
|
+
}
|
16
|
+
export declare class MobileBertModel extends LanguageModel {
|
17
|
+
passage: string;
|
18
|
+
modelUrl: string;
|
19
|
+
model: QuestionAndAnswer | undefined;
|
20
|
+
constructor({ passage, modelUrl }: ILanguageModelOptions);
|
21
|
+
init(): Promise<void>;
|
22
|
+
findAnswers(question: string): Promise<string>;
|
23
|
+
}
|
package/dist/LanguageModel.js
CHANGED
@@ -1,66 +1 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __defProp = Object.defineProperty;
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
4
|
-
var __publicField = (obj, key, value) => {
|
5
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
6
|
-
return value;
|
7
|
-
};
|
8
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
9
|
-
const qna = require("@tensorflow-models/qna");
|
10
|
-
require("@tensorflow/tfjs-core");
|
11
|
-
require("@tensorflow/tfjs-backend-cpu");
|
12
|
-
require("@tensorflow/tfjs-backend-webgl");
|
13
|
-
const utils = require("./utils-1rt7_Dvg.js");
|
14
|
-
function _interopNamespaceDefault(e) {
|
15
|
-
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
16
|
-
if (e) {
|
17
|
-
for (const k in e) {
|
18
|
-
if (k !== "default") {
|
19
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
20
|
-
Object.defineProperty(n, k, d.get ? d : {
|
21
|
-
enumerable: true,
|
22
|
-
get: () => e[k]
|
23
|
-
});
|
24
|
-
}
|
25
|
-
}
|
26
|
-
}
|
27
|
-
n.default = e;
|
28
|
-
return Object.freeze(n);
|
29
|
-
}
|
30
|
-
const qna__namespace = /* @__PURE__ */ _interopNamespaceDefault(qna);
|
31
|
-
class MobileBertModel {
|
32
|
-
constructor({ passage }) {
|
33
|
-
__publicField(this, "status", utils.LanguageModelStatus.loading);
|
34
|
-
__publicField(this, "passage");
|
35
|
-
__publicField(this, "model");
|
36
|
-
__publicField(this, "onLoadList", []);
|
37
|
-
this.passage = passage;
|
38
|
-
this.init();
|
39
|
-
}
|
40
|
-
async init() {
|
41
|
-
this.status = utils.LanguageModelStatus.loading;
|
42
|
-
try {
|
43
|
-
this.model = await qna__namespace.load();
|
44
|
-
this.status = utils.LanguageModelStatus.ready;
|
45
|
-
this.onLoadList.forEach((fn) => fn());
|
46
|
-
} catch (e) {
|
47
|
-
console.warn(e);
|
48
|
-
this.status = utils.LanguageModelStatus.error;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
async findAnswers(question) {
|
52
|
-
if (this.model) {
|
53
|
-
const answers = await this.model.findAnswers(question, this.passage);
|
54
|
-
const answer = utils.findHighestScoreItem(answers);
|
55
|
-
return !answer ? "" : answer.text;
|
56
|
-
}
|
57
|
-
return "";
|
58
|
-
}
|
59
|
-
onLoad(fn) {
|
60
|
-
this.onLoadList.push(fn);
|
61
|
-
}
|
62
|
-
removeLoadCb(fn) {
|
63
|
-
this.onLoadList = this.onLoadList.filter((f) => f != fn);
|
64
|
-
}
|
65
|
-
}
|
66
|
-
exports.MobileBertModel = MobileBertModel;
|
1
|
+
"use strict";var l=Object.defineProperty;var d=(s,t,e)=>t in s?l(s,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):s[t]=e;var a=(s,t,e)=>(d(s,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@tensorflow-models/qna");require("@tensorflow/tfjs-core");require("@tensorflow/tfjs-backend-cpu");require("@tensorflow/tfjs-backend-webgl");const r=require("./utils-ePOYkfFK.js");function c(s){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const e in s)if(e!=="default"){const o=Object.getOwnPropertyDescriptor(s,e);Object.defineProperty(t,e,o.get?o:{enumerable:!0,get:()=>s[e]})}}return t.default=s,Object.freeze(t)}const g=c(u);class i{constructor(){a(this,"status",r.ELanguageModelStatus.loading);a(this,"onLoadList",[])}loaded(){this.status=r.ELanguageModelStatus.ready,this.onLoadList.forEach(t=>t())}onLoad(t){this.onLoadList.push(t)}removeLoadCb(t){this.onLoadList=this.onLoadList.filter(e=>e!=t)}}class h extends i{constructor({passage:e,modelUrl:o}){super();a(this,"passage");a(this,"modelUrl");a(this,"model");this.passage=e,this.modelUrl=o,this.init()}async init(){this.status=r.ELanguageModelStatus.loading;try{const e=this.modelUrl?{modelUrl:this.modelUrl}:void 0;this.model=await g.load(e),this.loaded()}catch(e){console.warn(e),this.status=r.ELanguageModelStatus.error}}async findAnswers(e){if(this.model){const o=await this.model.findAnswers(e,this.passage),n=r.findHighestScoreItem(o);return n?n.text:""}return""}}exports.LanguageModel=i;exports.MobileBertModel=h;
|
package/dist/LanguageModel.mjs
CHANGED
@@ -1,49 +1,52 @@
|
|
1
|
-
var
|
2
|
-
var
|
3
|
-
var
|
4
|
-
|
5
|
-
return value;
|
6
|
-
};
|
7
|
-
import * as qna from "@tensorflow-models/qna";
|
1
|
+
var n = Object.defineProperty;
|
2
|
+
var d = (o, t, s) => t in o ? n(o, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[t] = s;
|
3
|
+
var a = (o, t, s) => (d(o, typeof t != "symbol" ? t + "" : t, s), s);
|
4
|
+
import * as l from "@tensorflow-models/qna";
|
8
5
|
import "@tensorflow/tfjs-core";
|
9
6
|
import "@tensorflow/tfjs-backend-cpu";
|
10
7
|
import "@tensorflow/tfjs-backend-webgl";
|
11
|
-
import {
|
12
|
-
class
|
13
|
-
constructor(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
this.
|
19
|
-
|
8
|
+
import { E as i, h } from "./utils-vFpckT4x.mjs";
|
9
|
+
class m {
|
10
|
+
constructor() {
|
11
|
+
a(this, "status", i.loading);
|
12
|
+
a(this, "onLoadList", []);
|
13
|
+
}
|
14
|
+
loaded() {
|
15
|
+
this.status = i.ready, this.onLoadList.forEach((t) => t());
|
16
|
+
}
|
17
|
+
onLoad(t) {
|
18
|
+
this.onLoadList.push(t);
|
19
|
+
}
|
20
|
+
removeLoadCb(t) {
|
21
|
+
this.onLoadList = this.onLoadList.filter((s) => s != t);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
class f extends m {
|
25
|
+
constructor({ passage: s, modelUrl: e }) {
|
26
|
+
super();
|
27
|
+
a(this, "passage");
|
28
|
+
a(this, "modelUrl");
|
29
|
+
a(this, "model");
|
30
|
+
this.passage = s, this.modelUrl = e, this.init();
|
20
31
|
}
|
21
32
|
async init() {
|
22
|
-
this.status =
|
33
|
+
this.status = i.loading;
|
23
34
|
try {
|
24
|
-
this.
|
25
|
-
this.
|
26
|
-
|
27
|
-
|
28
|
-
console.warn(e);
|
29
|
-
this.status = LanguageModelStatus.error;
|
35
|
+
const s = this.modelUrl ? { modelUrl: this.modelUrl } : void 0;
|
36
|
+
this.model = await l.load(s), this.loaded();
|
37
|
+
} catch (s) {
|
38
|
+
console.warn(s), this.status = i.error;
|
30
39
|
}
|
31
40
|
}
|
32
|
-
async findAnswers(
|
41
|
+
async findAnswers(s) {
|
33
42
|
if (this.model) {
|
34
|
-
const
|
35
|
-
|
36
|
-
return !answer ? "" : answer.text;
|
43
|
+
const e = await this.model.findAnswers(s, this.passage), r = h(e);
|
44
|
+
return r ? r.text : "";
|
37
45
|
}
|
38
46
|
return "";
|
39
47
|
}
|
40
|
-
onLoad(fn) {
|
41
|
-
this.onLoadList.push(fn);
|
42
|
-
}
|
43
|
-
removeLoadCb(fn) {
|
44
|
-
this.onLoadList = this.onLoadList.filter((f) => f != fn);
|
45
|
-
}
|
46
48
|
}
|
47
49
|
export {
|
48
|
-
|
50
|
+
m as LanguageModel,
|
51
|
+
f as MobileBertModel
|
49
52
|
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { IChatBoxConfig } from "./type";
|
2
|
+
export declare class QuestionManager {
|
3
|
+
btnDom: HTMLButtonElement | undefined;
|
4
|
+
inputDom: HTMLInputElement | undefined;
|
5
|
+
onAsk: (question: string) => void;
|
6
|
+
constructor(container: Element, onAsk: (question: string) => void, options?: IChatBoxConfig);
|
7
|
+
initChatBox(container: Element, options?: IChatBoxConfig): void;
|
8
|
+
addEventListener(): void;
|
9
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import * as faceDetection from "@tensorflow-models/face-detection";
|
2
|
+
import type { FaceDetector } from "@tensorflow-models/face-detection";
|
3
|
+
import { IUserDetectorConfig } from "./type";
|
4
|
+
export declare class UserDetector {
|
5
|
+
video: HTMLVideoElement;
|
6
|
+
detector: FaceDetector | undefined;
|
7
|
+
videoWidth: number;
|
8
|
+
videoHeight: number;
|
9
|
+
options: IUserDetectorConfig;
|
10
|
+
constructor(options?: IUserDetectorConfig);
|
11
|
+
init(): void;
|
12
|
+
initVideo(): Promise<void>;
|
13
|
+
createDetector(): Promise<void>;
|
14
|
+
getFaces(): Promise<faceDetection.Face[]>;
|
15
|
+
getFace(): Promise<faceDetection.Face>;
|
16
|
+
getFacePostion(): Promise<number[]>;
|
17
|
+
getFaceAngle(): Promise<number[]>;
|
18
|
+
}
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import type { IModelSceneConfig, IModelConfig } from "./type";
|
2
|
+
export declare const TARGET_FPS = 60;
|
3
|
+
export declare const MODEL_CONFIG: IModelConfig;
|
4
|
+
export declare const MODEL_SCENE_CONFIG: IModelSceneConfig;
|
5
|
+
export declare const VIDEO_SIZE: {
|
6
|
+
big: {
|
7
|
+
width: number;
|
8
|
+
height: number;
|
9
|
+
};
|
10
|
+
small: {
|
11
|
+
width: number;
|
12
|
+
height: number;
|
13
|
+
};
|
14
|
+
};
|
15
|
+
export declare const ASSISTANT_MODEL_CONTAINER_CLASS = "assistant-robot-model-container";
|
16
|
+
export declare const ASSISTANT_TIP_CONTAINER = "assistant_tip_container";
|
17
|
+
export declare const CONTAINER_HEAD = "<div class=\"assistant-robot-container ";
|
18
|
+
export declare const CONTAINER_BODY = "\">\n <style>\n .assistant-robot-container{\n width: 100%;\n height: 100%;\n display: flex;\n flex-direction: column;\n }\n .assistant-robot-model-container{\n flex: 1;\n position:relative;\n width:100%;\n }\n .assistant_tip_container{\n position: absolute;\n top: 2px;\n left: 50%;\n min-width: 100px;\n border: 1px solid #aaaaaa;\n border-radius: 6px;\n background: #fff;\n transform: translate(-50%);\n padding: 12px 20px;\n text-align: center;\n }\n .assistant_tip_container::after{\n content: '';\n display: block;\n position: absolute;\n bottom: -6px;\n left: 50%;\n width: 8px;\n height: 8px;\n transform: rotate(45deg);\n border-bottom: 1px solid #aaaaaa;\n border-right: 1px solid #aaaaaa;\n background: #fff;\n }\n </style>\n <div class=\"assistant-robot-model-container\">\n <div class=\"assistant_tip_container\">HI!</div>\n\n </div>\n<div>\n";
|
19
|
+
export declare const ROBOT_CHAT_INPUT_CLASS = "assistant-robot-input";
|
20
|
+
export declare const ROBOT_CHAT_BTN_CLASS = "assistant-robot-btn";
|
21
|
+
export declare const ROBOT_CHAT_BOX_HEAD = "<div class=\"assistant-robot-chartbox";
|
22
|
+
export declare const ROBOT_CHAT_BOX_BODY = "\">\n<style>\n .assistant-robot-chartbox{\n width: 100%;\n display: flex;\n flex-wrap: wrap;\n }\n .assistant-robot-input{\n flex: 1;\n min-width: 200px;\n background: rgba(0,0,0,0);\n border: 1px solid #aaaaaa;\n }\n .assistant-robot-btn{\n flex: 0 0 auto;\n }\n</style>\n<input class=\"assistant-robot-input\" type=\"text\" />\n<button class=\"assistant-robot-btn\">ask</button>\n</div>";
|
23
|
+
export declare enum ELanguageModelStatus {
|
24
|
+
loading = 1,
|
25
|
+
ready = 2,
|
26
|
+
error = 3
|
27
|
+
}
|
28
|
+
export declare const ONE_LETTER_READ_TIME = 50;
|
29
|
+
export declare const READ_WAIT_TIME = 2000;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
import { AssistantModel } from "./AssistantModel";
|
2
|
+
import { UserDetector } from "./UserDetector";
|
3
|
+
import { QuestionManager } from "./QuestionManager";
|
4
|
+
import type { LanguageModel } from "./LanguageModel";
|
5
|
+
import type { IAssistantRobotConfig } from "./type";
|
6
|
+
export declare class Assistant<T extends LanguageModel> {
|
7
|
+
assistantModel: AssistantModel;
|
8
|
+
userDetector: UserDetector;
|
9
|
+
questionManager: QuestionManager | undefined;
|
10
|
+
languageModel: T;
|
11
|
+
options: IAssistantRobotConfig<T>;
|
12
|
+
constructor(el: Element, options: IAssistantRobotConfig<T>);
|
13
|
+
handleLanguageModelLoad: () => void;
|
14
|
+
ask: (question: string) => Promise<void>;
|
15
|
+
lookAtUser(): Promise<void>;
|
16
|
+
}
|