From 1294a0bc2e9a4ca6517330f253052af3cb57876e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Wed, 15 May 2024 10:55:45 +0200 Subject: [PATCH 1/3] simple chat in terminal --- apps/remix-ide/src/app/plugins/solcoderAI.tsx | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/plugins/solcoderAI.tsx b/apps/remix-ide/src/app/plugins/solcoderAI.tsx index 99fcbbe0c3..c963699b5c 100644 --- a/apps/remix-ide/src/app/plugins/solcoderAI.tsx +++ b/apps/remix-ide/src/app/plugins/solcoderAI.tsx @@ -19,14 +19,32 @@ const profile = { events: [], maintainedBy: 'Remix', } +type ChatEntry = [string, string]; + +enum BackendOPModel{ + DeeSeek, + CodeLLama, + Mistral +} + +const PromptBuilder = (inst, answr, modelop) => { + if (modelop === BackendOPModel.CodeLLama) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr + if (modelop === BackendOPModel.DeeSeek) return "" + if (modelop === BackendOPModel.Mistral) return "" +} export class SolCoder extends Plugin { api_url: string completion_url: string + solgpt_chat_history:ChatEntry[] + max_history = 7 + model_op = BackendOPModel.CodeLLama + constructor() { super(profile) this.api_url = "https://solcoder.remixproject.org" this.completion_url = "https://completion.remixproject.org" + this.solgpt_chat_history = [] } async code_generation(prompt): Promise { @@ -62,6 +80,8 @@ export class SolCoder extends Plugin { this.call('layout', 'maximizeTerminal') let result try { + const main_prompt = this._build_solgpt_promt(prompt) + console.log(main_prompt.length) result = await( await fetch(this.api_url, { method: 'POST', @@ -69,17 +89,21 @@ export class SolCoder extends Plugin { Accept: 'application/json', 'Content-Type': 'application/json', }, - body: JSON.stringify({ "data":[prompt, "solidity_answer", false,1000,0.9,0.8,50]}), + body: JSON.stringify({ "data":[main_prompt, "solidity_answer", false,1000,0.9,0.8,50]}), }) ).json() } catch (e) { this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) + this.solgpt_chat_history = [] return } finally { this.emit("aiInferingDone") } if (result) { this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.data[0] }) + const chat:ChatEntry = [prompt, result.data[0]] + this.solgpt_chat_history.push(chat) + if (this.solgpt_chat_history.length >this.max_history){this.solgpt_chat_history.shift()} } else if (result.error) { this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "Error on request" }) } @@ -195,4 +219,18 @@ export class SolCoder extends Plugin { } } + _build_solgpt_promt(user_promt:string){ + if (this.solgpt_chat_history.length === 0){ + return user_promt + } else { + let new_promt = "" + for (const [question, answer] of this.solgpt_chat_history) { + new_promt += PromptBuilder(question.split('sol-gpt')[1], answer, this.model_op) + } + // finaly + new_promt = "sol-gpt " + new_promt + PromptBuilder(user_promt.split('sol-gpt')[1], "", this.model_op) + return new_promt + } + } + } From 1f173ae97b89b38610dd33fde6966c8c2a4a21bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Thu, 16 May 2024 15:01:37 +0200 Subject: [PATCH 2/3] changed backend model to deepseek --- apps/remix-ide/src/app/plugins/solcoderAI.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/solcoderAI.tsx b/apps/remix-ide/src/app/plugins/solcoderAI.tsx index c963699b5c..a4ac821b75 100644 --- a/apps/remix-ide/src/app/plugins/solcoderAI.tsx +++ b/apps/remix-ide/src/app/plugins/solcoderAI.tsx @@ -22,14 +22,14 @@ const profile = { type ChatEntry = [string, string]; enum BackendOPModel{ - DeeSeek, + DeepSeek, CodeLLama, Mistral } const PromptBuilder = (inst, answr, modelop) => { if (modelop === BackendOPModel.CodeLLama) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr - if (modelop === BackendOPModel.DeeSeek) return "" + if (modelop === BackendOPModel.DeepSeek) return "" if (modelop === BackendOPModel.Mistral) return "" } @@ -38,7 +38,7 @@ export class SolCoder extends Plugin { completion_url: string solgpt_chat_history:ChatEntry[] max_history = 7 - model_op = BackendOPModel.CodeLLama + model_op = BackendOPModel.DeepSeek constructor() { super(profile) From 15dd5008384d8adfd00963c8dc1da39e046d3d3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Wed, 22 May 2024 10:42:53 +0200 Subject: [PATCH 3/3] changed prompt for chat --- apps/remix-ide/src/app/plugins/solcoderAI.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/solcoderAI.tsx b/apps/remix-ide/src/app/plugins/solcoderAI.tsx index a4ac821b75..da2d439a0e 100644 --- a/apps/remix-ide/src/app/plugins/solcoderAI.tsx +++ b/apps/remix-ide/src/app/plugins/solcoderAI.tsx @@ -28,8 +28,8 @@ enum BackendOPModel{ } const PromptBuilder = (inst, answr, modelop) => { - if (modelop === BackendOPModel.CodeLLama) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr - if (modelop === BackendOPModel.DeepSeek) return "" + if (modelop === BackendOPModel.CodeLLama) return "" + if (modelop === BackendOPModel.DeepSeek) return "\n### INSTRUCTION:\n" + inst + "\n### RESPONSE:\n" + answr if (modelop === BackendOPModel.Mistral) return "" }