Vaibhavs10 commited on
Commit
862fb14
·
1 Parent(s): acf9557
Files changed (1) hide show
  1. index.html +16 -10
index.html CHANGED
@@ -270,18 +270,24 @@
270
  }
271
 
272
  const model = modelSelect.value;
273
- const response = await hfClient.conversational({
274
- model: model,
275
- inputs: {
276
- text: message,
277
- past_user_inputs: [],
278
- generated_responses: []
279
- }
 
 
 
 
280
  });
281
-
282
- updateMessage(loadingId, response.generated_text);
 
283
  chatMessages.scrollTop = chatMessages.scrollHeight;
284
- tokenCounter.textContent = `${response.conversation.generated_responses[0].length} tokens`;
 
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);