Skip to content

Commit 9757538

Browse files
committed
chatwidget realtime ide content
1 parent e666ed6 commit 9757538

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/resources/chat-widget/src/index.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,24 @@ const MAX_HISTORY_SIZE = 20;
131131
// Initialize the conversationHistory array
132132
let conversationHistory: MessageType[] = [];
133133

134+
function getcurrentIDECode(): MessageType {
135+
let idecodemsg = {
136+
role: "system",
137+
content: `Openrepl IDE/Editor real-time Code Content user is working on,
138+
(refer this code whenever user ask to debug editor/ide
139+
code without providing any code in message): `+ fetchEditorContent(),
140+
}
141+
return idecodemsg;
142+
}
143+
134144
// Function to add a message to the conversation history
135145
function addMessageToHistory(role: string, content: string, uid: string=UID): void {
136146
if (role=="user") {
137147
// to handle multiple peer users
138148
content = `[${role}-${uid}] ` + content;
139149
if (conversationHistory.length >= NUM_MANDATORY_ENTRIES) {
140150
// update editors content to msg history everytime user writes/sends message
141-
conversationHistory[NUM_MANDATORY_ENTRIES-1] = {
142-
role: "system",
143-
content: `Openrepl IDE/Editor real-time Code Content user is working on,
144-
(refer this code whenever user ask to debug editor/ide
145-
code without providing any code in message): `+ fetchEditorContent(),
146-
}
151+
conversationHistory[NUM_MANDATORY_ENTRIES-1] = getcurrentIDECode();
147152
}
148153
}
149154

@@ -601,7 +606,7 @@ async function submit(e: Event) {
601606
const data = {
602607
...config.user,
603608
model: config.model,
604-
messages: conversationHistory,
609+
messages: [...conversationHistory, getcurrentIDECode()],
605610
temperature: config.temperature,
606611
max_tokens: config.max_tokens,
607612
stream: config.responseIsAStream,

src/resources/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,24 @@ <h3 class="section__title">Share/Collaborate</h3>
902902
}
903903
}
904904
}
905+
906+
// save current topic and difficultylevel
907+
let topic = $("#topic").val().trim();
908+
let difficultyLevel = $("#difficulty").val().trim();
909+
910+
localStorage.setItem("topic", topic);
911+
localStorage.setItem("difficultyLevel", difficultyLevel);
905912
}
906913

907914
$(window).on("unload", SaveLastLanguageProgress);
915+
const existingHandler = window.onbeforeunload;
916+
window.onbeforeunload = function(event) {
917+
// Call existing handler first (if any)
918+
if (existingHandler) {
919+
return existingHandler(event);
920+
}
921+
SaveLastLanguageProgress();
922+
};
908923

909924
$("#optionlist").on("change", function () {
910925
SaveLastLanguageProgress(lastSelectedLanguage);
@@ -919,6 +934,11 @@ <h3 class="section__title">Share/Collaborate</h3>
919934
const modal = document.getElementById("modal");
920935
const button = document.getElementById("qsubmit-btn");
921936
$("#temperature").val(globaltemperature); // one time init
937+
938+
let savedTopic = localStorage.getItem("topic") || "";
939+
let savedDifficultyLevel = localStorage.getItem("difficultyLevel") || "";
940+
$("#topic").val(savedTopic).trigger('change');
941+
$("#difficulty").val(savedDifficultyLevel);
922942
button.addEventListener("click", function(event) {
923943
event.preventDefault(); // Prevent form submission
924944

0 commit comments

Comments
 (0)