@@ -131,19 +131,24 @@ const MAX_HISTORY_SIZE = 20;
131
131
// Initialize the conversationHistory array
132
132
let conversationHistory : MessageType [ ] = [ ] ;
133
133
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
+
134
144
// Function to add a message to the conversation history
135
145
function addMessageToHistory ( role : string , content : string , uid : string = UID ) : void {
136
146
if ( role == "user" ) {
137
147
// to handle multiple peer users
138
148
content = `[${ role } -${ uid } ] ` + content ;
139
149
if ( conversationHistory . length >= NUM_MANDATORY_ENTRIES ) {
140
150
// 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 ( ) ;
147
152
}
148
153
}
149
154
@@ -601,7 +606,7 @@ async function submit(e: Event) {
601
606
const data = {
602
607
...config . user ,
603
608
model : config . model ,
604
- messages : conversationHistory ,
609
+ messages : [ ... conversationHistory , getcurrentIDECode ( ) ] ,
605
610
temperature : config . temperature ,
606
611
max_tokens : config . max_tokens ,
607
612
stream : config . responseIsAStream ,
0 commit comments