Spaces:
Running
Running
Vaibhavs10
commited on
Commit
·
862fb14
1
Parent(s):
acf9557
up.
Browse files- index.html +16 -10
index.html
CHANGED
@@ -270,18 +270,24 @@
|
|
270 |
}
|
271 |
|
272 |
const model = modelSelect.value;
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
|
|
|
|
|
|
|
|
280 |
});
|
281 |
-
|
282 |
-
|
|
|
283 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
284 |
-
|
|
|
285 |
|
286 |
} catch (error) {
|
287 |
console.error("Error:", error);
|
|
|
270 |
}
|
271 |
|
272 |
const model = modelSelect.value;
|
273 |
+
// Build chat history for context
|
274 |
+
const history = getConversationHistory().map(msg => ({
|
275 |
+
role: msg.role,
|
276 |
+
content: msg.content
|
277 |
+
}));
|
278 |
+
history.push({ role: 'user', content: message });
|
279 |
+
|
280 |
+
const response = await hfClient.chatCompletion({
|
281 |
+
model,
|
282 |
+
messages: history,
|
283 |
+
max_tokens: 1024
|
284 |
});
|
285 |
+
|
286 |
+
const assistantMsg = response.choices?.[0]?.message?.content || '[No response]';
|
287 |
+
updateMessage(loadingId, assistantMsg);
|
288 |
chatMessages.scrollTop = chatMessages.scrollHeight;
|
289 |
+
// optional simple token count
|
290 |
+
tokenCounter.textContent = `${assistantMsg.split(/\s+/).length} tokens`;
|
291 |
|
292 |
} catch (error) {
|
293 |
console.error("Error:", error);
|