From a1f44f6123448b9f2b641c574f5f183c2fbef954 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Tetsing?= Date: Wed, 22 May 2024 14:13:08 +0200 Subject: [PATCH] switched open gpt to solcoder for error explaining --- .../src/app/components/feedbackAlert.tsx | 2 +- apps/remix-ide/src/app/plugins/solcoderAI.tsx | 31 ++++++++++++++++++- apps/vyper/src/app/utils/remix-client.tsx | 5 ++- libs/remix-ui/renderer/src/lib/renderer.tsx | 6 ++-- .../terminal/src/lib/remix-ui-terminal.tsx | 5 +-- .../terminal/src/lib/terminalWelcome.tsx | 3 -- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/apps/circuit-compiler/src/app/components/feedbackAlert.tsx b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx index 3edf89cc20..5bc7114520 100644 --- a/apps/circuit-compiler/src/app/components/feedbackAlert.tsx +++ b/apps/circuit-compiler/src/app/components/feedbackAlert.tsx @@ -24,7 +24,7 @@ export function FeedbackAlert ({ message, askGPT }: FeedbackAlertProps) { { e.stopPropagation() askGPT() - }}>ASK GPT + }}>ASK SOL-GPT diff --git a/apps/remix-ide/src/app/plugins/solcoderAI.tsx b/apps/remix-ide/src/app/plugins/solcoderAI.tsx index 94687d3440..44e7a8121e 100644 --- a/apps/remix-ide/src/app/plugins/solcoderAI.tsx +++ b/apps/remix-ide/src/app/plugins/solcoderAI.tsx @@ -15,7 +15,7 @@ const profile = { name: 'solcoder', displayName: 'solcoder', description: 'solcoder', - methods: ['code_generation', 'code_completion', "solidity_answer", "code_explaining", "code_insertion"], + methods: ['code_generation', 'code_completion', "solidity_answer", "code_explaining", "code_insertion", "error_explaining"], events: [], maintainedBy: 'Remix', } @@ -218,6 +218,35 @@ export class SolCoder extends Plugin { } } + async error_explaining(prompt): Promise { + this.emit("aiInfering") + this.call('layout', 'maximizeTerminal') + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for SOL-GPT answer...` }) + + let result + try { + result = await( + await fetch(this.api_url, { + method: 'POST', + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ "data":[prompt, "error_explaining", false,2000,0.9,0.8,50]}), + }) + ).json() + if (result) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result.data[0] }) + } + return result.data[0] + } catch (e) { + this.call('terminal', 'log', { type: 'typewritererror', value: `Unable to get a response ${e.message}` }) + return + } finally { + this.emit("aiInferingDone") + } + } + _build_solgpt_promt(user_promt:string){ if (this.solgpt_chat_history.length === 0){ return user_promt diff --git a/apps/vyper/src/app/utils/remix-client.tsx b/apps/vyper/src/app/utils/remix-client.tsx index 088aa6c36d..3de036f352 100644 --- a/apps/vyper/src/app/utils/remix-client.tsx +++ b/apps/vyper/src/app/utils/remix-client.tsx @@ -5,6 +5,7 @@ import {PluginClient} from '@remixproject/plugin' import {Contract, compileContract} from './compiler' import {ExampleContract} from '../components/VyperResult' import EventEmitter from 'events' +const _paq = (window._paq = window._paq || []) export type VyperComplierAddress = 'https://vyper2.remixproject.org/' | 'http://localhost:8000/' @@ -66,11 +67,13 @@ export class RemixClient extends PluginClient { return } try { + // TODO: remove! no formatting required since already handled on server const formattedMessage = ` ${message} can you explain why this error occurred and how to fix it? ` - await this.client.call('openaigpt' as any, 'message', formattedMessage) + await this.client.call('solcoder' as any, 'error_explaining', message) + _paq.push(['trackEvent', 'ai', 'solcoder', 'error_explaining']) } catch (err) { console.error('unable to askGpt') console.error(err) diff --git a/libs/remix-ui/renderer/src/lib/renderer.tsx b/libs/remix-ui/renderer/src/lib/renderer.tsx index 00a7af8ab3..6d830a8230 100644 --- a/libs/remix-ui/renderer/src/lib/renderer.tsx +++ b/libs/remix-ui/renderer/src/lib/renderer.tsx @@ -75,8 +75,8 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => { try { const content = await plugin.call('fileManager', 'readFile', editorOptions.errFile) const message = intl.formatMessage({ id: 'solidity.openaigptMessage' }, { content, messageText }) - await plugin.call('openaigpt', 'message', message) - _paq.push(['trackEvent', 'ai', 'openai', 'explainSolidityError']) + await plugin.call('solcoder', 'error_explaining', message) + _paq.push(['trackEvent', 'ai', 'solcoder', 'error_explaining_SolidityError']) } catch (err) { console.error('unable to askGtp') console.error(err) @@ -111,7 +111,7 @@ export const Renderer = ({ message, opt = {}, plugin }: RendererProps) => { onClick={() => { askGtp() }} style={{ borderColor: "var(--ai)" }} > - ASK GPT + ASK SOL-GPT 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 b5edd8a425..7936cda55e 100644 --- a/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx +++ b/libs/remix-ui/terminal/src/lib/remix-ui-terminal.tsx @@ -235,10 +235,11 @@ export const RemixUiTerminal = (props: RemixUiTerminalProps) => { try { if (script.trim().startsWith('git')) { // await this.call('git', 'execute', script) code might be used in the future + // TODO: rm gpt or redirect gpt to sol-pgt } else if (script.trim().startsWith('gpt')) { call('terminal', 'log',{ type: 'warn', value: `> ${script}` }) - await call('openaigpt', 'message', script) - _paq.push(['trackEvent', 'ai', 'openai', 'askFromTerminal']) + await call('solcoder', 'solidity_answer', script) + _paq.push(['trackEvent', 'ai', 'solcoder', 'askFromTerminal']) } else if (script.trim().startsWith('sol-gpt')) { call('terminal', 'log',{ type: 'warn', value: `> ${script}` }) await call('solcoder', 'solidity_answer', script) diff --git a/libs/remix-ui/terminal/src/lib/terminalWelcome.tsx b/libs/remix-ui/terminal/src/lib/terminalWelcome.tsx index 7fb7dbea23..1d1dcf77c8 100644 --- a/libs/remix-ui/terminal/src/lib/terminalWelcome.tsx +++ b/libs/remix-ui/terminal/src/lib/terminalWelcome.tsx @@ -54,9 +54,6 @@ const TerminalWelcomeMessage = ({ packageJson, storage }) => { ethers.js {' '} -
  • - gpt <your question here> {' '} -
  • sol-gpt <your Solidity question here> {' '}