@@ -19,14 +19,32 @@ const profile = {
19
19
events : [ ] ,
20
20
maintainedBy : 'Remix' ,
21
21
}
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
+ }
22
35
23
36
export class SolCoder extends Plugin {
24
37
api_url : string
25
38
completion_url : string
39
+ solgpt_chat_history :ChatEntry [ ]
40
+ max_history = 7
41
+ model_op = BackendOPModel . CodeLLama
42
+
26
43
constructor ( ) {
27
44
super ( profile )
28
45
this . api_url = "https://solcoder.remixproject.org"
29
46
this . completion_url = "https://completion.remixproject.org"
47
+ this . solgpt_chat_history = [ ]
30
48
}
31
49
32
50
async code_generation ( prompt ) : Promise < any > {
@@ -62,24 +80,29 @@ export class SolCoder extends Plugin {
62
80
this . call ( 'layout' , 'maximizeTerminal' )
63
81
let result
64
82
try {
83
+ const main_prompt = this . _build_solgpt_promt ( prompt )
65
84
result = await (
66
85
await fetch ( this . api_url , {
67
86
method : 'POST' ,
68
87
headers : {
69
88
Accept : 'application/json' ,
70
89
'Content-Type' : 'application/json' ,
71
90
} ,
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 ] } ) ,
73
92
} )
74
93
) . json ( )
75
94
} catch ( e ) {
76
95
this . call ( 'terminal' , 'log' , { type : 'typewritererror' , value : `Unable to get a response ${ e . message } ` } )
96
+ this . solgpt_chat_history = [ ]
77
97
return
78
98
} finally {
79
99
this . emit ( "aiInferingDone" )
80
100
}
81
101
if ( result ) {
82
102
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 ( ) }
83
106
} else if ( result . error ) {
84
107
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "Error on request" } )
85
108
}
@@ -195,4 +218,18 @@ export class SolCoder extends Plugin {
195
218
}
196
219
}
197
220
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
+
198
235
}
0 commit comments