Spaces:
Build error
Build error
Implemented chat completion streaming functionality in the Playground component.
Browse files
src/lib/components/Playground/Playground.svelte
CHANGED
@@ -63,19 +63,14 @@
|
|
63 |
try {
|
64 |
const hf = new HfInference(hfToken);
|
65 |
|
66 |
-
const
|
67 |
model: currentModel,
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
});
|
75 |
-
|
76 |
-
for await (const response of stream) {
|
77 |
-
if (streamingMessage) {
|
78 |
-
streamingMessage.content += response.token.text;
|
79 |
messages = [...messages];
|
80 |
}
|
81 |
}
|
|
|
63 |
try {
|
64 |
const hf = new HfInference(hfToken);
|
65 |
|
66 |
+
for await (const chunk of hf.chatCompletionStream({
|
67 |
model: currentModel,
|
68 |
+
messages: messages.map(({ role, content }) => ({ role, content })),
|
69 |
+
temperature: temperature,
|
70 |
+
max_tokens: maxTokens
|
71 |
+
})) {
|
72 |
+
if (streamingMessage && chunk.choices[0]?.delta?.content) {
|
73 |
+
streamingMessage.content += chunk.choices[0].delta.content;
|
|
|
|
|
|
|
|
|
|
|
74 |
messages = [...messages];
|
75 |
}
|
76 |
}
|