Update to use `OpenAssistant/oasst-sft-1-pythia-12b`
Browse files- src/routes/+page.svelte +21 -15
src/routes/+page.svelte
CHANGED
@@ -3,9 +3,11 @@
|
|
3 |
import ChatBox from '$lib/chat/ChatBox.svelte';
|
4 |
import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
|
5 |
import type { Message } from '$lib/Types';
|
6 |
-
|
7 |
-
const ENDPOINT = 'https://joi-20b.ngrok.io/generate_stream';
|
8 |
|
|
|
|
|
|
|
9 |
|
10 |
let messages: Message[] = [];
|
11 |
let message = '';
|
@@ -13,33 +15,37 @@
|
|
13 |
function onWrite() {
|
14 |
messages = [...messages, { from: 'user', content: message }];
|
15 |
message = '';
|
16 |
-
let incoming = '';
|
17 |
const inputs =
|
18 |
messages
|
19 |
-
.map((m) => (
|
20 |
-
|
|
|
|
|
21 |
|
22 |
-
fetchEventSource(
|
23 |
method: 'POST',
|
24 |
headers: {
|
25 |
Accept: 'text/event-stream',
|
26 |
-
'Content-Type': 'application/json'
|
|
|
|
|
27 |
},
|
28 |
body: JSON.stringify({
|
29 |
inputs: inputs,
|
30 |
parameters: {
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
|
|
38 |
}
|
39 |
}),
|
40 |
async onopen(response) {
|
41 |
if (response.ok && response.headers.get('content-type') === 'text/event-stream') {
|
42 |
-
messages = [...messages, { from: 'bot', content:
|
43 |
} else {
|
44 |
console.error('error opening the SSE endpoint');
|
45 |
}
|
|
|
3 |
import ChatBox from '$lib/chat/ChatBox.svelte';
|
4 |
import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
|
5 |
import type { Message } from '$lib/Types';
|
6 |
+
import { PUBLIC_ASSISTANT_MESSAGE_TOKEN, PUBLIC_ENDPOINT, PUBLIC_HF_TOKEN, PUBLIC_SEP_TOKEN, PUBLIC_USER_MESSAGE_TOKEN } from '$env/static/public';
|
|
|
7 |
|
8 |
+
const userToken = PUBLIC_USER_MESSAGE_TOKEN || "<|prompter|>";
|
9 |
+
const assistantToken = PUBLIC_ASSISTANT_MESSAGE_TOKEN || "<|assistant|>";
|
10 |
+
const sepToken = PUBLIC_SEP_TOKEN || "<|endoftext|>";
|
11 |
|
12 |
let messages: Message[] = [];
|
13 |
let message = '';
|
|
|
15 |
function onWrite() {
|
16 |
messages = [...messages, { from: 'user', content: message }];
|
17 |
message = '';
|
|
|
18 |
const inputs =
|
19 |
messages
|
20 |
+
.map((m) => (
|
21 |
+
(m.from === 'user' ? userToken + m.content : assistantToken + m.content))
|
22 |
+
+ (m.content.endsWith(sepToken) ? "" : sepToken))
|
23 |
+
.join('') + assistantToken;
|
24 |
|
25 |
+
fetchEventSource(PUBLIC_ENDPOINT, {
|
26 |
method: 'POST',
|
27 |
headers: {
|
28 |
Accept: 'text/event-stream',
|
29 |
+
'Content-Type': 'application/json',
|
30 |
+
"user-agent": "text-generation/0.3.0; hf_hub/0.12.1; python/3.10.10",
|
31 |
+
"authorization": `Bearer ${PUBLIC_HF_TOKEN}`,
|
32 |
},
|
33 |
body: JSON.stringify({
|
34 |
inputs: inputs,
|
35 |
parameters: {
|
36 |
+
do_sample: false,
|
37 |
+
max_new_tokens: 500,
|
38 |
+
return_full_text: false,
|
39 |
+
stop: [],
|
40 |
+
truncate: 1000,
|
41 |
+
typical_p: 0.2,
|
42 |
+
watermark: false,
|
43 |
+
details: true,
|
44 |
}
|
45 |
}),
|
46 |
async onopen(response) {
|
47 |
if (response.ok && response.headers.get('content-type') === 'text/event-stream') {
|
48 |
+
messages = [...messages, { from: 'bot', content: "" }];
|
49 |
} else {
|
50 |
console.error('error opening the SSE endpoint');
|
51 |
}
|