assistant-robot 0.0.1-alpha
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/dist/LanguageModel.js +66 -0
- package/dist/LanguageModel.mjs +49 -0
- package/dist/index.js +325 -0
- package/dist/index.mjs +307 -0
- package/dist/utils-1rt7_Dvg.js +153 -0
- package/dist/utils-7giLo_Tq.mjs +154 -0
- package/package.json +41 -0
@@ -0,0 +1,153 @@
|
|
1
|
+
"use strict";
|
2
|
+
const TARGET_FPS = 60;
|
3
|
+
const MODEL_CONFIG = {
|
4
|
+
position: [0, 0, 0],
|
5
|
+
rotation: [0, Math.PI, 0]
|
6
|
+
};
|
7
|
+
const MODEL_SCENE_CONFIG = {
|
8
|
+
backgroundColor: 0,
|
9
|
+
backgroundAlpha: 0,
|
10
|
+
camera: {
|
11
|
+
fov: 50,
|
12
|
+
near: 0.1,
|
13
|
+
far: 10,
|
14
|
+
position: [0, 0, 2],
|
15
|
+
lookAt: [0, 0, 0]
|
16
|
+
},
|
17
|
+
ambientLight: {
|
18
|
+
color: 16777215,
|
19
|
+
intensity: 0.5
|
20
|
+
},
|
21
|
+
directionalLight: {
|
22
|
+
color: 16777215,
|
23
|
+
intensity: 2,
|
24
|
+
position: [10, 10, 0]
|
25
|
+
}
|
26
|
+
};
|
27
|
+
const VIDEO_SIZE = {
|
28
|
+
big: { width: 640, height: 480 },
|
29
|
+
small: { width: 360, height: 270 }
|
30
|
+
};
|
31
|
+
const ASSISTANT_MODEL_CONTAINER_CLASS = "assistant-robot-model-container";
|
32
|
+
const ASSISTANT_TIP_CONTAINER = "assistant_tip_container";
|
33
|
+
const CONTAINER_HEAD = `<div class="assistant-robot-container `;
|
34
|
+
const CONTAINER_BODY = `">
|
35
|
+
<style>
|
36
|
+
.assistant-robot-container{
|
37
|
+
width: 100%;
|
38
|
+
height: 100%;
|
39
|
+
display: flex;
|
40
|
+
flex-direction: column;
|
41
|
+
}
|
42
|
+
.${ASSISTANT_MODEL_CONTAINER_CLASS}{
|
43
|
+
flex: 1;
|
44
|
+
position:relative;
|
45
|
+
width:100%;
|
46
|
+
}
|
47
|
+
.${ASSISTANT_TIP_CONTAINER}{
|
48
|
+
position: absolute;
|
49
|
+
top: 2px;
|
50
|
+
left: 50%;
|
51
|
+
min-width: 100px;
|
52
|
+
border: 1px solid #aaaaaa;
|
53
|
+
border-radius: 6px;
|
54
|
+
background: #fff;
|
55
|
+
transform: translate(-50%);
|
56
|
+
padding: 12px 20px;
|
57
|
+
text-align: center;
|
58
|
+
}
|
59
|
+
.${ASSISTANT_TIP_CONTAINER}::after{
|
60
|
+
content: '';
|
61
|
+
display: block;
|
62
|
+
position: absolute;
|
63
|
+
bottom: -6px;
|
64
|
+
left: 50%;
|
65
|
+
width: 8px;
|
66
|
+
height: 8px;
|
67
|
+
transform: rotate(45deg);
|
68
|
+
border-bottom: 1px solid #aaaaaa;
|
69
|
+
border-right: 1px solid #aaaaaa;
|
70
|
+
background: #fff;
|
71
|
+
}
|
72
|
+
</style>
|
73
|
+
<div class="${ASSISTANT_MODEL_CONTAINER_CLASS}">
|
74
|
+
<div class="${ASSISTANT_TIP_CONTAINER}">HI!</div>
|
75
|
+
|
76
|
+
</div>
|
77
|
+
<div>
|
78
|
+
`;
|
79
|
+
const ROBOT_CHAT_INPUT_CLASS = "assistant-robot-input";
|
80
|
+
const ROBOT_CHAT_BTN_CLASS = "assistant-robot-btn";
|
81
|
+
const ROBOT_CHAT_BOX_HEAD = '<div class="assistant-robot-chartbox';
|
82
|
+
const ROBOT_CHAT_BOX_BODY = `">
|
83
|
+
<style>
|
84
|
+
.assistant-robot-chartbox{
|
85
|
+
width: 100%;
|
86
|
+
display: flex;
|
87
|
+
flex-wrap: wrap;
|
88
|
+
}
|
89
|
+
.assistant-robot-input{
|
90
|
+
flex: 1;
|
91
|
+
min-width: 200px;
|
92
|
+
background: rgba(0,0,0,0);
|
93
|
+
border: 1px solid #aaaaaa;
|
94
|
+
}
|
95
|
+
.assistant-robot-btn{
|
96
|
+
flex: 0 0 auto;
|
97
|
+
}
|
98
|
+
</style>
|
99
|
+
<input class="${ROBOT_CHAT_INPUT_CLASS}" type="text" />
|
100
|
+
<button class="${ROBOT_CHAT_BTN_CLASS}">ask</button>
|
101
|
+
</div>`;
|
102
|
+
const LanguageModelStatus = {
|
103
|
+
loading: 1,
|
104
|
+
ready: 2,
|
105
|
+
error: 3
|
106
|
+
};
|
107
|
+
function isiOS() {
|
108
|
+
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
109
|
+
}
|
110
|
+
function isAndroid() {
|
111
|
+
return /Android/i.test(navigator.userAgent);
|
112
|
+
}
|
113
|
+
function isMobile() {
|
114
|
+
return isAndroid() || isiOS();
|
115
|
+
}
|
116
|
+
function parseHTML(htmlString) {
|
117
|
+
const parser = new DOMParser();
|
118
|
+
const doc = parser.parseFromString(htmlString, "text/html");
|
119
|
+
return doc.body.firstElementChild;
|
120
|
+
}
|
121
|
+
function findHighestScoreItem(data) {
|
122
|
+
if (!Array.isArray(data) || data.length === 0) {
|
123
|
+
return null;
|
124
|
+
}
|
125
|
+
let maxScore = -Infinity;
|
126
|
+
let maxScoreItem = null;
|
127
|
+
for (let i = 0; i < data.length; i++) {
|
128
|
+
const currentItem = data[i];
|
129
|
+
if (currentItem && typeof currentItem.score === "number") {
|
130
|
+
if (currentItem.score > maxScore) {
|
131
|
+
maxScore = currentItem.score;
|
132
|
+
maxScoreItem = currentItem;
|
133
|
+
}
|
134
|
+
}
|
135
|
+
}
|
136
|
+
return maxScoreItem;
|
137
|
+
}
|
138
|
+
exports.ASSISTANT_MODEL_CONTAINER_CLASS = ASSISTANT_MODEL_CONTAINER_CLASS;
|
139
|
+
exports.ASSISTANT_TIP_CONTAINER = ASSISTANT_TIP_CONTAINER;
|
140
|
+
exports.CONTAINER_BODY = CONTAINER_BODY;
|
141
|
+
exports.CONTAINER_HEAD = CONTAINER_HEAD;
|
142
|
+
exports.LanguageModelStatus = LanguageModelStatus;
|
143
|
+
exports.MODEL_CONFIG = MODEL_CONFIG;
|
144
|
+
exports.MODEL_SCENE_CONFIG = MODEL_SCENE_CONFIG;
|
145
|
+
exports.ROBOT_CHAT_BOX_BODY = ROBOT_CHAT_BOX_BODY;
|
146
|
+
exports.ROBOT_CHAT_BOX_HEAD = ROBOT_CHAT_BOX_HEAD;
|
147
|
+
exports.ROBOT_CHAT_BTN_CLASS = ROBOT_CHAT_BTN_CLASS;
|
148
|
+
exports.ROBOT_CHAT_INPUT_CLASS = ROBOT_CHAT_INPUT_CLASS;
|
149
|
+
exports.TARGET_FPS = TARGET_FPS;
|
150
|
+
exports.VIDEO_SIZE = VIDEO_SIZE;
|
151
|
+
exports.findHighestScoreItem = findHighestScoreItem;
|
152
|
+
exports.isMobile = isMobile;
|
153
|
+
exports.parseHTML = parseHTML;
|
@@ -0,0 +1,154 @@
|
|
1
|
+
const TARGET_FPS = 60;
|
2
|
+
const MODEL_CONFIG = {
|
3
|
+
position: [0, 0, 0],
|
4
|
+
rotation: [0, Math.PI, 0]
|
5
|
+
};
|
6
|
+
const MODEL_SCENE_CONFIG = {
|
7
|
+
backgroundColor: 0,
|
8
|
+
backgroundAlpha: 0,
|
9
|
+
camera: {
|
10
|
+
fov: 50,
|
11
|
+
near: 0.1,
|
12
|
+
far: 10,
|
13
|
+
position: [0, 0, 2],
|
14
|
+
lookAt: [0, 0, 0]
|
15
|
+
},
|
16
|
+
ambientLight: {
|
17
|
+
color: 16777215,
|
18
|
+
intensity: 0.5
|
19
|
+
},
|
20
|
+
directionalLight: {
|
21
|
+
color: 16777215,
|
22
|
+
intensity: 2,
|
23
|
+
position: [10, 10, 0]
|
24
|
+
}
|
25
|
+
};
|
26
|
+
const VIDEO_SIZE = {
|
27
|
+
big: { width: 640, height: 480 },
|
28
|
+
small: { width: 360, height: 270 }
|
29
|
+
};
|
30
|
+
const ASSISTANT_MODEL_CONTAINER_CLASS = "assistant-robot-model-container";
|
31
|
+
const ASSISTANT_TIP_CONTAINER = "assistant_tip_container";
|
32
|
+
const CONTAINER_HEAD = `<div class="assistant-robot-container `;
|
33
|
+
const CONTAINER_BODY = `">
|
34
|
+
<style>
|
35
|
+
.assistant-robot-container{
|
36
|
+
width: 100%;
|
37
|
+
height: 100%;
|
38
|
+
display: flex;
|
39
|
+
flex-direction: column;
|
40
|
+
}
|
41
|
+
.${ASSISTANT_MODEL_CONTAINER_CLASS}{
|
42
|
+
flex: 1;
|
43
|
+
position:relative;
|
44
|
+
width:100%;
|
45
|
+
}
|
46
|
+
.${ASSISTANT_TIP_CONTAINER}{
|
47
|
+
position: absolute;
|
48
|
+
top: 2px;
|
49
|
+
left: 50%;
|
50
|
+
min-width: 100px;
|
51
|
+
border: 1px solid #aaaaaa;
|
52
|
+
border-radius: 6px;
|
53
|
+
background: #fff;
|
54
|
+
transform: translate(-50%);
|
55
|
+
padding: 12px 20px;
|
56
|
+
text-align: center;
|
57
|
+
}
|
58
|
+
.${ASSISTANT_TIP_CONTAINER}::after{
|
59
|
+
content: '';
|
60
|
+
display: block;
|
61
|
+
position: absolute;
|
62
|
+
bottom: -6px;
|
63
|
+
left: 50%;
|
64
|
+
width: 8px;
|
65
|
+
height: 8px;
|
66
|
+
transform: rotate(45deg);
|
67
|
+
border-bottom: 1px solid #aaaaaa;
|
68
|
+
border-right: 1px solid #aaaaaa;
|
69
|
+
background: #fff;
|
70
|
+
}
|
71
|
+
</style>
|
72
|
+
<div class="${ASSISTANT_MODEL_CONTAINER_CLASS}">
|
73
|
+
<div class="${ASSISTANT_TIP_CONTAINER}">HI!</div>
|
74
|
+
|
75
|
+
</div>
|
76
|
+
<div>
|
77
|
+
`;
|
78
|
+
const ROBOT_CHAT_INPUT_CLASS = "assistant-robot-input";
|
79
|
+
const ROBOT_CHAT_BTN_CLASS = "assistant-robot-btn";
|
80
|
+
const ROBOT_CHAT_BOX_HEAD = '<div class="assistant-robot-chartbox';
|
81
|
+
const ROBOT_CHAT_BOX_BODY = `">
|
82
|
+
<style>
|
83
|
+
.assistant-robot-chartbox{
|
84
|
+
width: 100%;
|
85
|
+
display: flex;
|
86
|
+
flex-wrap: wrap;
|
87
|
+
}
|
88
|
+
.assistant-robot-input{
|
89
|
+
flex: 1;
|
90
|
+
min-width: 200px;
|
91
|
+
background: rgba(0,0,0,0);
|
92
|
+
border: 1px solid #aaaaaa;
|
93
|
+
}
|
94
|
+
.assistant-robot-btn{
|
95
|
+
flex: 0 0 auto;
|
96
|
+
}
|
97
|
+
</style>
|
98
|
+
<input class="${ROBOT_CHAT_INPUT_CLASS}" type="text" />
|
99
|
+
<button class="${ROBOT_CHAT_BTN_CLASS}">ask</button>
|
100
|
+
</div>`;
|
101
|
+
const LanguageModelStatus = {
|
102
|
+
loading: 1,
|
103
|
+
ready: 2,
|
104
|
+
error: 3
|
105
|
+
};
|
106
|
+
function isiOS() {
|
107
|
+
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
108
|
+
}
|
109
|
+
function isAndroid() {
|
110
|
+
return /Android/i.test(navigator.userAgent);
|
111
|
+
}
|
112
|
+
function isMobile() {
|
113
|
+
return isAndroid() || isiOS();
|
114
|
+
}
|
115
|
+
function parseHTML(htmlString) {
|
116
|
+
const parser = new DOMParser();
|
117
|
+
const doc = parser.parseFromString(htmlString, "text/html");
|
118
|
+
return doc.body.firstElementChild;
|
119
|
+
}
|
120
|
+
function findHighestScoreItem(data) {
|
121
|
+
if (!Array.isArray(data) || data.length === 0) {
|
122
|
+
return null;
|
123
|
+
}
|
124
|
+
let maxScore = -Infinity;
|
125
|
+
let maxScoreItem = null;
|
126
|
+
for (let i = 0; i < data.length; i++) {
|
127
|
+
const currentItem = data[i];
|
128
|
+
if (currentItem && typeof currentItem.score === "number") {
|
129
|
+
if (currentItem.score > maxScore) {
|
130
|
+
maxScore = currentItem.score;
|
131
|
+
maxScoreItem = currentItem;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|
135
|
+
return maxScoreItem;
|
136
|
+
}
|
137
|
+
export {
|
138
|
+
ASSISTANT_TIP_CONTAINER as A,
|
139
|
+
CONTAINER_HEAD as C,
|
140
|
+
LanguageModelStatus as L,
|
141
|
+
MODEL_SCENE_CONFIG as M,
|
142
|
+
ROBOT_CHAT_BOX_HEAD as R,
|
143
|
+
TARGET_FPS as T,
|
144
|
+
VIDEO_SIZE as V,
|
145
|
+
MODEL_CONFIG as a,
|
146
|
+
ROBOT_CHAT_BOX_BODY as b,
|
147
|
+
ROBOT_CHAT_BTN_CLASS as c,
|
148
|
+
ROBOT_CHAT_INPUT_CLASS as d,
|
149
|
+
CONTAINER_BODY as e,
|
150
|
+
ASSISTANT_MODEL_CONTAINER_CLASS as f,
|
151
|
+
findHighestScoreItem as g,
|
152
|
+
isMobile as i,
|
153
|
+
parseHTML as p
|
154
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
{
|
2
|
+
"name": "assistant-robot",
|
3
|
+
"version": "0.0.1-alpha",
|
4
|
+
"description": "An assistant widget, have a 3D robot which can interact with user, have a simple LLM which can chat with user.",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"module": "dist/index.mjs",
|
7
|
+
"exports": {
|
8
|
+
".": {
|
9
|
+
"import": "./dist/index.mjs",
|
10
|
+
"require": "./dist/index.js"
|
11
|
+
},
|
12
|
+
"./languageModels": {
|
13
|
+
"import": "./dist/LanguageModel.mjs",
|
14
|
+
"require": "./dist/LanguageModel.js"
|
15
|
+
}
|
16
|
+
},
|
17
|
+
"dependencies": {
|
18
|
+
"@mediapipe/face_detection": "^0.4.1646425229",
|
19
|
+
"@tensorflow-models/face-detection": "^1.0.2",
|
20
|
+
"@tensorflow-models/qna": "^1.0.2",
|
21
|
+
"three": "^0.158.0"
|
22
|
+
},
|
23
|
+
"devDependencies": {
|
24
|
+
"vite": "^5.0.4"
|
25
|
+
},
|
26
|
+
"scripts": {
|
27
|
+
"dev": "vite example",
|
28
|
+
"build": "vite build --minify=false",
|
29
|
+
"preview": "vite preview"
|
30
|
+
},
|
31
|
+
"keywords": [
|
32
|
+
"assistant",
|
33
|
+
"LLM",
|
34
|
+
"AI",
|
35
|
+
"3D",
|
36
|
+
"bert",
|
37
|
+
"UI"
|
38
|
+
],
|
39
|
+
"author": "ymrdf",
|
40
|
+
"license": "ISC"
|
41
|
+
}
|