Spaces:
Build error
Build error
Adrien Denat
commited on
Commit
•
793c54c
1
Parent(s):
f953cbd
apply Prettier to changes
Browse files- src/routes/+page.svelte +25 -15
src/routes/+page.svelte
CHANGED
@@ -1,14 +1,20 @@
|
|
1 |
<script lang="ts">
|
2 |
-
import { afterUpdate } from 'svelte'
|
3 |
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
4 |
import ChatBox from '$lib/chat/ChatBox.svelte';
|
5 |
import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
|
6 |
import type { Message, StreamResponse } from '$lib/Types';
|
7 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
const userToken = PUBLIC_USER_MESSAGE_TOKEN ||
|
10 |
-
const assistantToken = PUBLIC_ASSISTANT_MESSAGE_TOKEN ||
|
11 |
-
const sepToken = PUBLIC_SEP_TOKEN ||
|
12 |
|
13 |
let messages: Message[] = [];
|
14 |
let message = '';
|
@@ -24,9 +30,11 @@
|
|
24 |
message = '';
|
25 |
const inputs =
|
26 |
messages
|
27 |
-
.map(
|
28 |
-
(m
|
29 |
-
|
|
|
|
|
30 |
.join('') + assistantToken;
|
31 |
|
32 |
console.log(inputs);
|
@@ -35,10 +43,12 @@
|
|
35 |
headers: {
|
36 |
Accept: 'text/event-stream',
|
37 |
'Content-Type': 'application/json',
|
38 |
-
|
39 |
-
...(PUBLIC_HF_TOKEN
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
},
|
43 |
body: JSON.stringify({
|
44 |
inputs: inputs,
|
@@ -51,12 +61,12 @@
|
|
51 |
truncate: 1000,
|
52 |
typical_p: 0.2,
|
53 |
watermark: false,
|
54 |
-
details: true
|
55 |
}
|
56 |
}),
|
57 |
async onopen(response) {
|
58 |
if (response.ok && response.headers.get('content-type') === 'text/event-stream') {
|
59 |
-
messages = [...messages, { from: 'bot', content:
|
60 |
} else {
|
61 |
console.error('error opening the SSE endpoint');
|
62 |
}
|
@@ -81,7 +91,7 @@
|
|
81 |
>
|
82 |
<div class="flex-none sticky top-0 relative p-3 flex flex-col">
|
83 |
<button
|
84 |
-
on:click={() =>
|
85 |
class="border px-12 py-2.5 rounded-lg border shadow bg-white dark:bg-gray-700 dark:border-gray-600"
|
86 |
>New Chat</button
|
87 |
>
|
|
|
1 |
<script lang="ts">
|
2 |
+
import { afterUpdate } from 'svelte';
|
3 |
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
4 |
import ChatBox from '$lib/chat/ChatBox.svelte';
|
5 |
import ChatIntroduction from '$lib/chat/ChatIntroduction.svelte';
|
6 |
import type { Message, StreamResponse } from '$lib/Types';
|
7 |
+
import {
|
8 |
+
PUBLIC_ASSISTANT_MESSAGE_TOKEN,
|
9 |
+
PUBLIC_ENDPOINT,
|
10 |
+
PUBLIC_HF_TOKEN,
|
11 |
+
PUBLIC_SEP_TOKEN,
|
12 |
+
PUBLIC_USER_MESSAGE_TOKEN
|
13 |
+
} from '$env/static/public';
|
14 |
|
15 |
+
const userToken = PUBLIC_USER_MESSAGE_TOKEN || '<|prompter|>';
|
16 |
+
const assistantToken = PUBLIC_ASSISTANT_MESSAGE_TOKEN || '<|assistant|>';
|
17 |
+
const sepToken = PUBLIC_SEP_TOKEN || '<|endoftext|>';
|
18 |
|
19 |
let messages: Message[] = [];
|
20 |
let message = '';
|
|
|
30 |
message = '';
|
31 |
const inputs =
|
32 |
messages
|
33 |
+
.map(
|
34 |
+
(m) =>
|
35 |
+
(m.from === 'user' ? userToken + m.content : assistantToken + m.content) +
|
36 |
+
(m.content.endsWith(sepToken) ? '' : sepToken)
|
37 |
+
)
|
38 |
.join('') + assistantToken;
|
39 |
|
40 |
console.log(inputs);
|
|
|
43 |
headers: {
|
44 |
Accept: 'text/event-stream',
|
45 |
'Content-Type': 'application/json',
|
46 |
+
'user-agent': 'chat-ui/0.0.1',
|
47 |
+
...(PUBLIC_HF_TOKEN
|
48 |
+
? {
|
49 |
+
authorization: `Bearer ${PUBLIC_HF_TOKEN}`
|
50 |
+
}
|
51 |
+
: {})
|
52 |
},
|
53 |
body: JSON.stringify({
|
54 |
inputs: inputs,
|
|
|
61 |
truncate: 1000,
|
62 |
typical_p: 0.2,
|
63 |
watermark: false,
|
64 |
+
details: true
|
65 |
}
|
66 |
}),
|
67 |
async onopen(response) {
|
68 |
if (response.ok && response.headers.get('content-type') === 'text/event-stream') {
|
69 |
+
messages = [...messages, { from: 'bot', content: '' }];
|
70 |
} else {
|
71 |
console.error('error opening the SSE endpoint');
|
72 |
}
|
|
|
91 |
>
|
92 |
<div class="flex-none sticky top-0 relative p-3 flex flex-col">
|
93 |
<button
|
94 |
+
on:click={() => location.reload()}
|
95 |
class="border px-12 py-2.5 rounded-lg border shadow bg-white dark:bg-gray-700 dark:border-gray-600"
|
96 |
>New Chat</button
|
97 |
>
|