@@ -131,19 +131,24 @@ const MAX_HISTORY_SIZE = 20;
131131// Initialize the conversationHistory array
132132let 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
135145function 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 ,
0 commit comments