single request Remix AI except completions

pull/5370/head
Stéphane Tetsing 7 months ago
parent c3335b6d82
commit 9ef419b1ca
  1. 46
      apps/remix-ide/src/app/plugins/remixAIPlugin.tsx
  2. 14
      apps/remixdesktop/src/plugins/remixAIDektop.ts

@ -50,14 +50,31 @@ export class RemixAIPlugin extends ViewPlugin {
async initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel){ async initialize(model1?:IModel, model2?:IModel, remoteModel?:IRemoteModel){
if (this.isOnDesktop) { if (this.isOnDesktop) {
this.call(this.remixDesktopPluginName, 'initializeModelBackend', false, model1, model2) const res = await this.call(this.remixDesktopPluginName, 'initializeModelBackend', false, model1, model2)
this.on(this.remixDesktopPluginName, 'onStreamResult', (value) => { if (res) {
this.call('terminal', 'log', { type: 'log', value: value }) this.on(this.remixDesktopPluginName, 'onStreamResult', (value) => {
}) this.call('terminal', 'log', { type: 'log', value: value })
})
this.on(this.remixDesktopPluginName, 'onInference', () => {
this.isInferencing = true
})
this.on(this.remixDesktopPluginName, 'onInferenceDone', () => {
this.isInferencing = false
})
}
} else { } else {
// on browser // on browser
console.log('Initializing RemixAIPlugin on browser') console.log('Initializing RemixAIPlugin on browser')
this.remoteInferencer = new RemoteInferencer(remoteModel?.apiUrl, remoteModel?.completionUrl) this.remoteInferencer = new RemoteInferencer(remoteModel?.apiUrl, remoteModel?.completionUrl)
this.remoteInferencer.event.on('onInference', () => {
this.isInferencing = true
})
this.remoteInferencer.event.on('onInferenceDone', () => {
this.isInferencing = false
})
} }
this.aiIsActivated = true this.aiIsActivated = true
@ -65,7 +82,11 @@ export class RemixAIPlugin extends ViewPlugin {
} }
async code_generation(prompt: string): Promise<any> { async code_generation(prompt: string): Promise<any> {
console.log('code_generation') if (this.isInferencing) {
this.call('terminal', 'log', { type: 'aitypewriterwarning', value: "RemixAI is already busy!" })
return
}
if (this.isOnDesktop) { if (this.isOnDesktop) {
return await this.call(this.remixDesktopPluginName, 'code_generation', prompt) return await this.call(this.remixDesktopPluginName, 'code_generation', prompt)
} else { } else {
@ -82,6 +103,11 @@ export class RemixAIPlugin extends ViewPlugin {
} }
async solidity_answer(prompt: string): Promise<any> { async solidity_answer(prompt: string): 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...` }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` })
let result let result
@ -95,6 +121,11 @@ export class RemixAIPlugin extends ViewPlugin {
} }
async code_explaining(prompt: string): Promise<any> { async code_explaining(prompt: string): 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...` }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` })
let result let result
@ -109,6 +140,11 @@ export class RemixAIPlugin extends ViewPlugin {
} }
async error_explaining(prompt: string): Promise<any> { async error_explaining(prompt: string): 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...` }) this.call('terminal', 'log', { type: 'aitypewriterwarning', value: `\n\nWaiting for RemixAI answer...` })
let result let result

@ -68,15 +68,18 @@ class RemixAIDesktopPluginClient extends ElectronBasePluginClient {
if (local){ if (local){
console.log('Initializing Inference model locally') console.log('Initializing Inference model locally')
this.desktopInferencer = new RemoteInferencer() this.desktopInferencer = new RemoteInferencer()
} else { } else if (generalModel || completionModel){
if (!this.desktopInferencer){ if (!this.desktopInferencer){
console.log('Initializing Inference model') console.log('Initializing Inference model')
this.desktopInferencer = InferenceManager.getInstance(this.modelCacheDir) this.desktopInferencer = InferenceManager.getInstance(this.modelCacheDir)
if (this.desktopInferencer instanceof InferenceManager && generalModel) await this.desktopInferencer.init(generalModel)
if (this.desktopInferencer instanceof InferenceManager && completionModel) await this.desktopInferencer.init(completionModel)
} else { } else {
console.log('Inference model already initialized') console.log('Inference model already initialized')
return false // do not set event listener twice
} }
if (this.desktopInferencer instanceof InferenceManager && generalModel) await this.desktopInferencer.init(generalModel) } else {
if (this.desktopInferencer instanceof InferenceManager && completionModel) await this.desktopInferencer.init(completionModel) throw new Error('No model provided')
} }
// set event listeners // set event listeners
@ -86,9 +89,10 @@ class RemixAIDesktopPluginClient extends ElectronBasePluginClient {
this.desktopInferencer.event.on('onInference', () => { this.desktopInferencer.event.on('onInference', () => {
this.emit('onInference') this.emit('onInference')
}) })
this.desktopInferencer.event.on('onInfrenceDone', () => { this.desktopInferencer.event.on('onInferenceDone', () => {
this.emit('onInfrenceDone') this.emit('onInferenceDone')
}) })
return true
} }
async code_completion(context: any) { async code_completion(context: any) {

Loading…
Cancel
Save