diff --git a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx index d6d3c78a48..73cd4e489e 100644 --- a/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx +++ b/apps/remix-ide/src/app/plugins/remixAIPlugin.tsx @@ -15,7 +15,7 @@ const profile = { displayName: 'Remix AI', methods: ['code_generation', 'code_completion', "solidity_answer", "code_explaining", - "code_insertion", "error_explaining", + "code_insertion", "error_explaining", "vulnerability_check", "initialize", 'chatPipe', 'ProcessChatRequestBuffer', 'isChatRequestPending'], events: [], icon: 'assets/img/remix-logo-blue.png', @@ -162,6 +162,23 @@ export class RemixAIPlugin extends ViewPlugin { return result } + async vulnerability_check(prompt: string, params: IParams=GenerationParams): Promise { + if (this.isInferencing) { + this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) + return + } + + let result + if (this.isOnDesktop && !this.useRemoteInferencer) { + result = await this.call(this.remixDesktopPluginName, 'vulnerability_check', prompt) + + } else { + result = await this.remoteInferencer.vulnerability_check(prompt) + } + if (result && params.terminal_output) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) + return result + } + async code_insertion(msg_pfx: string, msg_sfx: string): Promise { if (this.isOnDesktop && !this.useRemoteInferencer) { return await this.call(this.remixDesktopPluginName, 'code_insertion', msg_pfx, msg_sfx) @@ -182,11 +199,12 @@ export class RemixAIPlugin extends ViewPlugin { if (fn === "code_explaining") ChatApi.composer.send("Explain the current code") else if (fn === "error_explaining") ChatApi.composer.send("Explain the error") else if (fn === "solidity_answer") ChatApi.composer.send("Answer the following question") - else console.log("chatRequestBuffer is not empty. First process the last request.") + else if (fn === "vulnerability_check") ChatApi.composer.send("Is there any vulnerability in the pasted code?") + else console.log("chatRequestBuffer function name not recognized.") } } else { - console.log("chatRequestBuffer is not empty. First process the last request.") + console.log("chatRequestBuffer is not empty. First process the last request.", this.chatRequestBuffer) } } diff --git a/libs/remix-ai-core/src/inferencers/remote/remoteInference.ts b/libs/remix-ai-core/src/inferencers/remote/remoteInference.ts index f618133a0f..4975f985f9 100644 --- a/libs/remix-ai-core/src/inferencers/remote/remoteInference.ts +++ b/libs/remix-ai-core/src/inferencers/remote/remoteInference.ts @@ -12,7 +12,7 @@ export class RemoteInferencer implements ICompletions { max_history = 7 model_op = RemoteBackendOPModel.CODELLAMA // default model operation change this to llama if necessary event: EventEmitter - test_env=false + test_env=true test_url="http://solcodertest.org" constructor(apiUrl?:string, completionUrl?:string) { @@ -27,7 +27,7 @@ export class RemoteInferencer implements ICompletions { try { const options = { headers: { 'Content-Type': 'application/json', } } - const result = await axios.post(`${requestURL}`, payload, options) + const result = await axios.post(requestURL, payload, options) switch (rType) { case AIRequestType.COMPLETION: @@ -56,7 +56,7 @@ export class RemoteInferencer implements ICompletions { } } - private async _streamInferenceRequest(endpoint, payload, rType:AIRequestType){ + private async _streamInferenceRequest(payload, rType:AIRequestType){ let resultText = "" try { this.event.emit('onInference') @@ -122,26 +122,32 @@ export class RemoteInferencer implements ICompletions { async code_generation(prompt, options:IParams=GenerationParams): Promise { const payload = { prompt, "endpoint":"code_completion", ...options } - if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.COMPLETION) + if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.COMPLETION) else return this._makeRequest(payload, AIRequestType.COMPLETION) } async solidity_answer(prompt, options:IParams=GenerationParams): Promise { const main_prompt = buildSolgptPromt(prompt, this.model_op) const payload = { 'prompt': main_prompt, "endpoint":"solidity_answer", ...options } - if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL) + if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.GENERAL) else return this._makeRequest(payload, AIRequestType.GENERAL) } async code_explaining(prompt, context:string="", options:IParams=GenerationParams): Promise { const payload = { prompt, "endpoint":"code_explaining", context, ...options } - if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL) + if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.GENERAL) else return this._makeRequest(payload, AIRequestType.GENERAL) } async error_explaining(prompt, options:IParams=GenerationParams): Promise { const payload = { prompt, "endpoint":"error_explaining", ...options } - if (options.stream_result) return this._streamInferenceRequest(payload.endpoint, payload, AIRequestType.GENERAL) + if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.GENERAL) + else return this._makeRequest(payload, AIRequestType.GENERAL) + } + + async vulnerability_check(prompt, options:IParams=GenerationParams): Promise { + const payload = { prompt, "endpoint":"vulnerability_check", ...options } + if (options.stream_result) return this._streamInferenceRequest(payload, AIRequestType.GENERAL) else return this._makeRequest(payload, AIRequestType.GENERAL) } } diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 795e274a11..56e9bc273e 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -700,12 +700,12 @@ export const EditorUI = (props: EditorUIProps) => { const pastedCode = editor.getModel().getValueInRange(e.range) const pastedCodePrompt = intl.formatMessage({ id: 'editor.PastedCodeSafety' }, { content:pastedCode }) - // props.plugin.call('remixAI', 'chatPipe', 'solidity_answer', pastedCodePrompt) - const result = props.plugin.call('remixAI', 'solidity_answer', pastedCodePrompt) + props.plugin.call('remixAI', 'chatPipe', 'vulnerability_check', pastedCodePrompt) props.plugin.call('notification', 'alert', modalContent) - pasteCodeRef.current = true + // pasteCodeRef.current = true _paq.push(['trackEvent', 'editor', 'onDidPaste', 'more_than_10_lines']) - console.log('result test:', await result) + // const result = await props.plugin.call('remixAI', 'vulnerability_check', pastedCodePrompt) + // console.log(JSON.parse(result)) } })