Skip to content

Commit bbfdf5e

Browse files
STetsingAniket-Engg
authored andcommitted
simple chat in terminal
1 parent 677a949 commit bbfdf5e

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

apps/remix-ide/src/app/plugins/solcoderAI.tsx

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

2336
export 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,30 @@ export class SolCoder extends Plugin {
6280
this.call('layout', 'maximizeTerminal')
6381
let result
6482
try {
83+
const main_prompt = this._build_solgpt_promt(prompt)
84+
console.log(main_prompt.length)
6585
result = await(
6686
await fetch(this.api_url, {
6787
method: 'POST',
6888
headers: {
6989
Accept: 'application/json',
7090
'Content-Type': 'application/json',
7191
},
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]}),
7393
})
7494
).json()
7595
} catch (e) {
7696
this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` })
97+
this.solgpt_chat_history = []
7798
return
7899
} finally {
79100
this.emit("aiInferingDone")
80101
}
81102
if (result) {
82103
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()}
83107
} else if (result.error) {
84108
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "Error on request" })
85109
}
@@ -195,4 +219,18 @@ export class SolCoder extends Plugin {
195219
}
196220
}
197221

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+
198236
}

0 commit comments

Comments
 (0)