@@ -19,14 +19,32 @@ const profile = {
1919 events : [ ] ,
2020 maintainedBy : 'Remix' ,
2121}
22+ type ChatEntry = [ string , string ] ;
23+
24+ enum BackendOPModel {
25+ DeeSeek ,
26+ CodeLLama ,
27+ Mistral
28+ }
29+
30+ const PromptBuilder = ( inst , answr , modelop ) => {
31+ if ( modelop === BackendOPModel . CodeLLama ) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr
32+ if ( modelop === BackendOPModel . DeeSeek ) return ""
33+ if ( modelop === BackendOPModel . Mistral ) return ""
34+ }
2235
2336export class SolCoder extends Plugin {
2437 api_url : string
2538 completion_url : string
39+ solgpt_chat_history :ChatEntry [ ]
40+ max_history = 7
41+ model_op = BackendOPModel . CodeLLama
42+
2643 constructor ( ) {
2744 super ( profile )
2845 this . api_url = "https://solcoder.remixproject.org"
2946 this . completion_url = "https://completion.remixproject.org"
47+ this . solgpt_chat_history = [ ]
3048 }
3149
3250 async code_generation ( prompt ) : Promise < any > {
@@ -62,24 +80,29 @@ export class SolCoder extends Plugin {
6280 this . call ( 'layout' , 'maximizeTerminal' )
6381 let result
6482 try {
83+ const main_prompt = this . _build_solgpt_promt ( prompt )
6584 result = await (
6685 await fetch ( this . api_url , {
6786 method : 'POST' ,
6887 headers : {
6988 Accept : 'application/json' ,
7089 'Content-Type' : 'application/json' ,
7190 } ,
72- body : JSON . stringify ( { "data" :[ prompt , "solidity_answer" , false , 1000 , 0.9 , 0.8 , 50 ] } ) ,
91+ body : JSON . stringify ( { "data" :[ main_prompt , "solidity_answer" , false , 1000 , 0.9 , 0.8 , 50 ] } ) ,
7392 } )
7493 ) . json ( )
7594 } catch ( e ) {
7695 this . call ( 'terminal' , 'log' , { type : 'typewritererror' , value : `Unable to get a response ${ e . message } ` } )
96+ this . solgpt_chat_history = [ ]
7797 return
7898 } finally {
7999 this . emit ( "aiInferingDone" )
80100 }
81101 if ( result ) {
82102 this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : result . data [ 0 ] } )
103+ const chat :ChatEntry = [ prompt , result . data [ 0 ] ]
104+ this . solgpt_chat_history . push ( chat )
105+ if ( this . solgpt_chat_history . length > this . max_history ) { this . solgpt_chat_history . shift ( ) }
83106 } else if ( result . error ) {
84107 this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "Error on request" } )
85108 }
@@ -195,4 +218,18 @@ export class SolCoder extends Plugin {
195218 }
196219 }
197220
221+ _build_solgpt_promt ( user_promt :string ) {
222+ if ( this . solgpt_chat_history . length === 0 ) {
223+ return user_promt
224+ } else {
225+ let new_promt = ""
226+ for ( const [ question , answer ] of this . solgpt_chat_history ) {
227+ new_promt += PromptBuilder ( question . split ( 'sol-gpt' ) [ 1 ] , answer , this . model_op )
228+ }
229+ // finaly
230+ new_promt = "sol-gpt " + new_promt + PromptBuilder ( user_promt . split ( 'sol-gpt' ) [ 1 ] , "" , this . model_op )
231+ return new_promt
232+ }
233+ }
234+
198235}
0 commit comments