Spaces:
Runtime error
Runtime error
JoFrost
commited on
Commit
•
0015338
1
Parent(s):
cd86937
feat: add phi
Browse files- .env +28 -0
- .svelte-kit/ambient.d.ts +2 -2
- .svelte-kit/generated/server/internal.js +2 -2
- .svelte-kit/types/src/routes/proxy+layout.server.ts +2 -2
- src/lib/components/InitModelModal.svelte +16 -0
- src/lib/components/LoadingModal.svelte +66 -13
- src/lib/components/LoadingModalWritable.js +1 -0
- src/lib/components/chat/ChatMessage.svelte +10 -42
- src/lib/server/models.ts +1 -0
- src/routes/+layout.server.ts +1 -0
- src/routes/+layout.svelte +10 -0
- src/routes/LayoutWritable.js +2 -0
- src/routes/LocalDB.ts +3 -0
- src/routes/conversation/[id]/+page.svelte +22 -18
- src/routes/conversation/[id]/phi/m.d.ts +65 -0
- src/routes/conversation/[id]/phi/m.js +476 -0
- src/routes/conversation/[id]/phi/m_bg.wasm +3 -0
- src/routes/conversation/[id]/phi/m_bg.wasm.d.ts +14 -0
- src/routes/conversation/[id]/worker.js +169 -23
.env
CHANGED
@@ -29,6 +29,34 @@ REJECT_UNAUTHORIZED=true
|
|
29 |
|
30 |
# 'name', 'userMessageToken', 'assistantMessageToken' are required
|
31 |
MODELS=`[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
{
|
33 |
"name": "Xenova/LaMini-Flan-T5-783M",
|
34 |
"is_local": true,
|
|
|
29 |
|
30 |
# 'name', 'userMessageToken', 'assistantMessageToken' are required
|
31 |
MODELS=`[
|
32 |
+
{
|
33 |
+
"name": "microsoft/phi-1_5",
|
34 |
+
"is_local": true,
|
35 |
+
"is_phi": true,
|
36 |
+
"type": "text-generation",
|
37 |
+
"userMessageToken": "<|prompter|>",
|
38 |
+
"assistantMessageToken": "<|assistant|>",
|
39 |
+
"messageEndToken": "</s>",
|
40 |
+
"preprompt": "",
|
41 |
+
"promptExamples": [
|
42 |
+
{
|
43 |
+
"title": "What is love?",
|
44 |
+
"prompt": "Describe what love is in a few sentences."
|
45 |
+
},
|
46 |
+
{
|
47 |
+
"title": "What does end-to-end protected mean?",
|
48 |
+
"prompt": "Describe what does end-to-end protected mean in a few sentences."
|
49 |
+
}
|
50 |
+
],
|
51 |
+
"parameters": {
|
52 |
+
"temperature": 0.5,
|
53 |
+
"top_p": 0.95,
|
54 |
+
"repetition_penalty": 1.2,
|
55 |
+
"top_k": 50,
|
56 |
+
"truncate": 1000,
|
57 |
+
"max_new_tokens": 256
|
58 |
+
}
|
59 |
+
},
|
60 |
{
|
61 |
"name": "Xenova/LaMini-Flan-T5-783M",
|
62 |
"is_local": true,
|
.svelte-kit/ambient.d.ts
CHANGED
@@ -64,7 +64,7 @@ declare module '$env/static/private' {
|
|
64 |
export const ComSpec: string;
|
65 |
export const DriverData: string;
|
66 |
export const EDITOR: string;
|
67 |
-
export const
|
68 |
export const EnableLog: string;
|
69 |
export const GIT_ASKPASS: string;
|
70 |
export const HOME: string;
|
@@ -213,7 +213,7 @@ declare module '$env/dynamic/private' {
|
|
213 |
ComSpec: string;
|
214 |
DriverData: string;
|
215 |
EDITOR: string;
|
216 |
-
|
217 |
EnableLog: string;
|
218 |
GIT_ASKPASS: string;
|
219 |
HOME: string;
|
|
|
64 |
export const ComSpec: string;
|
65 |
export const DriverData: string;
|
66 |
export const EDITOR: string;
|
67 |
+
export const EFC_29500: string;
|
68 |
export const EnableLog: string;
|
69 |
export const GIT_ASKPASS: string;
|
70 |
export const HOME: string;
|
|
|
213 |
ComSpec: string;
|
214 |
DriverData: string;
|
215 |
EDITOR: string;
|
216 |
+
EFC_29500: string;
|
217 |
EnableLog: string;
|
218 |
GIT_ASKPASS: string;
|
219 |
HOME: string;
|
.svelte-kit/generated/server/internal.js
CHANGED
@@ -17,10 +17,10 @@ export const options = {
|
|
17 |
root,
|
18 |
service_worker: false,
|
19 |
templates: {
|
20 |
-
app: ({ head, body, assets, nonce, env }) => "<!DOCTYPE html>\r\n<html lang=\"en\" class=\"h-full\">\r\n\t<link rel=\"stylesheet\" href=\"https://www.w3schools.com/w3css/4/w3.css\" />\r\n\t<head>\r\n\t\t<meta charset=\"utf-8\" />\r\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\" />\r\n\t\t<meta property=\"og:image\" content=\"/chatui/thumbnail.jpg\"/>\r\n\t\t<script>\r\n\t\t\tif (\r\n\t\t\t\tlocalStorage.theme === \"dark\" ||\r\n\t\t\t\t(!(\"theme\" in localStorage) && window.matchMedia(\"(prefers-color-scheme: dark)\").matches)\r\n\t\t\t) {\r\n\t\t\t\tdocument.documentElement.classList.add(\"dark\");\r\n\t\t\t}\r\n\t\t</script>\r\n\t\t" + head + "\r\n\t</head>\r\n\t<body data-sveltekit-preload-data=\"hover\" class=\"h-full dark:bg-gray-900\">\r\n\t\t<div id=\"app\" class=\"contents h-full\">" + body + "</div>\r\n\t</body>\r\n</html>\r\n",
|
21 |
error: ({ status, message }) => "<!DOCTYPE html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<title>" + message + "</title>\n\n\t\t<style>\n\t\t\tbody {\n\t\t\t\t--bg: white;\n\t\t\t\t--fg: #222;\n\t\t\t\t--divider: #ccc;\n\t\t\t\tbackground: var(--bg);\n\t\t\t\tcolor: var(--fg);\n\t\t\t\tfont-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,\n\t\t\t\t\tUbuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t.error {\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tmax-width: 32rem;\n\t\t\t\tmargin: 0 1rem;\n\t\t\t}\n\n\t\t\t.status {\n\t\t\t\tfont-weight: 200;\n\t\t\t\tfont-size: 3rem;\n\t\t\t\tline-height: 1;\n\t\t\t\tposition: relative;\n\t\t\t\ttop: -0.05rem;\n\t\t\t}\n\n\t\t\t.message {\n\t\t\t\tborder-left: 1px solid var(--divider);\n\t\t\t\tpadding: 0 0 0 1rem;\n\t\t\t\tmargin: 0 0 0 1rem;\n\t\t\t\tmin-height: 2.5rem;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t}\n\n\t\t\t.message h1 {\n\t\t\t\tfont-weight: 400;\n\t\t\t\tfont-size: 1em;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t@media (prefers-color-scheme: dark) {\n\t\t\t\tbody {\n\t\t\t\t\t--bg: #222;\n\t\t\t\t\t--fg: #ddd;\n\t\t\t\t\t--divider: #666;\n\t\t\t\t}\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<div class=\"error\">\n\t\t\t<span class=\"status\">" + status + "</span>\n\t\t\t<div class=\"message\">\n\t\t\t\t<h1>" + message + "</h1>\n\t\t\t</div>\n\t\t</div>\n\t</body>\n</html>\n"
|
22 |
},
|
23 |
-
version_hash: "
|
24 |
};
|
25 |
|
26 |
export function get_hooks() {
|
|
|
17 |
root,
|
18 |
service_worker: false,
|
19 |
templates: {
|
20 |
+
app: ({ head, body, assets, nonce, env }) => "<!DOCTYPE html>\r\n<html lang=\"en\" class=\"h-full\">\r\n\t<link rel=\"stylesheet\" href=\"https://www.w3schools.com/w3css/4/w3.css\" />\r\n\t<head>\r\n\t\t<!-- Google Tag Manager -->\r\n\t\t<script>\r\n\t\tvar _paq = window._paq || [];\r\n\t\twindow._paq=_paq;\r\n\t\t(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':\r\n\t\tnew Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],\r\n\t\tj=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=\r\n\t\t'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\r\n\t\t})(window,document,'script','dataLayer','GTM-TVD93MF');\r\n\t\t</script>\r\n\t\t<!-- End Google Tag Manager -->\r\n\t\t<meta charset=\"utf-8\" />\r\n\t\t<meta name=\"viewport\" content=\"width=device-width, initial-scale=1, user-scalable=no\" />\r\n\t\t<meta property=\"og:image\" content=\"/chatui/thumbnail.jpg\" />\r\n\t\t<script>\r\n\t\t\tif (\r\n\t\t\t\tlocalStorage.theme === \"dark\" ||\r\n\t\t\t\t(!(\"theme\" in localStorage) && window.matchMedia(\"(prefers-color-scheme: dark)\").matches)\r\n\t\t\t) {\r\n\t\t\t\tdocument.documentElement.classList.add(\"dark\");\r\n\t\t\t}\r\n\t\t</script>\r\n\t\t" + head + "\r\n\t</head>\r\n\t<body data-sveltekit-preload-data=\"hover\" class=\"h-full dark:bg-gray-900\">\r\n\t\t<div id=\"app\" class=\"contents h-full\">" + body + "</div>\r\n\t</body>\r\n</html>\r\n",
|
21 |
error: ({ status, message }) => "<!DOCTYPE html>\n<html lang=\"en\">\n\t<head>\n\t\t<meta charset=\"utf-8\" />\n\t\t<title>" + message + "</title>\n\n\t\t<style>\n\t\t\tbody {\n\t\t\t\t--bg: white;\n\t\t\t\t--fg: #222;\n\t\t\t\t--divider: #ccc;\n\t\t\t\tbackground: var(--bg);\n\t\t\t\tcolor: var(--fg);\n\t\t\t\tfont-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,\n\t\t\t\t\tUbuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tjustify-content: center;\n\t\t\t\theight: 100vh;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t.error {\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t\tmax-width: 32rem;\n\t\t\t\tmargin: 0 1rem;\n\t\t\t}\n\n\t\t\t.status {\n\t\t\t\tfont-weight: 200;\n\t\t\t\tfont-size: 3rem;\n\t\t\t\tline-height: 1;\n\t\t\t\tposition: relative;\n\t\t\t\ttop: -0.05rem;\n\t\t\t}\n\n\t\t\t.message {\n\t\t\t\tborder-left: 1px solid var(--divider);\n\t\t\t\tpadding: 0 0 0 1rem;\n\t\t\t\tmargin: 0 0 0 1rem;\n\t\t\t\tmin-height: 2.5rem;\n\t\t\t\tdisplay: flex;\n\t\t\t\talign-items: center;\n\t\t\t}\n\n\t\t\t.message h1 {\n\t\t\t\tfont-weight: 400;\n\t\t\t\tfont-size: 1em;\n\t\t\t\tmargin: 0;\n\t\t\t}\n\n\t\t\t@media (prefers-color-scheme: dark) {\n\t\t\t\tbody {\n\t\t\t\t\t--bg: #222;\n\t\t\t\t\t--fg: #ddd;\n\t\t\t\t\t--divider: #666;\n\t\t\t\t}\n\t\t\t}\n\t\t</style>\n\t</head>\n\t<body>\n\t\t<div class=\"error\">\n\t\t\t<span class=\"status\">" + status + "</span>\n\t\t\t<div class=\"message\">\n\t\t\t\t<h1>" + message + "</h1>\n\t\t\t</div>\n\t\t</div>\n\t</body>\n</html>\n"
|
22 |
},
|
23 |
+
version_hash: "1iyihr1"
|
24 |
};
|
25 |
|
26 |
export function get_hooks() {
|
.svelte-kit/types/src/routes/proxy+layout.server.ts
CHANGED
@@ -32,8 +32,7 @@ export const load = async ({ locals, depends, url }: Parameters<LayoutServerLoad
|
|
32 |
return {
|
33 |
conversations: [],
|
34 |
settings: {
|
35 |
-
shareConversationsWithModelAuthors:
|
36 |
-
DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
|
37 |
ethicsModalAcceptedAt: null,
|
38 |
activeModel: DEFAULT_SETTINGS.activeModel,
|
39 |
searchEnabled: false,
|
@@ -45,6 +44,7 @@ export const load = async ({ locals, depends, url }: Parameters<LayoutServerLoad
|
|
45 |
websiteUrl: model.websiteUrl,
|
46 |
modelUrl: model.modelUrl,
|
47 |
is_local: model.is_local,
|
|
|
48 |
is_code: model.is_code,
|
49 |
type: model.type,
|
50 |
datasetName: model.datasetName,
|
|
|
32 |
return {
|
33 |
conversations: [],
|
34 |
settings: {
|
35 |
+
shareConversationsWithModelAuthors: DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
|
|
|
36 |
ethicsModalAcceptedAt: null,
|
37 |
activeModel: DEFAULT_SETTINGS.activeModel,
|
38 |
searchEnabled: false,
|
|
|
44 |
websiteUrl: model.websiteUrl,
|
45 |
modelUrl: model.modelUrl,
|
46 |
is_local: model.is_local,
|
47 |
+
is_phi: model.is_phi,
|
48 |
is_code: model.is_code,
|
49 |
type: model.type,
|
50 |
datasetName: model.datasetName,
|
src/lib/components/InitModelModal.svelte
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<script lang="ts">
|
2 |
+
import Modal from "$lib/components/Modal.svelte";
|
3 |
+
</script>
|
4 |
+
|
5 |
+
<Modal>
|
6 |
+
<div class="flex w-full flex-col gap-0 p-2">
|
7 |
+
<div class="flex items-start text-xl font-bold text-gray-800">
|
8 |
+
<h2>Initializing the model...</h2>
|
9 |
+
<br />
|
10 |
+
</div>
|
11 |
+
<div class="text-s flex items-start text-gray-800">
|
12 |
+
<br />The model is preparing the answer for your queries...
|
13 |
+
</div>
|
14 |
+
<br />
|
15 |
+
</div>
|
16 |
+
</Modal>
|
src/lib/components/LoadingModal.svelte
CHANGED
@@ -1,19 +1,44 @@
|
|
1 |
<script lang="ts">
|
2 |
import Modal from "$lib/components/Modal.svelte";
|
3 |
-
import
|
|
|
4 |
|
5 |
const forceUpdate = async (_) => {};
|
6 |
|
7 |
let loadingMap = new Map<string, number>();
|
8 |
let pr = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
map_writable.subscribe((value) => {
|
11 |
const [model, percent] = value;
|
12 |
pr = Number(percent);
|
13 |
-
if (model.startsWith("onnx")) {
|
|
|
14 |
loadingMap.set(model, Math.floor(Number(percent)));
|
15 |
-
//console.log(loadingMap);
|
16 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
});
|
18 |
</script>
|
19 |
|
@@ -21,20 +46,48 @@
|
|
21 |
<div class="flex w-full flex-col gap-0 p-2">
|
22 |
<div class="flex items-start text-xl font-bold text-gray-800">
|
23 |
<h2>Loading the model...</h2>
|
24 |
-
<br />
|
25 |
-
</div>
|
26 |
-
<div class="text-s flex items-start text-gray-800">
|
27 |
-
<br />Please wait while we download the model. This has to be done only once.
|
28 |
</div>
|
29 |
<br />
|
30 |
{#await forceUpdate(pr) then _}
|
31 |
-
{#
|
32 |
-
|
33 |
-
|
34 |
-
<div class="w3-blue" style="width:{value}%">{value}%</div>
|
35 |
-
</div>
|
36 |
<br />
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
{/await}
|
39 |
</div>
|
40 |
</Modal>
|
|
|
1 |
<script lang="ts">
|
2 |
import Modal from "$lib/components/Modal.svelte";
|
3 |
+
import is from "date-fns/locale/is";
|
4 |
+
import { progress_writable, curr_model_writable, map_writable, phi_writable } from "./LoadingModalWritable.js";
|
5 |
|
6 |
const forceUpdate = async (_) => {};
|
7 |
|
8 |
let loadingMap = new Map<string, number>();
|
9 |
let pr = 1;
|
10 |
+
let other_loading = false;
|
11 |
+
let is_phi_loading = false;
|
12 |
+
let is_phi = false;
|
13 |
+
|
14 |
+
phi_writable.subscribe((value) => {
|
15 |
+
is_phi = value;
|
16 |
+
if (value) {
|
17 |
+
other_loading = true;
|
18 |
+
}
|
19 |
+
});
|
20 |
|
21 |
map_writable.subscribe((value) => {
|
22 |
const [model, percent] = value;
|
23 |
pr = Number(percent);
|
24 |
+
if (model != undefined && model.startsWith("onnx")) {
|
25 |
+
is_phi_loading = false;
|
26 |
loadingMap.set(model, Math.floor(Number(percent)));
|
|
|
27 |
}
|
28 |
+
else if (model != undefined && model.startsWith("phi")) {
|
29 |
+
is_phi_loading = true;
|
30 |
+
}
|
31 |
+
if (loadingMap.size > 0)
|
32 |
+
{
|
33 |
+
is_phi_loading = false;
|
34 |
+
other_loading = true;
|
35 |
+
loadingMap.forEach((per, model, map) => {
|
36 |
+
if (per < 100 && loadingMap.size > 0) {
|
37 |
+
other_loading = false;
|
38 |
+
}
|
39 |
+
})
|
40 |
+
}
|
41 |
+
|
42 |
});
|
43 |
</script>
|
44 |
|
|
|
46 |
<div class="flex w-full flex-col gap-0 p-2">
|
47 |
<div class="flex items-start text-xl font-bold text-gray-800">
|
48 |
<h2>Loading the model...</h2>
|
|
|
|
|
|
|
|
|
49 |
</div>
|
50 |
<br />
|
51 |
{#await forceUpdate(pr) then _}
|
52 |
+
{#if other_loading == false}
|
53 |
+
<div class="text-s flex items-start text-gray-800">
|
54 |
+
Please wait while we download the model. This has to be done only once.
|
|
|
|
|
55 |
<br />
|
56 |
+
</div>
|
57 |
+
{#if is_phi_loading == false}
|
58 |
+
<br />
|
59 |
+
{#each [...loadingMap] as [key, value]}
|
60 |
+
<p class="text-s text-gray-800">{key}</p>
|
61 |
+
<div class="w3-light-grey">
|
62 |
+
<div class="w3-blue" style="width:{value}%">{value}%</div>
|
63 |
+
</div>
|
64 |
+
<br />
|
65 |
+
{/each}
|
66 |
+
{:else}
|
67 |
+
<div class="text-left">
|
68 |
+
<div role="status">
|
69 |
+
<svg aria-hidden="true" class="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-gray-600 dark:fill-gray-300" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
70 |
+
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
|
71 |
+
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
|
72 |
+
</svg>
|
73 |
+
<span class="sr-only">Loading...</span>
|
74 |
+
</div>
|
75 |
+
</div>
|
76 |
+
{/if}
|
77 |
+
{:else}
|
78 |
+
<div class="text-s flex items-start text-gray-800">
|
79 |
+
Loading the model into memory...
|
80 |
+
</div>
|
81 |
+
<div class="text-left">
|
82 |
+
<div role="status">
|
83 |
+
<svg aria-hidden="true" class="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-gray-600 dark:fill-gray-300" viewBox="0 0 100 101" fill="none" xmlns="http://www.w3.org/2000/svg">
|
84 |
+
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentColor"/>
|
85 |
+
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentFill"/>
|
86 |
+
</svg>
|
87 |
+
<span class="sr-only">Loading...</span>
|
88 |
+
</div>
|
89 |
+
</div>
|
90 |
+
{/if}
|
91 |
{/await}
|
92 |
</div>
|
93 |
</Modal>
|
src/lib/components/LoadingModalWritable.js
CHANGED
@@ -3,3 +3,4 @@ import { writable } from "svelte/store";
|
|
3 |
export const progress_writable = writable(0);
|
4 |
export const curr_model_writable = writable("");
|
5 |
export const map_writable = writable(["", ""]);
|
|
|
|
3 |
export const progress_writable = writable(0);
|
4 |
export const curr_model_writable = writable("");
|
5 |
export const map_writable = writable(["", ""]);
|
6 |
+
export const phi_writable = writable(false);
|
src/lib/components/chat/ChatMessage.svelte
CHANGED
@@ -83,16 +83,16 @@
|
|
83 |
clearTimeout(pendingTimeout);
|
84 |
|
85 |
// Add loading animation to the last message if update takes more than 600ms
|
86 |
-
if (loading) {
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
}
|
96 |
});
|
97 |
|
98 |
$: downloadLink =
|
@@ -142,38 +142,6 @@
|
|
142 |
{/if}
|
143 |
</div>
|
144 |
</div>
|
145 |
-
<!-- {#if isAuthor && !loading && message.content}
|
146 |
-
<div
|
147 |
-
class="absolute bottom-1 right-0 flex max-md:transition-all md:bottom-0 md:group-hover:visible md:group-hover:opacity-100
|
148 |
-
{message.score ? 'visible opacity-100' : 'invisible max-md:-translate-y-4 max-md:opacity-0'}
|
149 |
-
{isTapped ? 'max-md:visible max-md:translate-y-0 max-md:opacity-100' : ''}
|
150 |
-
"
|
151 |
-
>
|
152 |
-
<button
|
153 |
-
class="btn rounded-sm p-1 text-sm text-gray-400 focus:ring-0 hover:text-gray-500 dark:text-gray-400 dark:hover:text-gray-300
|
154 |
-
{message.score && message.score > 0
|
155 |
-
? 'text-green-500 hover:text-green-500 dark:text-green-400 hover:dark:text-green-400'
|
156 |
-
: ''}"
|
157 |
-
title={message.score === 1 ? "Remove +1" : "+1"}
|
158 |
-
type="button"
|
159 |
-
on:click={() => dispatch("vote", { score: message.score === 1 ? 0 : 1, id: message.id })}
|
160 |
-
>
|
161 |
-
<CarbonThumbsUp class="h-[1.14em] w-[1.14em]" />
|
162 |
-
</button>
|
163 |
-
<button
|
164 |
-
class="btn rounded-sm p-1 text-sm text-gray-400 focus:ring-0 hover:text-gray-500 dark:text-gray-400 dark:hover:text-gray-300
|
165 |
-
{message.score && message.score < 0
|
166 |
-
? 'text-red-500 hover:text-red-500 dark:text-red-400 hover:dark:text-red-400'
|
167 |
-
: ''}"
|
168 |
-
title={message.score === -1 ? "Remove -1" : "-1"}
|
169 |
-
type="button"
|
170 |
-
on:click={() =>
|
171 |
-
dispatch("vote", { score: message.score === -1 ? 0 : -1, id: message.id })}
|
172 |
-
>
|
173 |
-
<CarbonThumbsDown class="h-[1.14em] w-[1.14em]" />
|
174 |
-
</button>
|
175 |
-
</div>
|
176 |
-
{/if} -->
|
177 |
</div>
|
178 |
{/if}
|
179 |
{#if message.from === "user"}
|
|
|
83 |
clearTimeout(pendingTimeout);
|
84 |
|
85 |
// Add loading animation to the last message if update takes more than 600ms
|
86 |
+
// if (loading) {
|
87 |
+
// pendingTimeout = setTimeout(() => {
|
88 |
+
// if (contentEl) {
|
89 |
+
// loadingEl = new IconLoading({
|
90 |
+
// target: deepestChild(contentEl),
|
91 |
+
// props: { classNames: "loading inline ml-2" },
|
92 |
+
// });
|
93 |
+
// }
|
94 |
+
// }, 600);
|
95 |
+
// }
|
96 |
});
|
97 |
|
98 |
$: downloadLink =
|
|
|
142 |
{/if}
|
143 |
</div>
|
144 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
</div>
|
146 |
{/if}
|
147 |
{#if message.from === "user"}
|
src/lib/server/models.ts
CHANGED
@@ -65,6 +65,7 @@ const modelsRaw = z
|
|
65 |
description: z.string().min(1).optional(),
|
66 |
is_local: z.boolean().optional(),
|
67 |
is_code: z.boolean().optional(),
|
|
|
68 |
type: z.string().min(1),
|
69 |
websiteUrl: z.string().url().optional(),
|
70 |
modelUrl: z.string().url().optional(),
|
|
|
65 |
description: z.string().min(1).optional(),
|
66 |
is_local: z.boolean().optional(),
|
67 |
is_code: z.boolean().optional(),
|
68 |
+
is_phi: z.boolean().optional(),
|
69 |
type: z.string().min(1),
|
70 |
websiteUrl: z.string().url().optional(),
|
71 |
modelUrl: z.string().url().optional(),
|
src/routes/+layout.server.ts
CHANGED
@@ -43,6 +43,7 @@ export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
|
|
43 |
websiteUrl: model.websiteUrl,
|
44 |
modelUrl: model.modelUrl,
|
45 |
is_local: model.is_local,
|
|
|
46 |
is_code: model.is_code,
|
47 |
type: model.type,
|
48 |
datasetName: model.datasetName,
|
|
|
43 |
websiteUrl: model.websiteUrl,
|
44 |
modelUrl: model.modelUrl,
|
45 |
is_local: model.is_local,
|
46 |
+
is_phi: model.is_phi,
|
47 |
is_code: model.is_code,
|
48 |
type: model.type,
|
49 |
datasetName: model.datasetName,
|
src/routes/+layout.svelte
CHANGED
@@ -21,6 +21,7 @@
|
|
21 |
import { PUBLIC_APP_ASSETS, PUBLIC_APP_NAME } from "$env/static/public";
|
22 |
import {
|
23 |
isloading_writable,
|
|
|
24 |
refresh_chats_writable,
|
25 |
refresh_chats_writable_empty,
|
26 |
} from "./LayoutWritable";
|
@@ -32,15 +33,21 @@
|
|
32 |
modifyTitle,
|
33 |
} from "../routes/LocalDB";
|
34 |
import { env } from "$env/dynamic/public";
|
|
|
35 |
|
36 |
export let data;
|
37 |
let isloading = false;
|
|
|
38 |
let showWarning = true;
|
39 |
|
40 |
let go_to_main = false;
|
41 |
|
42 |
let conversations_list = [];
|
43 |
|
|
|
|
|
|
|
|
|
44 |
isloading_writable.subscribe((value) => {
|
45 |
isloading = value;
|
46 |
});
|
@@ -205,6 +212,9 @@
|
|
205 |
{#if showWarning}
|
206 |
<ConfirmModal on:close={() => (showWarning = false)} />
|
207 |
{/if}
|
|
|
|
|
|
|
208 |
{#if isloading}
|
209 |
<LoadingModal />
|
210 |
{/if}
|
|
|
21 |
import { PUBLIC_APP_ASSETS, PUBLIC_APP_NAME } from "$env/static/public";
|
22 |
import {
|
23 |
isloading_writable,
|
24 |
+
is_init_writable,
|
25 |
refresh_chats_writable,
|
26 |
refresh_chats_writable_empty,
|
27 |
} from "./LayoutWritable";
|
|
|
33 |
modifyTitle,
|
34 |
} from "../routes/LocalDB";
|
35 |
import { env } from "$env/dynamic/public";
|
36 |
+
import InitModelModal from "$lib/components/InitModelModal.svelte";
|
37 |
|
38 |
export let data;
|
39 |
let isloading = false;
|
40 |
+
let isInit = false;
|
41 |
let showWarning = true;
|
42 |
|
43 |
let go_to_main = false;
|
44 |
|
45 |
let conversations_list = [];
|
46 |
|
47 |
+
is_init_writable.subscribe((value) => {
|
48 |
+
isInit = value;
|
49 |
+
});
|
50 |
+
|
51 |
isloading_writable.subscribe((value) => {
|
52 |
isloading = value;
|
53 |
});
|
|
|
212 |
{#if showWarning}
|
213 |
<ConfirmModal on:close={() => (showWarning = false)} />
|
214 |
{/if}
|
215 |
+
{#if isInit}
|
216 |
+
<InitModelModal />
|
217 |
+
{/if}
|
218 |
{#if isloading}
|
219 |
<LoadingModal />
|
220 |
{/if}
|
src/routes/LayoutWritable.js
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import { writable } from "svelte/store";
|
2 |
|
3 |
export const isloading_writable = writable(false);
|
|
|
|
|
4 |
export const refresh_chats_writable = writable([]);
|
5 |
export const refresh_chats_writable_empty = writable(false);
|
6 |
export const curr_model_writable = writable(0);
|
|
|
1 |
import { writable } from "svelte/store";
|
2 |
|
3 |
export const isloading_writable = writable(false);
|
4 |
+
export const is_init_writable = writable(false);
|
5 |
+
export const cancel_writable = writable(false);
|
6 |
export const refresh_chats_writable = writable([]);
|
7 |
export const refresh_chats_writable_empty = writable(false);
|
8 |
export const curr_model_writable = writable(0);
|
src/routes/LocalDB.ts
CHANGED
@@ -28,6 +28,9 @@ export class ChatDatabase extends Dexie {
|
|
28 |
chats: null,
|
29 |
});
|
30 |
this.version(17).stores({
|
|
|
|
|
|
|
31 |
chats: "++index, title, createdAt, id, message, model",
|
32 |
});
|
33 |
}
|
|
|
28 |
chats: null,
|
29 |
});
|
30 |
this.version(17).stores({
|
31 |
+
chats: null,
|
32 |
+
});
|
33 |
+
this.version(18).stores({
|
34 |
chats: "++index, title, createdAt, id, message, model",
|
35 |
});
|
36 |
}
|
src/routes/conversation/[id]/+page.svelte
CHANGED
@@ -16,8 +16,8 @@
|
|
16 |
import type { Message } from "$lib/types/Message";
|
17 |
import { PUBLIC_APP_DISCLAIMER } from "$env/static/public";
|
18 |
import { pipeline, Pipeline, env as env_transformers } from "@xenova/transformers";
|
19 |
-
import { isloading_writable, curr_model_writable } from "../../LayoutWritable.js";
|
20 |
-
import { map_writable } from "$lib/components/LoadingModalWritable.js";
|
21 |
import { params_writable } from "./ParamsWritable.js";
|
22 |
import { addMessageToChat, getChats, getMessages, getTitle, getModel } from "../../LocalDB.js";
|
23 |
import { env } from "$env/dynamic/public";
|
@@ -48,18 +48,13 @@
|
|
48 |
|
49 |
let webSearchMessages: WebSearchMessage[] = [];
|
50 |
|
51 |
-
// // Since we modify the messages array locally, we don't want to reset it if an old version is passed
|
52 |
-
// $: if (data.messages !== lastLoadedMessages) {
|
53 |
-
// messages = data.messages;
|
54 |
-
// lastLoadedMessages = data.messages;
|
55 |
-
// }
|
56 |
-
|
57 |
let loading = false;
|
58 |
let pending = false;
|
59 |
let loginRequired = false;
|
60 |
|
61 |
// Create a callback function for messages from the worker thread.
|
62 |
const onMessageReceived = (e) => {
|
|
|
63 |
let lastMessage: any = undefined;
|
64 |
switch (e.data.status) {
|
65 |
case "initiate":
|
@@ -67,7 +62,16 @@
|
|
67 |
|
68 |
case "progress":
|
69 |
isloading_writable.set(true);
|
70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
break;
|
72 |
|
73 |
case "done":
|
@@ -75,6 +79,8 @@
|
|
75 |
|
76 |
case "ready":
|
77 |
isloading_writable.set(false);
|
|
|
|
|
78 |
break;
|
79 |
|
80 |
case "update":
|
@@ -85,8 +91,12 @@
|
|
85 |
lastMessage.updatedAt = new Date();
|
86 |
messages = [...messages];
|
87 |
}
|
|
|
|
|
|
|
88 |
break;
|
89 |
|
|
|
90 |
case "complete":
|
91 |
if (e.data.id_now == id_now) {
|
92 |
lastMessage = messages[messages.length - 1];
|
@@ -120,8 +130,6 @@
|
|
120 |
|
121 |
let opt = "";
|
122 |
|
123 |
-
console.log(curr_model_obj);
|
124 |
-
|
125 |
messages = [
|
126 |
...messages,
|
127 |
// id doesn't match the backend id but it's not important for assistant messages
|
@@ -148,6 +156,7 @@
|
|
148 |
|
149 |
let lastMessage = messages[messages.length - 1];
|
150 |
pipelineWorker.postMessage({
|
|
|
151 |
id_now: id_now,
|
152 |
task: curr_model_obj.type,
|
153 |
max_new_tokens: curr_model_obj.parameters?.max_new_tokens ?? 256,
|
@@ -251,7 +260,7 @@
|
|
251 |
}
|
252 |
console.error(err);
|
253 |
} finally {
|
254 |
-
loading = false;
|
255 |
pending = false;
|
256 |
}
|
257 |
}
|
@@ -298,15 +307,10 @@
|
|
298 |
} else {
|
299 |
curr_model_obj = findCurrentModel([...data.models, ...data.oldModels], curr_model);
|
300 |
}
|
301 |
-
|
302 |
-
console.log(curr_model);
|
303 |
-
console.log(curr_model_obj);
|
304 |
-
|
305 |
if (res != undefined) {
|
306 |
messages = res;
|
307 |
lastLoadedMessages = res;
|
308 |
}
|
309 |
-
|
310 |
id_now = randomUUID();
|
311 |
}
|
312 |
});
|
@@ -373,7 +377,7 @@
|
|
373 |
on:retry={(event) => writeMessage(event.detail.content, event.detail.id)}
|
374 |
on:vote={(event) => voteMessage(event.detail.score, event.detail.id)}
|
375 |
on:share={() => shareConversation($page.params.id, data.title)}
|
376 |
-
on:stop={() => (isAborted = true)}
|
377 |
models={data.models}
|
378 |
currentModel={findCurrentModel([...data.models, ...data.oldModels], curr_model)}
|
379 |
settings={data.settings}
|
|
|
16 |
import type { Message } from "$lib/types/Message";
|
17 |
import { PUBLIC_APP_DISCLAIMER } from "$env/static/public";
|
18 |
import { pipeline, Pipeline, env as env_transformers } from "@xenova/transformers";
|
19 |
+
import { isloading_writable, curr_model_writable, is_init_writable, cancel_writable } from "../../LayoutWritable.js";
|
20 |
+
import { map_writable, phi_writable } from "$lib/components/LoadingModalWritable.js";
|
21 |
import { params_writable } from "./ParamsWritable.js";
|
22 |
import { addMessageToChat, getChats, getMessages, getTitle, getModel } from "../../LocalDB.js";
|
23 |
import { env } from "$env/dynamic/public";
|
|
|
48 |
|
49 |
let webSearchMessages: WebSearchMessage[] = [];
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
let loading = false;
|
52 |
let pending = false;
|
53 |
let loginRequired = false;
|
54 |
|
55 |
// Create a callback function for messages from the worker thread.
|
56 |
const onMessageReceived = (e) => {
|
57 |
+
console.log(e)
|
58 |
let lastMessage: any = undefined;
|
59 |
switch (e.data.status) {
|
60 |
case "initiate":
|
|
|
62 |
|
63 |
case "progress":
|
64 |
isloading_writable.set(true);
|
65 |
+
if (e.data.no_progress_bar == undefined || e.data.no_progress_bar == false) {
|
66 |
+
map_writable.set([e.data.file, e.data.progress]);
|
67 |
+
}
|
68 |
+
else {
|
69 |
+
map_writable.set(["phi", "-1"])
|
70 |
+
}
|
71 |
+
break;
|
72 |
+
|
73 |
+
case "init_model":
|
74 |
+
phi_writable.set(true);
|
75 |
break;
|
76 |
|
77 |
case "done":
|
|
|
79 |
|
80 |
case "ready":
|
81 |
isloading_writable.set(false);
|
82 |
+
is_init_writable.set(false);
|
83 |
+
phi_writable.set(false);
|
84 |
break;
|
85 |
|
86 |
case "update":
|
|
|
91 |
lastMessage.updatedAt = new Date();
|
92 |
messages = [...messages];
|
93 |
}
|
94 |
+
else {
|
95 |
+
pipelineWorker.postMessage({ command: "abort" })
|
96 |
+
}
|
97 |
break;
|
98 |
|
99 |
+
case "aborted":
|
100 |
case "complete":
|
101 |
if (e.data.id_now == id_now) {
|
102 |
lastMessage = messages[messages.length - 1];
|
|
|
130 |
|
131 |
let opt = "";
|
132 |
|
|
|
|
|
133 |
messages = [
|
134 |
...messages,
|
135 |
// id doesn't match the backend id but it's not important for assistant messages
|
|
|
156 |
|
157 |
let lastMessage = messages[messages.length - 1];
|
158 |
pipelineWorker.postMessage({
|
159 |
+
is_phi: curr_model_obj.is_phi ?? false,
|
160 |
id_now: id_now,
|
161 |
task: curr_model_obj.type,
|
162 |
max_new_tokens: curr_model_obj.parameters?.max_new_tokens ?? 256,
|
|
|
260 |
}
|
261 |
console.error(err);
|
262 |
} finally {
|
263 |
+
loading = curr_model_obj.is_phi ?? false;
|
264 |
pending = false;
|
265 |
}
|
266 |
}
|
|
|
307 |
} else {
|
308 |
curr_model_obj = findCurrentModel([...data.models, ...data.oldModels], curr_model);
|
309 |
}
|
|
|
|
|
|
|
|
|
310 |
if (res != undefined) {
|
311 |
messages = res;
|
312 |
lastLoadedMessages = res;
|
313 |
}
|
|
|
314 |
id_now = randomUUID();
|
315 |
}
|
316 |
});
|
|
|
377 |
on:retry={(event) => writeMessage(event.detail.content, event.detail.id)}
|
378 |
on:vote={(event) => voteMessage(event.detail.score, event.detail.id)}
|
379 |
on:share={() => shareConversation($page.params.id, data.title)}
|
380 |
+
on:stop={() => (isAborted = true, pipelineWorker.postMessage({ command: "abort" }))}
|
381 |
models={data.models}
|
382 |
currentModel={findCurrentModel([...data.models, ...data.oldModels], curr_model)}
|
383 |
settings={data.settings}
|
src/routes/conversation/[id]/phi/m.d.ts
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* tslint:disable */
|
2 |
+
/* eslint-disable */
|
3 |
+
/**
|
4 |
+
*/
|
5 |
+
export class Model {
|
6 |
+
free(): void;
|
7 |
+
/**
|
8 |
+
* @param {Uint8Array} weights
|
9 |
+
* @param {Uint8Array} tokenizer
|
10 |
+
* @param {boolean} quantized
|
11 |
+
*/
|
12 |
+
constructor(weights: Uint8Array, tokenizer: Uint8Array, quantized: boolean);
|
13 |
+
/**
|
14 |
+
* @param {string} prompt
|
15 |
+
* @param {number} temp
|
16 |
+
* @param {number} top_p
|
17 |
+
* @param {number} repeat_penalty
|
18 |
+
* @param {number} repeat_last_n
|
19 |
+
* @param {bigint} seed
|
20 |
+
* @returns {string}
|
21 |
+
*/
|
22 |
+
init_with_prompt(prompt: string, temp: number, top_p: number, repeat_penalty: number, repeat_last_n: number, seed: bigint): string;
|
23 |
+
/**
|
24 |
+
* @returns {string}
|
25 |
+
*/
|
26 |
+
next_token(): string;
|
27 |
+
}
|
28 |
+
|
29 |
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
30 |
+
|
31 |
+
export interface InitOutput {
|
32 |
+
readonly memory: WebAssembly.Memory;
|
33 |
+
readonly __wbg_model_free: (a: number) => void;
|
34 |
+
readonly model_load: (a: number, b: number, c: number, d: number, e: number, f: number) => void;
|
35 |
+
readonly model_init_with_prompt: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
36 |
+
readonly model_next_token: (a: number, b: number) => void;
|
37 |
+
readonly main: (a: number, b: number) => number;
|
38 |
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
39 |
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
40 |
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
41 |
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
42 |
+
readonly __wbindgen_exn_store: (a: number) => void;
|
43 |
+
readonly __wbindgen_start: () => void;
|
44 |
+
}
|
45 |
+
|
46 |
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
47 |
+
/**
|
48 |
+
* Instantiates the given `module`, which can either be bytes or
|
49 |
+
* a precompiled `WebAssembly.Module`.
|
50 |
+
*
|
51 |
+
* @param {SyncInitInput} module
|
52 |
+
*
|
53 |
+
* @returns {InitOutput}
|
54 |
+
*/
|
55 |
+
export function initSync(module: SyncInitInput): InitOutput;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
59 |
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
60 |
+
*
|
61 |
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
62 |
+
*
|
63 |
+
* @returns {Promise<InitOutput>}
|
64 |
+
*/
|
65 |
+
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
src/routes/conversation/[id]/phi/m.js
ADDED
@@ -0,0 +1,476 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
let wasm;
|
2 |
+
|
3 |
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
4 |
+
|
5 |
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
6 |
+
|
7 |
+
let cachedUint8Memory0 = null;
|
8 |
+
|
9 |
+
function getUint8Memory0() {
|
10 |
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
11 |
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
12 |
+
}
|
13 |
+
return cachedUint8Memory0;
|
14 |
+
}
|
15 |
+
|
16 |
+
function getStringFromWasm0(ptr, len) {
|
17 |
+
ptr = ptr >>> 0;
|
18 |
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
19 |
+
}
|
20 |
+
|
21 |
+
const heap = new Array(128).fill(undefined);
|
22 |
+
|
23 |
+
heap.push(undefined, null, true, false);
|
24 |
+
|
25 |
+
let heap_next = heap.length;
|
26 |
+
|
27 |
+
function addHeapObject(obj) {
|
28 |
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
29 |
+
const idx = heap_next;
|
30 |
+
heap_next = heap[idx];
|
31 |
+
|
32 |
+
heap[idx] = obj;
|
33 |
+
return idx;
|
34 |
+
}
|
35 |
+
|
36 |
+
function getObject(idx) { return heap[idx]; }
|
37 |
+
|
38 |
+
function dropObject(idx) {
|
39 |
+
if (idx < 132) return;
|
40 |
+
heap[idx] = heap_next;
|
41 |
+
heap_next = idx;
|
42 |
+
}
|
43 |
+
|
44 |
+
function takeObject(idx) {
|
45 |
+
const ret = getObject(idx);
|
46 |
+
dropObject(idx);
|
47 |
+
return ret;
|
48 |
+
}
|
49 |
+
|
50 |
+
let WASM_VECTOR_LEN = 0;
|
51 |
+
|
52 |
+
function passArray8ToWasm0(arg, malloc) {
|
53 |
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
54 |
+
getUint8Memory0().set(arg, ptr / 1);
|
55 |
+
WASM_VECTOR_LEN = arg.length;
|
56 |
+
return ptr;
|
57 |
+
}
|
58 |
+
|
59 |
+
let cachedInt32Memory0 = null;
|
60 |
+
|
61 |
+
function getInt32Memory0() {
|
62 |
+
if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
|
63 |
+
cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
64 |
+
}
|
65 |
+
return cachedInt32Memory0;
|
66 |
+
}
|
67 |
+
|
68 |
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
69 |
+
|
70 |
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
71 |
+
? function (arg, view) {
|
72 |
+
return cachedTextEncoder.encodeInto(arg, view);
|
73 |
+
}
|
74 |
+
: function (arg, view) {
|
75 |
+
const buf = cachedTextEncoder.encode(arg);
|
76 |
+
view.set(buf);
|
77 |
+
return {
|
78 |
+
read: arg.length,
|
79 |
+
written: buf.length
|
80 |
+
};
|
81 |
+
});
|
82 |
+
|
83 |
+
function passStringToWasm0(arg, malloc, realloc) {
|
84 |
+
|
85 |
+
if (realloc === undefined) {
|
86 |
+
const buf = cachedTextEncoder.encode(arg);
|
87 |
+
const ptr = malloc(buf.length, 1) >>> 0;
|
88 |
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
89 |
+
WASM_VECTOR_LEN = buf.length;
|
90 |
+
return ptr;
|
91 |
+
}
|
92 |
+
|
93 |
+
let len = arg.length;
|
94 |
+
let ptr = malloc(len, 1) >>> 0;
|
95 |
+
|
96 |
+
const mem = getUint8Memory0();
|
97 |
+
|
98 |
+
let offset = 0;
|
99 |
+
|
100 |
+
for (; offset < len; offset++) {
|
101 |
+
const code = arg.charCodeAt(offset);
|
102 |
+
if (code > 0x7F) break;
|
103 |
+
mem[ptr + offset] = code;
|
104 |
+
}
|
105 |
+
|
106 |
+
if (offset !== len) {
|
107 |
+
if (offset !== 0) {
|
108 |
+
arg = arg.slice(offset);
|
109 |
+
}
|
110 |
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
111 |
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
112 |
+
const ret = encodeString(arg, view);
|
113 |
+
|
114 |
+
offset += ret.written;
|
115 |
+
}
|
116 |
+
|
117 |
+
WASM_VECTOR_LEN = offset;
|
118 |
+
return ptr;
|
119 |
+
}
|
120 |
+
|
121 |
+
function handleError(f, args) {
|
122 |
+
try {
|
123 |
+
return f.apply(this, args);
|
124 |
+
} catch (e) {
|
125 |
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
126 |
+
}
|
127 |
+
}
|
128 |
+
/**
|
129 |
+
*/
|
130 |
+
export class Model {
|
131 |
+
|
132 |
+
static __wrap(ptr) {
|
133 |
+
ptr = ptr >>> 0;
|
134 |
+
const obj = Object.create(Model.prototype);
|
135 |
+
obj.__wbg_ptr = ptr;
|
136 |
+
|
137 |
+
return obj;
|
138 |
+
}
|
139 |
+
|
140 |
+
__destroy_into_raw() {
|
141 |
+
const ptr = this.__wbg_ptr;
|
142 |
+
this.__wbg_ptr = 0;
|
143 |
+
|
144 |
+
return ptr;
|
145 |
+
}
|
146 |
+
|
147 |
+
free() {
|
148 |
+
const ptr = this.__destroy_into_raw();
|
149 |
+
wasm.__wbg_model_free(ptr);
|
150 |
+
}
|
151 |
+
/**
|
152 |
+
* @param {Uint8Array} weights
|
153 |
+
* @param {Uint8Array} tokenizer
|
154 |
+
* @param {boolean} quantized
|
155 |
+
*/
|
156 |
+
constructor(weights, tokenizer, quantized) {
|
157 |
+
try {
|
158 |
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
159 |
+
const ptr0 = passArray8ToWasm0(weights, wasm.__wbindgen_malloc);
|
160 |
+
const len0 = WASM_VECTOR_LEN;
|
161 |
+
const ptr1 = passArray8ToWasm0(tokenizer, wasm.__wbindgen_malloc);
|
162 |
+
const len1 = WASM_VECTOR_LEN;
|
163 |
+
wasm.model_load(retptr, ptr0, len0, ptr1, len1, quantized);
|
164 |
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
165 |
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
166 |
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
167 |
+
if (r2) {
|
168 |
+
throw takeObject(r1);
|
169 |
+
}
|
170 |
+
return Model.__wrap(r0);
|
171 |
+
} finally {
|
172 |
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
173 |
+
}
|
174 |
+
}
|
175 |
+
/**
|
176 |
+
* @param {string} prompt
|
177 |
+
* @param {number} temp
|
178 |
+
* @param {number} top_p
|
179 |
+
* @param {number} repeat_penalty
|
180 |
+
* @param {number} repeat_last_n
|
181 |
+
* @param {bigint} seed
|
182 |
+
* @returns {string}
|
183 |
+
*/
|
184 |
+
init_with_prompt(prompt, temp, top_p, repeat_penalty, repeat_last_n, seed) {
|
185 |
+
let deferred3_0;
|
186 |
+
let deferred3_1;
|
187 |
+
try {
|
188 |
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
189 |
+
const ptr0 = passStringToWasm0(prompt, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
190 |
+
const len0 = WASM_VECTOR_LEN;
|
191 |
+
wasm.model_init_with_prompt(retptr, this.__wbg_ptr, ptr0, len0, temp, top_p, repeat_penalty, repeat_last_n, seed);
|
192 |
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
193 |
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
194 |
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
195 |
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
196 |
+
var ptr2 = r0;
|
197 |
+
var len2 = r1;
|
198 |
+
if (r3) {
|
199 |
+
ptr2 = 0; len2 = 0;
|
200 |
+
throw takeObject(r2);
|
201 |
+
}
|
202 |
+
deferred3_0 = ptr2;
|
203 |
+
deferred3_1 = len2;
|
204 |
+
return getStringFromWasm0(ptr2, len2);
|
205 |
+
} finally {
|
206 |
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
207 |
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
208 |
+
}
|
209 |
+
}
|
210 |
+
/**
|
211 |
+
* @returns {string}
|
212 |
+
*/
|
213 |
+
next_token() {
|
214 |
+
let deferred2_0;
|
215 |
+
let deferred2_1;
|
216 |
+
try {
|
217 |
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
218 |
+
wasm.model_next_token(retptr, this.__wbg_ptr);
|
219 |
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
220 |
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
221 |
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
222 |
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
223 |
+
var ptr1 = r0;
|
224 |
+
var len1 = r1;
|
225 |
+
if (r3) {
|
226 |
+
ptr1 = 0; len1 = 0;
|
227 |
+
throw takeObject(r2);
|
228 |
+
}
|
229 |
+
deferred2_0 = ptr1;
|
230 |
+
deferred2_1 = len1;
|
231 |
+
return getStringFromWasm0(ptr1, len1);
|
232 |
+
} finally {
|
233 |
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
234 |
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
235 |
+
}
|
236 |
+
}
|
237 |
+
}
|
238 |
+
|
239 |
+
async function __wbg_load(module, imports) {
|
240 |
+
if (typeof Response === 'function' && module instanceof Response) {
|
241 |
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
242 |
+
try {
|
243 |
+
return await WebAssembly.instantiateStreaming(module, imports);
|
244 |
+
|
245 |
+
} catch (e) {
|
246 |
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
247 |
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
248 |
+
|
249 |
+
} else {
|
250 |
+
throw e;
|
251 |
+
}
|
252 |
+
}
|
253 |
+
}
|
254 |
+
|
255 |
+
const bytes = await module.arrayBuffer();
|
256 |
+
return await WebAssembly.instantiate(bytes, imports);
|
257 |
+
|
258 |
+
} else {
|
259 |
+
const instance = await WebAssembly.instantiate(module, imports);
|
260 |
+
|
261 |
+
if (instance instanceof WebAssembly.Instance) {
|
262 |
+
return { instance, module };
|
263 |
+
|
264 |
+
} else {
|
265 |
+
return instance;
|
266 |
+
}
|
267 |
+
}
|
268 |
+
}
|
269 |
+
|
270 |
+
function __wbg_get_imports() {
|
271 |
+
const imports = {};
|
272 |
+
imports.wbg = {};
|
273 |
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
274 |
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
275 |
+
return addHeapObject(ret);
|
276 |
+
};
|
277 |
+
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
278 |
+
const ret = new Error();
|
279 |
+
return addHeapObject(ret);
|
280 |
+
};
|
281 |
+
imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
|
282 |
+
const ret = getObject(arg1).stack;
|
283 |
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
284 |
+
const len1 = WASM_VECTOR_LEN;
|
285 |
+
getInt32Memory0()[arg0 / 4 + 1] = len1;
|
286 |
+
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
|
287 |
+
};
|
288 |
+
imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
|
289 |
+
let deferred0_0;
|
290 |
+
let deferred0_1;
|
291 |
+
try {
|
292 |
+
deferred0_0 = arg0;
|
293 |
+
deferred0_1 = arg1;
|
294 |
+
console.error(getStringFromWasm0(arg0, arg1));
|
295 |
+
} finally {
|
296 |
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
297 |
+
}
|
298 |
+
};
|
299 |
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
300 |
+
takeObject(arg0);
|
301 |
+
};
|
302 |
+
imports.wbg.__wbg_log_ff7e0b5e6573cdff = function(arg0, arg1) {
|
303 |
+
console.log(getStringFromWasm0(arg0, arg1));
|
304 |
+
};
|
305 |
+
imports.wbg.__wbg_crypto_c48a774b022d20ac = function(arg0) {
|
306 |
+
const ret = getObject(arg0).crypto;
|
307 |
+
return addHeapObject(ret);
|
308 |
+
};
|
309 |
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
310 |
+
const val = getObject(arg0);
|
311 |
+
const ret = typeof(val) === 'object' && val !== null;
|
312 |
+
return ret;
|
313 |
+
};
|
314 |
+
imports.wbg.__wbg_process_298734cf255a885d = function(arg0) {
|
315 |
+
const ret = getObject(arg0).process;
|
316 |
+
return addHeapObject(ret);
|
317 |
+
};
|
318 |
+
imports.wbg.__wbg_versions_e2e78e134e3e5d01 = function(arg0) {
|
319 |
+
const ret = getObject(arg0).versions;
|
320 |
+
return addHeapObject(ret);
|
321 |
+
};
|
322 |
+
imports.wbg.__wbg_node_1cd7a5d853dbea79 = function(arg0) {
|
323 |
+
const ret = getObject(arg0).node;
|
324 |
+
return addHeapObject(ret);
|
325 |
+
};
|
326 |
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
327 |
+
const ret = typeof(getObject(arg0)) === 'string';
|
328 |
+
return ret;
|
329 |
+
};
|
330 |
+
imports.wbg.__wbg_msCrypto_bcb970640f50a1e8 = function(arg0) {
|
331 |
+
const ret = getObject(arg0).msCrypto;
|
332 |
+
return addHeapObject(ret);
|
333 |
+
};
|
334 |
+
imports.wbg.__wbg_require_8f08ceecec0f4fee = function() { return handleError(function () {
|
335 |
+
const ret = module.require;
|
336 |
+
return addHeapObject(ret);
|
337 |
+
}, arguments) };
|
338 |
+
imports.wbg.__wbindgen_is_function = function(arg0) {
|
339 |
+
const ret = typeof(getObject(arg0)) === 'function';
|
340 |
+
return ret;
|
341 |
+
};
|
342 |
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
343 |
+
const ret = getStringFromWasm0(arg0, arg1);
|
344 |
+
return addHeapObject(ret);
|
345 |
+
};
|
346 |
+
imports.wbg.__wbg_getRandomValues_37fa2ca9e4e07fab = function() { return handleError(function (arg0, arg1) {
|
347 |
+
getObject(arg0).getRandomValues(getObject(arg1));
|
348 |
+
}, arguments) };
|
349 |
+
imports.wbg.__wbg_randomFillSync_dc1e9a60c158336d = function() { return handleError(function (arg0, arg1) {
|
350 |
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
351 |
+
}, arguments) };
|
352 |
+
imports.wbg.__wbg_newnoargs_581967eacc0e2604 = function(arg0, arg1) {
|
353 |
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
354 |
+
return addHeapObject(ret);
|
355 |
+
};
|
356 |
+
imports.wbg.__wbg_call_cb65541d95d71282 = function() { return handleError(function (arg0, arg1) {
|
357 |
+
const ret = getObject(arg0).call(getObject(arg1));
|
358 |
+
return addHeapObject(ret);
|
359 |
+
}, arguments) };
|
360 |
+
imports.wbg.__wbindgen_object_clone_ref = function(arg0) {
|
361 |
+
const ret = getObject(arg0);
|
362 |
+
return addHeapObject(ret);
|
363 |
+
};
|
364 |
+
imports.wbg.__wbg_self_1ff1d729e9aae938 = function() { return handleError(function () {
|
365 |
+
const ret = self.self;
|
366 |
+
return addHeapObject(ret);
|
367 |
+
}, arguments) };
|
368 |
+
imports.wbg.__wbg_window_5f4faef6c12b79ec = function() { return handleError(function () {
|
369 |
+
const ret = window.window;
|
370 |
+
return addHeapObject(ret);
|
371 |
+
}, arguments) };
|
372 |
+
imports.wbg.__wbg_globalThis_1d39714405582d3c = function() { return handleError(function () {
|
373 |
+
const ret = globalThis.globalThis;
|
374 |
+
return addHeapObject(ret);
|
375 |
+
}, arguments) };
|
376 |
+
imports.wbg.__wbg_global_651f05c6a0944d1c = function() { return handleError(function () {
|
377 |
+
const ret = global.global;
|
378 |
+
return addHeapObject(ret);
|
379 |
+
}, arguments) };
|
380 |
+
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
381 |
+
const ret = getObject(arg0) === undefined;
|
382 |
+
return ret;
|
383 |
+
};
|
384 |
+
imports.wbg.__wbg_call_01734de55d61e11d = function() { return handleError(function (arg0, arg1, arg2) {
|
385 |
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
386 |
+
return addHeapObject(ret);
|
387 |
+
}, arguments) };
|
388 |
+
imports.wbg.__wbg_now_9c5990bda04c7e53 = function() {
|
389 |
+
const ret = Date.now();
|
390 |
+
return ret;
|
391 |
+
};
|
392 |
+
imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) {
|
393 |
+
const ret = getObject(arg0).buffer;
|
394 |
+
return addHeapObject(ret);
|
395 |
+
};
|
396 |
+
imports.wbg.__wbg_newwithbyteoffsetandlength_6da8e527659b86aa = function(arg0, arg1, arg2) {
|
397 |
+
const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0);
|
398 |
+
return addHeapObject(ret);
|
399 |
+
};
|
400 |
+
imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) {
|
401 |
+
const ret = new Uint8Array(getObject(arg0));
|
402 |
+
return addHeapObject(ret);
|
403 |
+
};
|
404 |
+
imports.wbg.__wbg_set_5cf90238115182c3 = function(arg0, arg1, arg2) {
|
405 |
+
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
406 |
+
};
|
407 |
+
imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function(arg0) {
|
408 |
+
const ret = new Uint8Array(arg0 >>> 0);
|
409 |
+
return addHeapObject(ret);
|
410 |
+
};
|
411 |
+
imports.wbg.__wbg_subarray_13db269f57aa838d = function(arg0, arg1, arg2) {
|
412 |
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
413 |
+
return addHeapObject(ret);
|
414 |
+
};
|
415 |
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
416 |
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
417 |
+
};
|
418 |
+
imports.wbg.__wbindgen_memory = function() {
|
419 |
+
const ret = wasm.memory;
|
420 |
+
return addHeapObject(ret);
|
421 |
+
};
|
422 |
+
|
423 |
+
return imports;
|
424 |
+
}
|
425 |
+
|
426 |
+
function __wbg_init_memory(imports, maybe_memory) {
|
427 |
+
|
428 |
+
}
|
429 |
+
|
430 |
+
function __wbg_finalize_init(instance, module) {
|
431 |
+
wasm = instance.exports;
|
432 |
+
__wbg_init.__wbindgen_wasm_module = module;
|
433 |
+
cachedInt32Memory0 = null;
|
434 |
+
cachedUint8Memory0 = null;
|
435 |
+
|
436 |
+
wasm.__wbindgen_start();
|
437 |
+
return wasm;
|
438 |
+
}
|
439 |
+
|
440 |
+
function initSync(module) {
|
441 |
+
if (wasm !== undefined) return wasm;
|
442 |
+
|
443 |
+
const imports = __wbg_get_imports();
|
444 |
+
|
445 |
+
__wbg_init_memory(imports);
|
446 |
+
|
447 |
+
if (!(module instanceof WebAssembly.Module)) {
|
448 |
+
module = new WebAssembly.Module(module);
|
449 |
+
}
|
450 |
+
|
451 |
+
const instance = new WebAssembly.Instance(module, imports);
|
452 |
+
|
453 |
+
return __wbg_finalize_init(instance, module);
|
454 |
+
}
|
455 |
+
|
456 |
+
async function __wbg_init(input) {
|
457 |
+
if (wasm !== undefined) return wasm;
|
458 |
+
|
459 |
+
if (typeof input === 'undefined') {
|
460 |
+
input = new URL('m_bg.wasm', import.meta.url);
|
461 |
+
}
|
462 |
+
const imports = __wbg_get_imports();
|
463 |
+
|
464 |
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
465 |
+
input = fetch(input);
|
466 |
+
}
|
467 |
+
|
468 |
+
__wbg_init_memory(imports);
|
469 |
+
|
470 |
+
const { instance, module } = await __wbg_load(await input, imports);
|
471 |
+
|
472 |
+
return __wbg_finalize_init(instance, module);
|
473 |
+
}
|
474 |
+
|
475 |
+
export { initSync }
|
476 |
+
export default __wbg_init;
|
src/routes/conversation/[id]/phi/m_bg.wasm
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4f38c8d88da95e96b33813a5e6f0479028ec4c550ea4a055082d2c5ff129605f
|
3 |
+
size 4368129
|
src/routes/conversation/[id]/phi/m_bg.wasm.d.ts
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* tslint:disable */
|
2 |
+
/* eslint-disable */
|
3 |
+
export const memory: WebAssembly.Memory;
|
4 |
+
export function __wbg_model_free(a: number): void;
|
5 |
+
export function model_load(a: number, b: number, c: number, d: number, e: number, f: number): void;
|
6 |
+
export function model_init_with_prompt(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void;
|
7 |
+
export function model_next_token(a: number, b: number): void;
|
8 |
+
export function main(a: number, b: number): number;
|
9 |
+
export function __wbindgen_add_to_stack_pointer(a: number): number;
|
10 |
+
export function __wbindgen_malloc(a: number, b: number): number;
|
11 |
+
export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
|
12 |
+
export function __wbindgen_free(a: number, b: number, c: number): void;
|
13 |
+
export function __wbindgen_exn_store(a: number): void;
|
14 |
+
export function __wbindgen_start(): void;
|
src/routes/conversation/[id]/worker.js
CHANGED
@@ -1,4 +1,48 @@
|
|
1 |
import { pipeline, env } from "@xenova/transformers";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
export class FlanPipeline {
|
4 |
static curr_model = "";
|
@@ -18,33 +62,135 @@ export class FlanPipeline {
|
|
18 |
}
|
19 |
}
|
20 |
|
|
|
|
|
21 |
// Listen for messages from the main thread
|
22 |
self.addEventListener("message", async (event) => {
|
23 |
-
|
24 |
-
(
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
self.postMessage({
|
36 |
-
status: "
|
37 |
-
output:
|
|
|
38 |
id_now: event.data.id_now,
|
39 |
});
|
40 |
-
}
|
41 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
status: "complete",
|
46 |
-
output:
|
47 |
-
searchID:
|
48 |
-
id_now:
|
49 |
-
|
50 |
-
})
|
|
|
|
|
|
|
|
|
|
1 |
import { pipeline, env } from "@xenova/transformers";
|
2 |
+
import init, { Model } from "./phi/m.js";
|
3 |
+
|
4 |
+
async function fetchArrayBuffer(url) {
|
5 |
+
const cacheName = "phi-mixformer-candle-cache";
|
6 |
+
const cache = await caches.open(cacheName);
|
7 |
+
const cachedResponse = await cache.match(url);
|
8 |
+
if (cachedResponse) {
|
9 |
+
const data = await cachedResponse.arrayBuffer();
|
10 |
+
return new Uint8Array(data);
|
11 |
+
}
|
12 |
+
const res = await fetch(url, { cache: "force-cache" });
|
13 |
+
cache.put(url, res.clone());
|
14 |
+
return new Uint8Array(await res.arrayBuffer());
|
15 |
+
}
|
16 |
+
|
17 |
+
class Phi {
|
18 |
+
static instance = {};
|
19 |
+
|
20 |
+
static async getInstance(weightsURL, modelID, tokenizerURL, quantized) {
|
21 |
+
// load individual modelID only once
|
22 |
+
if (!this.instance[modelID]) {
|
23 |
+
await init();
|
24 |
+
|
25 |
+
self.postMessage({ status: "loading", message: "Loading Model" });
|
26 |
+
self.postMessage({ status: "progress", file: "model-q4k.gguf", no_progress_bar: true, message: "Starting Phi" });
|
27 |
+
|
28 |
+
|
29 |
+
const [weightsArrayU8, tokenizerArrayU8] = await Promise.all([
|
30 |
+
fetchArrayBuffer(weightsURL),
|
31 |
+
fetchArrayBuffer(tokenizerURL),
|
32 |
+
]);
|
33 |
+
|
34 |
+
self.postMessage({ status: "init_model" });
|
35 |
+
|
36 |
+
this.instance[modelID] = new Model(
|
37 |
+
weightsArrayU8,
|
38 |
+
tokenizerArrayU8,
|
39 |
+
quantized
|
40 |
+
);
|
41 |
+
self.postMessage({ status: "ready" });
|
42 |
+
}
|
43 |
+
return this.instance[modelID];
|
44 |
+
}
|
45 |
+
}
|
46 |
|
47 |
export class FlanPipeline {
|
48 |
static curr_model = "";
|
|
|
62 |
}
|
63 |
}
|
64 |
|
65 |
+
let controller = null;
|
66 |
+
|
67 |
// Listen for messages from the main thread
|
68 |
self.addEventListener("message", async (event) => {
|
69 |
+
if (event.data.command != "abort") {
|
70 |
+
if (event.data.is_phi) {
|
71 |
+
controller = new AbortController();
|
72 |
+
generate_phi(event.data);
|
73 |
+
}
|
74 |
+
else {
|
75 |
+
let pipe = await FlanPipeline.getInstance(
|
76 |
+
(x) => {
|
77 |
+
self.postMessage(x);
|
78 |
+
},
|
79 |
+
event.data.model,
|
80 |
+
event.data.task
|
81 |
+
);
|
82 |
+
|
83 |
+
let output = await pipe(event.data.text, {
|
84 |
+
max_new_tokens: event.data.max_new_tokens,
|
85 |
+
temperature: event.data.temperature,
|
86 |
+
callback_function: (x) => {
|
87 |
+
self.postMessage({
|
88 |
+
status: "update",
|
89 |
+
output: pipe.tokenizer.decode(x[0].output_token_ids, { skip_special_tokens: true }),
|
90 |
+
id_now: event.data.id_now,
|
91 |
+
});
|
92 |
+
},
|
93 |
+
});
|
94 |
+
|
95 |
+
// Send the output back to the main thread
|
96 |
self.postMessage({
|
97 |
+
status: "complete",
|
98 |
+
output: output,
|
99 |
+
searchID: event.data.searchID,
|
100 |
id_now: event.data.id_now,
|
101 |
});
|
102 |
+
}
|
103 |
+
}
|
104 |
+
else {
|
105 |
+
if (controller != null)
|
106 |
+
controller.abort();
|
107 |
+
}
|
108 |
+
});
|
109 |
+
|
110 |
|
111 |
+
|
112 |
+
async function generate_phi(data) {
|
113 |
+
const tokenizerURL = "https://huggingface.co/microsoft/phi-1_5/raw/main/tokenizer.json";
|
114 |
+
const weightsURL = "https://huggingface.co/lmz/candle-quantized-phi/resolve/main/model-q4k.gguf";
|
115 |
+
let prompt = data.text
|
116 |
+
let maxSeqLen = data.max_new_tokens
|
117 |
+
let temp = data.temperature
|
118 |
+
let modelID = 0;
|
119 |
+
let quantized = true;
|
120 |
+
let top_p = 1;
|
121 |
+
let repeatPenalty = 1.1;
|
122 |
+
let seed = 299792458;
|
123 |
+
try {
|
124 |
+
const model = await Phi.getInstance(
|
125 |
+
weightsURL,
|
126 |
+
modelID,
|
127 |
+
tokenizerURL,
|
128 |
+
quantized
|
129 |
+
);
|
130 |
+
|
131 |
+
const firstToken = model.init_with_prompt(
|
132 |
+
prompt,
|
133 |
+
temp,
|
134 |
+
top_p,
|
135 |
+
repeatPenalty,
|
136 |
+
64,
|
137 |
+
BigInt(seed)
|
138 |
+
);
|
139 |
+
const seq_len = 2048;
|
140 |
+
|
141 |
+
let sentence = firstToken;
|
142 |
+
let maxTokens = maxSeqLen ? maxSeqLen : seq_len - prompt.length - 1;
|
143 |
+
let startTime = performance.now();
|
144 |
+
let tokensCount = 0;
|
145 |
+
|
146 |
+
while (tokensCount < maxTokens) {
|
147 |
+
await new Promise(async (resolve) => {
|
148 |
+
if (controller && controller.signal.aborted) {
|
149 |
+
self.postMessage({
|
150 |
+
status: "aborted",
|
151 |
+
message: "Aborted",
|
152 |
+
output: sentence,
|
153 |
+
searchID: data.searchID,
|
154 |
+
id_now: data.id_now,
|
155 |
+
});
|
156 |
+
return;
|
157 |
+
}
|
158 |
+
const token = await model.next_token();
|
159 |
+
if (token === "<|endoftext|>") {
|
160 |
+
self.postMessage({
|
161 |
+
status: "complete",
|
162 |
+
output: sentence,
|
163 |
+
searchID: data.searchID,
|
164 |
+
id_now: data.id_now,
|
165 |
+
});
|
166 |
+
return;
|
167 |
+
}
|
168 |
+
const tokensSec =
|
169 |
+
((tokensCount + 1) / (performance.now() - startTime)) * 1000;
|
170 |
+
|
171 |
+
sentence += token;
|
172 |
+
self.postMessage({
|
173 |
+
status: "update",
|
174 |
+
message: "Generating token",
|
175 |
+
token: token,
|
176 |
+
output: sentence,
|
177 |
+
totalTime: performance.now() - startTime,
|
178 |
+
tokensSec,
|
179 |
+
prompt: prompt,
|
180 |
+
id_now: data.id_now,
|
181 |
+
});
|
182 |
+
setTimeout(resolve, 0);
|
183 |
+
});
|
184 |
+
tokensCount++;
|
185 |
+
}
|
186 |
+
self.postMessage({
|
187 |
status: "complete",
|
188 |
+
output: sentence,
|
189 |
+
searchID: data.searchID,
|
190 |
+
id_now: data.id_now,
|
191 |
+
});
|
192 |
+
} catch (e) {
|
193 |
+
console.log(e)
|
194 |
+
self.postMessage({ error: e });
|
195 |
+
}
|
196 |
+
}
|