Skip to content

Commit f7e6683

Browse files
Update scripts.js
Signed-off-by: Brad Hutchings <[email protected]>
1 parent a6006fc commit f7e6683

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

completion-ui/completion/scripts.js

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ var generating = false; // Replace this with a mode: kMode_Typing, kMode
4040
var replaying = false;
4141
var metadata = {};
4242
var contextWindowSize = 0;
43+
var tokenCount = 0;
4344
var modelName = "";
4445

4546
var isMobile = (navigator.maxTouchPoints > 1) && (window.navigator.userAgent.includes("Mobi"));
@@ -393,8 +394,6 @@ function StopWordsSetFocus() {
393394
function Generate() {
394395
if (!generating && !replaying) {
395396
PushChange();
396-
397-
SetGenerating(true);
398397

399398
var workAreaText = elements.workAreaText.value;
400399

@@ -418,9 +417,18 @@ function Generate() {
418417

419418
if (kLogging) console.log(workAreaText);
420419

421-
StartGenerating(workAreaText, temperature, tokens, stopWords);
420+
if (tokenCount <= contextWindowSize) {
421+
SetGenerating(true);
422+
StartGenerating(workAreaText, temperature, tokens, stopWords);
423+
}
424+
else {
425+
let problemText = "\n\n----------------------------------------\n\n" +
426+
"The text in the work area exceeds the context window size for this model.\n\n" +
427+
"Please remove some text from the work area or switch to a bigger model.";
428+
elements.workAreaText.value = elements.workAreaText.value + problemText;
422429

423-
430+
ScrollToEnd();
431+
}
424432
}
425433
}
426434

@@ -458,7 +466,7 @@ var manualStop = false;
458466
var generatedContent = '';
459467

460468
async function StartGenerating(workAreaText, temperature, tokens, stopWords) {
461-
let logThis = true;
469+
let logThis = false;
462470

463471
// show that we're working??
464472
SetStatus(kStatus_Evaluating);
@@ -723,6 +731,21 @@ function StopReplaying() {
723731
SetReplaying(false);
724732
}
725733

734+
function WorkAreaTextPaste() {
735+
if (!generating && !replaying) {
736+
// Force this to happen after the paste. If you double paste
737+
// too quickly, it will get caught in the same change.
738+
setTimeout(() => {
739+
PushChange();
740+
}, 500);
741+
}
742+
else {
743+
event.preventDefault(); // Prevent the default paste behavior
744+
}
745+
746+
ShowHideStatusButtons();
747+
}
748+
726749
function ShowHideStatusButtons() {
727750
if ((elements.workAreaText.value != '') && !generating) {
728751
ShowElement(elements.statusStart);
@@ -1443,13 +1466,15 @@ async function CountTokens() {
14431466
if (kLogging) console.log(tokens);
14441467

14451468
if (Array.isArray(tokens)) {
1446-
if (kLogging) console.log("tokens is an array with " + tokens.length + " items.");
1469+
tokenCount = tokens.length;
1470+
1471+
if (kLogging) console.log("tokens is an array with " + tokenCount + " items.");
14471472

14481473
if (contextWindowSize > 1 ) {
1449-
tokensHTML = "<b>Tokens:</b> " + + tokens.length + "&nbsp;/&nbsp;" + contextWindowSize;
1474+
tokensHTML = "<b>Tokens:</b> " + tokenCount + "&nbsp;/&nbsp;" + contextWindowSize;
14501475
}
14511476
else {
1452-
tokensHTML = "<b>Tokens:</b> " + + tokens.length;
1477+
tokensHTML = "<b>Tokens:</b> " + tokenCount;
14531478
}
14541479
}
14551480
}

0 commit comments

Comments
 (0)