Skip to content

Commit 69c6db2

Browse files
Update scripts.js
Signed-off-by: Brad Hutchings <[email protected]>
1 parent 727ef33 commit 69c6db2

File tree

1 file changed

+39
-16
lines changed

1 file changed

+39
-16
lines changed

completion-ui/completion/scripts.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,21 @@ async function StartGenerating(workAreaText, temperature, tokens, stopWords) {
599599
}
600600
catch(exc) {
601601
if (kLogging) console.log("Exception caught receiving results.");
602-
if (kLogging) console.log(exc);
602+
if (kLogging) console.log(exc.name);
603+
if (kLogging) console.log(exc.message);
604+
605+
// I thought this might be a checkbox in settings, but that felt clumsy.
606+
// These are mostly network errors. It would be good for the user to know.
607+
// -Brad 2025-07-25
608+
let reportProblemsInWorkArea = true;
609+
if (reportProblemsInWorkArea) {
610+
if (!exc.name.includes("AbortError")) {
611+
let problemText = "\n\n----------------------------------------\n\n" +
612+
"A problem was encountered while completing:\n\n" +
613+
exc + "\n\n";
614+
elements.workAreaText.value = elements.workAreaText.value + problemText;
615+
}
616+
}
603617
}
604618

605619
controller = null;
@@ -722,6 +736,9 @@ function SetStatus(status) {
722736
elements.statusText.innerHTML = "<b>Status:</b> " + status;
723737
}
724738

739+
var generationStartedMS = 0;
740+
const generationMinimumTimeMS = 1500;
741+
725742
function WorkAreaTextKeyDown(event) {
726743
let logThis = false;
727744
if (kLogging || logThis) console.log('WorkAreaTextKeyDown()');
@@ -733,8 +750,10 @@ function WorkAreaTextKeyDown(event) {
733750

734751
// return key in the field should stop generating.
735752
if (event.keyCode == 13) {
736-
if (kLogging || logThis) console.log('- return');
737-
StopGenerating();
753+
if ((Date.now() - generationStartedMS) >= generationMinimumTimeMS) {
754+
if (kLogging || logThis) console.log('- return');
755+
StopGenerating();
756+
}
738757
}
739758
}
740759

@@ -759,6 +778,7 @@ function WorkAreaTextKeyDown(event) {
759778
}
760779
event.preventDefault();
761780

781+
generationStartedMS = Date.now();
762782
setTimeout(() => {
763783
Generate();
764784
}, 500);
@@ -1377,20 +1397,20 @@ async function CountTokens() {
13771397
"with_pieces": false,
13781398
}
13791399

1380-
const response = await fetch(kTokenizeURL, {
1381-
method: 'POST',
1382-
mode: 'cors',
1383-
headers: {
1384-
'Content-Type': 'application/json',
1385-
},
1386-
body: JSON.stringify(data),
1387-
// signal: controller.signal,
1388-
});
1389-
1390-
const json = await response.json();
1391-
13921400
try {
13931401

1402+
const response = await fetch(kTokenizeURL, {
1403+
method: 'POST',
1404+
mode: 'cors',
1405+
headers: {
1406+
'Content-Type': 'application/json',
1407+
},
1408+
body: JSON.stringify(data),
1409+
// signal: controller.signal,
1410+
});
1411+
1412+
const json = await response.json();
1413+
13941414
if (kLogging) console.log("json:\n");
13951415
if (kLogging) console.log(json);
13961416

@@ -1411,7 +1431,10 @@ async function CountTokens() {
14111431
}
14121432
catch(exc) {
14131433
if (kLogging) console.log("Exception caught receiving results from " + kTokenizeURL + ".");
1414-
if (kLogging) console.log(exc);
1434+
if (kLogging) console.log(exc.name);
1435+
if (kLogging) console.log(exc.message);
1436+
1437+
// As far as the user sees, a silent fail here is OK.
14151438
}
14161439

14171440
elements.statusTokens.innerHTML = tokensHTML;

0 commit comments

Comments
 (0)