RecapAnon commited on
Commit ·
d74eb19
1
Parent(s): 35982a7
Remove more useless comments.
Browse files
index.js
CHANGED
|
@@ -157,36 +157,22 @@ async function generateResponse(userMessage) {
|
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
| 160 |
-
// Create enhanced user message with context
|
| 161 |
const enhancedMessage = contextInfo
|
| 162 |
? userMessage + contextInfo
|
| 163 |
: userMessage;
|
| 164 |
-
|
| 165 |
-
// Add user message to history (with context if available)
|
| 166 |
conversationHistory.push({ role: "user", content: enhancedMessage });
|
| 167 |
-
|
| 168 |
-
// Create streaming message container
|
| 169 |
const responseContainer = createStreamingMessageContainer();
|
| 170 |
-
|
| 171 |
-
// Generate response with streaming
|
| 172 |
const streamer = new TextStreamer(generator.tokenizer, {
|
| 173 |
skip_prompt: true,
|
| 174 |
skip_special_tokens: true
|
| 175 |
});
|
| 176 |
-
|
| 177 |
const output = await generator(conversationHistory, {
|
| 178 |
max_new_tokens: 512,
|
| 179 |
do_sample: false,
|
| 180 |
streamer: streamer
|
| 181 |
});
|
| 182 |
-
|
| 183 |
-
// Extract the generated text
|
| 184 |
const generatedText = output[0].generated_text.at(-1).content;
|
| 185 |
-
|
| 186 |
-
// Add assistant response to history
|
| 187 |
conversationHistory.push({ role: "assistant", content: generatedText });
|
| 188 |
-
|
| 189 |
-
// Update final response
|
| 190 |
responseContainer.textContent = generatedText || "I apologize, but I couldn't generate a response. Please try again.";
|
| 191 |
|
| 192 |
} catch (error) {
|
|
|
|
| 157 |
}
|
| 158 |
}
|
| 159 |
|
|
|
|
| 160 |
const enhancedMessage = contextInfo
|
| 161 |
? userMessage + contextInfo
|
| 162 |
: userMessage;
|
|
|
|
|
|
|
| 163 |
conversationHistory.push({ role: "user", content: enhancedMessage });
|
|
|
|
|
|
|
| 164 |
const responseContainer = createStreamingMessageContainer();
|
|
|
|
|
|
|
| 165 |
const streamer = new TextStreamer(generator.tokenizer, {
|
| 166 |
skip_prompt: true,
|
| 167 |
skip_special_tokens: true
|
| 168 |
});
|
|
|
|
| 169 |
const output = await generator(conversationHistory, {
|
| 170 |
max_new_tokens: 512,
|
| 171 |
do_sample: false,
|
| 172 |
streamer: streamer
|
| 173 |
});
|
|
|
|
|
|
|
| 174 |
const generatedText = output[0].generated_text.at(-1).content;
|
|
|
|
|
|
|
| 175 |
conversationHistory.push({ role: "assistant", content: generatedText });
|
|
|
|
|
|
|
| 176 |
responseContainer.textContent = generatedText || "I apologize, but I couldn't generate a response. Please try again.";
|
| 177 |
|
| 178 |
} catch (error) {
|