akhaliq HF Staff commited on
Commit
3fe4bf5
·
verified ·
1 Parent(s): 6b9de7b

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +18 -4
index.js CHANGED
@@ -153,6 +153,18 @@ class StreamingChatbot {
153
  streamingIndicator.style.marginLeft = '4px';
154
  messageContent.appendChild(streamingIndicator);
155
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  // Create enhanced TextStreamer with proper callback handling
157
  this.currentStreamer = new TextStreamer(this.generator.tokenizer, {
158
  skip_prompt: true,
@@ -168,12 +180,14 @@ class StreamingChatbot {
168
  }
169
  });
170
 
171
- // Use the messages array directly with the generator (like the original working code)
172
- const output = await this.generator(this.messages, {
173
- max_new_tokens: 300,
174
- do_sample: false,
175
  temperature: 0.7,
 
176
  streamer: this.currentStreamer,
 
177
  });
178
 
179
  // Clean up streaming indicator if still present
 
153
  streamingIndicator.style.marginLeft = '4px';
154
  messageContent.appendChild(streamingIndicator);
155
 
156
+ // Create a simple prompt from the last few messages
157
+ const recentMessages = this.messages.slice(-6); // Keep last 6 messages for context
158
+ let prompt = "";
159
+ for (const msg of recentMessages) {
160
+ if (msg.role === "user") {
161
+ prompt += `Human: ${msg.content}\n`;
162
+ } else {
163
+ prompt += `Assistant: ${msg.content}\n`;
164
+ }
165
+ }
166
+ prompt += "Assistant:";
167
+
168
  // Create enhanced TextStreamer with proper callback handling
169
  this.currentStreamer = new TextStreamer(this.generator.tokenizer, {
170
  skip_prompt: true,
 
180
  }
181
  });
182
 
183
+ // Generate response with streaming
184
+ const output = await this.generator(prompt, {
185
+ max_new_tokens: 200,
186
+ do_sample: true,
187
  temperature: 0.7,
188
+ top_p: 0.9,
189
  streamer: this.currentStreamer,
190
+ return_full_text: false
191
  });
192
 
193
  // Clean up streaming indicator if still present