diff --git a/apps/remix-ide/src/app.js b/apps/remix-ide/src/app.js index cceb3ec091..33e0e4d4cb 100644 --- a/apps/remix-ide/src/app.js +++ b/apps/remix-ide/src/app.js @@ -59,7 +59,7 @@ import { ripgrepPlugin } from './app/plugins/electron/ripgrepPlugin' import { compilerLoaderPlugin, compilerLoaderPluginDesktop } from './app/plugins/electron/compilerLoaderPlugin' import {OpenAIGpt} from './app/plugins/openaigpt' -import {SolCodeComp} from './app/plugins/solcode_completion' +import {SolCoder} from './app/plugins/solcoderAI' const isElectron = require('is-electron') @@ -234,7 +234,7 @@ class AppComponent { // ----------------- AI -------------------------------------- const openaigpt = new OpenAIGpt() - const solcodercomp = new SolCodeComp() + const solcoder = new SolCoder() const copilotSuggestion = new CopilotSuggestion() // ----------------- import content service ------------------------ @@ -362,7 +362,7 @@ class AppComponent { solidityScript, templates, openaigpt, - solcodercomp, + solcoder, copilotSuggestion ]) @@ -518,7 +518,7 @@ class AppComponent { } ) await this.appManager.activatePlugin(['solidity-script', 'openaigpt']) - await this.appManager.activatePlugin(['solcodercomp']) + await this.appManager.activatePlugin(['solcoder']) diff --git a/apps/remix-ide/src/app/plugins/solcode_completion.tsx b/apps/remix-ide/src/app/plugins/solcode_completion.tsx deleted file mode 100644 index 76b4bec519..0000000000 --- a/apps/remix-ide/src/app/plugins/solcode_completion.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { Plugin } from '@remixproject/engine' -import { client } from "@gradio/client" - -const _paq = (window._paq = window._paq || []) - -const profile = { - name: 'solcoder_completion', - displayName: 'solcoder_completion', - description: 'solcoder_completion', - methods: ['message'], - events: [], - maintainedBy: 'Remix', -} - -export class SolCodeComp extends Plugin { - constructor() { - super(profile) - } - - async message(prompt): Promise { - this.call('layout', 'maximizeTerminal') - this.call('terminal', 'log', 'Waiting for GPT answer...') - let result - try { - const app = await client("http://127.0.0.1:7860/", null); - const result = await app.predict("/code_completion", [ - prompt, // string in 'context_code' Textbox component - "", // string in 'comment' Textbox component - false, // boolean in 'stream_result' Checkbox component - 200, // number (numeric value between 0 and 2000) in 'max_new_tokens' Slider component - 0.4, // number (numeric value between 0.01 and 1) in 'temperature' Slider component - 0.90, // number (numeric value between 0 and 1) in 'top_p' Slider component - 50, // number (numeric value between 1 and 200) in 'top_k' Slider component - ]); - return result - } catch (e) { - this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) - return - } - } -} diff --git a/apps/remix-ide/src/app/plugins/solcoderAI.tsx b/apps/remix-ide/src/app/plugins/solcoderAI.tsx new file mode 100644 index 0000000000..65b7040306 --- /dev/null +++ b/apps/remix-ide/src/app/plugins/solcoderAI.tsx @@ -0,0 +1,77 @@ +import { Plugin } from '@remixproject/engine' + +const _paq = (window._paq = window._paq || []) + +const profile = { + name: 'solcoder', + displayName: 'solcoder', + description: 'solcoder', + methods: ['code_generation', 'code_completion'], + events: [], + maintainedBy: 'Remix', +} + +export class SolCoder extends Plugin { + constructor() { + super(profile) + } + + async code_generation(prompt): Promise { + this.call('layout', 'maximizeTerminal') + this.call('terminal', 'log', 'Waiting for Solcoder answer...') + let result + try { + result = await( + await fetch("https://hkfll35zthu6e2-7861.proxy.runpod.net/api/code_generation", { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({"data":[prompt,false,1000,0.2,0.8,50]}), + }) + ).json() + } catch (e) { + this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) + return + } + if (result) { + this.call('terminal', 'log', { type: 'typewriterwarning', value: result.data[0]}) + } else if (result.error) { + this.call('terminal', 'log', { type: 'typewriterwarning', value: "Error on request" }) + } + + } + + + async code_completion(prompt): Promise { + let result + try { + result = await( + await fetch("https://hkfll35zthu6e2-7861.proxy.runpod.net/api/code_completion", { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({"data":[ + prompt, // string in 'context_code' Textbox component + "", // string in 'comment' Textbox component + false, // boolean in 'stream_result' Checkbox component + 200, // number (numeric value between 0 and 2000) in 'max_new_tokens' Slider component + 0.4, // number (numeric value between 0.01 and 1) in 'temperature' Slider component + 0.90, // number (numeric value between 0 and 1) in 'top_p' Slider component + 50, // number (numeric value between 1 and 200) in 'top_k' Slider component + ]}), + }) + ).json() + + console.log('solcoder result', result.data) + return result.data + } catch (e) { + this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) + return + } + } + +} diff --git a/apps/remix-ide/src/remixAppManager.js b/apps/remix-ide/src/remixAppManager.js index 19716a2f84..d55a27a560 100644 --- a/apps/remix-ide/src/remixAppManager.js +++ b/apps/remix-ide/src/remixAppManager.js @@ -77,6 +77,7 @@ let requiredModules = [ // services + layout views + system views 'contractflattener', 'solidity-script', 'openaigpt', + 'solcoder', 'home', 'doc-viewer', 'doc-gen', diff --git a/apps/remix-ide/src/remixEngine.js b/apps/remix-ide/src/remixEngine.js index 5c0657ce22..1e416d0066 100644 --- a/apps/remix-ide/src/remixEngine.js +++ b/apps/remix-ide/src/remixEngine.js @@ -26,6 +26,7 @@ export class RemixEngine extends Engine { if (name === 'compilerloader') return { queueTimeout: 60000 * 4 } if (name === 'filePanel') return { queueTimeout: 60000 * 20 } if (name === 'openaigpt') return { queueTimeout: 60000 * 2 } + if (name === 'solcoder') return { queueTimeout: 60000 * 2 } if (name === 'cookbookdev') return { queueTimeout: 60000 * 2 } return { queueTimeout: 10000 } } diff --git a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts index 5de52f2b63..c6e0c19515 100644 --- a/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/inlineCompletionProvider.ts @@ -43,8 +43,9 @@ export class RemixInLineCompletionProvider implements monacoTypes.languages.Inli if (split[split.length - 1].trim() === '' && ask.startsWith('///')) { // use the code generation model - const {data} = await this.props.plugin.call('solcoder_completion', 'message', ask) - const parsedData = JSON.parse(data).trimStart() + const data = await this.props.plugin.call('solcoder', 'code_completion', word) + console.log("received solcoder data", data) + const parsedData = data[0].trimStart() //JSON.parse(data).trimStart() const item: monacoTypes.languages.InlineCompletion = { insertText: parsedData }; diff --git a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx index 2f5caaf9ac..3a35adbf08 100644 --- a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx +++ b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx @@ -239,7 +239,11 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { call('terminal', 'log',{ type: 'warn', value: `> ${script}` }) await call('openaigpt', 'message', script) _paq.push(['trackEvent', 'ai', 'openai', 'askFromTerminal']) - } else { + } else if (script.trim().startsWith('gpt-sol')) { + call('terminal', 'log',{ type: 'warn', value: `> ${script}` }) + await call('solcoder', 'code_generation', script) + _paq.push(['trackEvent', 'ai', 'solcoder', 'askFromTerminal']) + }else { await call('scriptRunner', 'execute', script) } done()