@@ -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,30 @@ 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 )
84
+ console . log ( main_prompt . length )
65
85
result = await (
66
86
await fetch ( this . api_url , {
67
87
method : 'POST' ,
68
88
headers : {
69
89
Accept : 'application/json' ,
70
90
'Content-Type' : 'application/json' ,
71
91
} ,
72
- body : JSON . stringify ( { "data" :[ prompt , "solidity_answer" , false , 1000 , 0.9 , 0.8 , 50 ] } ) ,
92
+ body : JSON . stringify ( { "data" :[ main_prompt , "solidity_answer" , false , 1000 , 0.9 , 0.8 , 50 ] } ) ,
73
93
} )
74
94
) . json ( )
75
95
} catch ( e ) {
76
96
this . call ( 'terminal' , 'log' , { type : 'typewritererror' , value : `Unable to get a response ${ e . message } ` } )
97
+ this . solgpt_chat_history = [ ]
77
98
return
78
99
} finally {
79
100
this . emit ( "aiInferingDone" )
80
101
}
81
102
if ( result ) {
82
103
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : result . data [ 0 ] } )
104
+ const chat :ChatEntry = [ prompt , result . data [ 0 ] ]
105
+ this . solgpt_chat_history . push ( chat )
106
+ if ( this . solgpt_chat_history . length > this . max_history ) { this . solgpt_chat_history . shift ( ) }
83
107
} else if ( result . error ) {
84
108
this . call ( 'terminal' , 'log' , { type : 'aitypewriterwarning' , value : "Error on request" } )
85
109
}
@@ -195,4 +219,18 @@ export class SolCoder extends Plugin {
195
219
}
196
220
}
197
221
222
+ _build_solgpt_promt ( user_promt :string ) {
223
+ if ( this . solgpt_chat_history . length === 0 ) {
224
+ return user_promt
225
+ } else {
226
+ let new_promt = ""
227
+ for ( const [ question , answer ] of this . solgpt_chat_history ) {
228
+ new_promt += PromptBuilder ( question . split ( 'sol-gpt' ) [ 1 ] , answer , this . model_op )
229
+ }
230
+ // finaly
231
+ new_promt = "sol-gpt " + new_promt + PromptBuilder ( user_promt . split ( 'sol-gpt' ) [ 1 ] , "" , this . model_op )
232
+ return new_promt
233
+ }
234
+ }
235
+
198
236
}
0 commit comments