-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remixai chat #5241
Merged
Merged
Remixai chat #5241
Changes from 32 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
edfb3bd
initial chat
STetsing 1e68ae0
initiall
STetsing 118d66e
nlux chat working local
STetsing abeac7d
linked explain to remix ai output
STetsing 4c843e9
directed all logs to chat element
STetsing ad70e5e
styled the chat interface
STetsing 39e89ab
turned remote to live
STetsing 52408f3
minor
STetsing 1348d1f
minor fix docs
STetsing 2695aaf
Merge branch 'master' into remixai__chat
STetsing 1743146
api ai desktop
STetsing 8c11a35
Merge branch 'master' into remixai__chat
LianaHus 2b0f7a2
cleanup and new send button on remixai chat
STetsing 0d0dbd1
Merge branch 'remixai__chat' of https://github.com/ethereum/remix-pro…
STetsing 5b69872
fixed lint
STetsing b6eeacf
enforced insertion on completion
STetsing 917f562
minor
STetsing 9d782ea
minor
STetsing d2d68ce
Merge branch 'master' into remixai__chat
STetsing bfa5eda
enable forward stability
STetsing 6e5ed32
Merge branch 'remixai__chat' of https://github.com/ethereum/remix-pro…
STetsing 707699b
fixed streaming error leaving out some text in chat UI
STetsing b237be8
matomo back in
STetsing e89e938
off rexix AI when starting
STetsing dd061e5
minor
STetsing 2d4fbb5
enable remixai remote on desktop
STetsing 8968ce6
remixai remote inference working on desktop
STetsing 51c4fbd
improving completion process
STetsing f964671
improving completion process
STetsing e33392f
improving completion process
STetsing 5f0dc4d
enabled completion at string begin
STetsing 0f0809e
Merge branch 'master' into remixai__chat
STetsing d52765b
Update remixAIPlugin.tsx rm setting to side panel
STetsing a18460d
Merge branch 'master' into remixai__chat
STetsing 09db2ad
Merge branch 'master' into remixai__chat
STetsing f5e116e
Merge branch 'master' into remixai__chat
Aniket-Engg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,77 @@ | ||
import * as packageJson from '../../../../../package.json' | ||
import { ViewPlugin } from '@remixproject/engine-web' | ||
import { Plugin } from '@remixproject/engine'; | ||
import { RemixAITab } from '@remix-ui/remix-ai' | ||
import React from 'react'; | ||
import { ICompletions, IModel, RemoteInferencer, IRemoteModel } from '@remix/remix-ai-core'; | ||
import { RemixAITab, ChatApi } from '@remix-ui/remix-ai' | ||
import React, { useCallback } from 'react'; | ||
import { ICompletions, IModel, RemoteInferencer, IRemoteModel, IParams, GenerationParams, CodeExplainAgent } from '@remix/remix-ai-core'; | ||
import { CustomRemixApi } from '@remix-api' | ||
|
||
type chatRequestBufferT<T> = { | ||
[key in keyof T]: T[key] | ||
} | ||
|
||
const profile = { | ||
name: 'remixAI', | ||
displayName: 'Remix AI', | ||
methods: ['code_generation', 'code_completion', | ||
"solidity_answer", "code_explaining", | ||
"code_insertion", "error_explaining", | ||
"initialize"], | ||
"initialize", 'chatPipe', 'ProcessChatRequestBuffer', 'isChatRequestPending'], | ||
events: [], | ||
icon: 'assets/img/remix-logo-blue.png', | ||
description: 'RemixAI provides AI services to Remix IDE.', | ||
kind: '', | ||
// location: 'sidePanel', | ||
location: 'sidePanel', | ||
documentation: 'https://remix-ide.readthedocs.io/en/latest/remixai.html', | ||
version: packageJson.version, | ||
maintainedBy: 'Remix' | ||
} | ||
|
||
export class RemixAIPlugin extends Plugin { | ||
// add Plugin<any, CustomRemixApi> | ||
export class RemixAIPlugin extends ViewPlugin { | ||
isOnDesktop:boolean = false | ||
aiIsActivated:boolean = false | ||
readonly remixDesktopPluginName = 'remixAID' | ||
remoteInferencer:RemoteInferencer = null | ||
isInferencing: boolean = false | ||
chatRequestBuffer: chatRequestBufferT<any> = null | ||
agent: CodeExplainAgent | ||
useRemoteInferencer:boolean = false | ||
|
||
constructor(inDesktop:boolean) { | ||
super(profile) | ||
this.isOnDesktop = inDesktop | ||
|
||
this.agent = new CodeExplainAgent(this) | ||
// user machine dont use ressource for remote inferencing | ||
} | ||
|
||
onActivation(): void { | ||
this.initialize(null, null, null, false) | ||
if (this.isOnDesktop) { | ||
console.log('Activating RemixAIPlugin on desktop') | ||
// this.on(this.remixDesktopPluginName, 'activated', () => { | ||
this.useRemoteInferencer = true | ||
this.initialize(null, null, null, this.useRemoteInferencer); | ||
// }) | ||
} else { | ||
console.log('Activating RemixAIPlugin on browser') | ||
this.useRemoteInferencer = true | ||
this.initialize() | ||
} | ||
// this.setRemixAIOnSidePannel(false) | ||
} | ||
|
||
setRemixAIOnSidePannel(resize:boolean=false){ | ||
if (resize){ | ||
this.call('sidePanel', 'pinView', profile) | ||
|
||
} else { | ||
this.call('sidePanel', 'pinView', profile) | ||
} | ||
} | ||
|
||
async initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel, useRemote?:boolean){ | ||
if (this.isOnDesktop) { | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
// on desktop use remote inferencer -> false | ||
console.log('initialize on desktop') | ||
const res = await this.call(this.remixDesktopPluginName, 'initializeModelBackend', useRemote, model1, model2) | ||
if (res) { | ||
this.on(this.remixDesktopPluginName, 'onStreamResult', (value) => { | ||
|
@@ -60,7 +88,6 @@ export class RemixAIPlugin extends Plugin { | |
} | ||
|
||
} else { | ||
// on browser | ||
this.remoteInferencer = new RemoteInferencer(remoteModel?.apiUrl, remoteModel?.completionUrl) | ||
this.remoteInferencer.event.on('onInference', () => { | ||
this.isInferencing = true | ||
|
@@ -80,90 +107,117 @@ export class RemixAIPlugin extends Plugin { | |
return | ||
} | ||
|
||
if (this.isOnDesktop) { | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
return await this.call(this.remixDesktopPluginName, 'code_generation', prompt) | ||
} else { | ||
return await this.remoteInferencer.code_generation(prompt) | ||
} | ||
} | ||
|
||
async code_completion(prompt: string, promptAfter: string): Promise<any> { | ||
if (this.isOnDesktop) { | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
return await this.call(this.remixDesktopPluginName, 'code_completion', prompt, promptAfter) | ||
} else { | ||
return await this.remoteInferencer.code_completion(prompt, promptAfter) | ||
} | ||
} | ||
|
||
async solidity_answer(prompt: string): Promise<any> { | ||
async solidity_answer(prompt: string, params: IParams=GenerationParams): Promise<any> { | ||
if (this.isInferencing) { | ||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) | ||
return | ||
} | ||
|
||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) | ||
|
||
const newPrompt = await this.agent.chatCommand(prompt) | ||
let result | ||
if (this.isOnDesktop) { | ||
result = await this.call(this.remixDesktopPluginName, 'solidity_answer', prompt) | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
result = await this.call(this.remixDesktopPluginName, 'solidity_answer', newPrompt) | ||
} else { | ||
result = await this.remoteInferencer.solidity_answer(prompt) | ||
result = await this.remoteInferencer.solidity_answer(newPrompt) | ||
} | ||
if (result) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) | ||
// this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI Done" }) | ||
if (result && params.terminal_output) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) | ||
return result | ||
} | ||
|
||
async code_explaining(prompt: string): Promise<any> { | ||
async code_explaining(prompt: string, context: string, params: IParams=GenerationParams): Promise<any> { | ||
if (this.isInferencing) { | ||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) | ||
return | ||
} | ||
|
||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) | ||
|
||
let result | ||
if (this.isOnDesktop) { | ||
result = await this.call(this.remixDesktopPluginName, 'code_explaining', prompt) | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
result = await this.call(this.remixDesktopPluginName, 'code_explaining', prompt, context, params) | ||
|
||
} else { | ||
result = await this.remoteInferencer.code_explaining(prompt) | ||
result = await this.remoteInferencer.code_explaining(prompt, context, params) | ||
} | ||
if (result) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) | ||
// this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI Done" }) | ||
if (result && params.terminal_output) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) | ||
return result | ||
} | ||
|
||
async error_explaining(prompt: string): Promise<any> { | ||
async error_explaining(prompt: string, context: string="", params: IParams=GenerationParams): Promise<any> { | ||
if (this.isInferencing) { | ||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" }) | ||
return | ||
} | ||
|
||
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` }) | ||
|
||
let result | ||
if (this.isOnDesktop) { | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
result = await this.call(this.remixDesktopPluginName, 'error_explaining', prompt) | ||
} else { | ||
result = await this.remoteInferencer.error_explaining(prompt) | ||
result = await this.remoteInferencer.error_explaining(prompt, params) | ||
} | ||
if (result) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: result }) | ||
// this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI Done" }) | ||
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<any> { | ||
if (this.isOnDesktop) { | ||
if (this.isOnDesktop && !this.useRemoteInferencer) { | ||
return await this.call(this.remixDesktopPluginName, 'code_insertion', msg_pfx, msg_sfx) | ||
} else { | ||
return await this.remoteInferencer.code_insertion(msg_pfx, msg_sfx) | ||
} | ||
} | ||
|
||
// render() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need those? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This goes out from this PR |
||
// return ( | ||
// <RemixAITab plugin={this}></RemixAITab> | ||
// ) | ||
// } | ||
chatPipe(fn, prompt: string, context?: string, pipeMessage?: string){ | ||
if (this.chatRequestBuffer == null){ | ||
this.chatRequestBuffer = { | ||
fn_name: fn, | ||
prompt: prompt, | ||
context: context | ||
} | ||
if (pipeMessage) ChatApi.composer.send(pipeMessage) | ||
else { | ||
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 { | ||
console.log("chatRequestBuffer is not empty. First process the last request.") | ||
} | ||
} | ||
|
||
async ProcessChatRequestBuffer(params:IParams=GenerationParams){ | ||
if (this.chatRequestBuffer != null){ | ||
const result = this[this.chatRequestBuffer.fn_name](this.chatRequestBuffer.prompt, this.chatRequestBuffer.context, params) | ||
this.chatRequestBuffer = null | ||
return result | ||
} | ||
else { | ||
console.log("chatRequestBuffer is empty.") | ||
return "" | ||
} | ||
} | ||
isChatRequestPending(){ | ||
return this.chatRequestBuffer != null | ||
} | ||
|
||
render() { | ||
return ( | ||
<RemixAITab plugin={this}></RemixAITab> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
andelse
are doing the same thing.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Waiting for some answers from David to resize the sidepanel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will remove it from there anyway, you don't need to do this @STetsing