moved refinement to backend

workspace_completion
STetsing 7 days ago
parent d68b0a5f3d
commit 9c03ba221b
  1. 13
      apps/remix-ide/src/app/plugins/remixAIPlugin.tsx
  2. 28
      libs/remix-ai-core/src/agents/completionAgent.ts

@ -113,12 +113,10 @@ export class RemixAIPlugin extends ViewPlugin {
const currentFile = await this.call('fileManager', 'getCurrentFile')
const contextfiles = await this.completionAgent.getContextFiles(prompt)
const refined = CodeCompletionAgent.refineContext(prompt, promptAfter)
console.log('contextfiles', contextfiles)
if (this.isOnDesktop && !this.useRemoteInferencer) {
return await this.call(this.remixDesktopPluginName, 'code_completion', refined[0], refined[1])
return await this.call(this.remixDesktopPluginName, 'code_completion', prompt, promptAfter)
} else {
return await this.remoteInferencer.code_completion(refined[0], refined[1], contextfiles, currentFile)
return await this.remoteInferencer.code_completion(prompt, promptAfter, contextfiles, currentFile)
}
}
@ -180,13 +178,12 @@ export class RemixAIPlugin extends ViewPlugin {
if (this.completionAgent.indexer == null || this.completionAgent.indexer == undefined) await this.completionAgent.indexWorkspace()
const currentFile = await this.call('fileManager', 'getCurrentFile')
const contextfiles = this.completionAgent.getContextFiles(msg_pfx)
const refined = CodeCompletionAgent.refineContext(msg_pfx, msg_sfx)
const contextfiles = await this.completionAgent.getContextFiles(msg_pfx)
if (this.isOnDesktop && !this.useRemoteInferencer) {
return await this.call(this.remixDesktopPluginName, 'code_insertion', refined[0], refined[1])
return await this.call(this.remixDesktopPluginName, 'code_insertion', msg_pfx, msg_sfx)
} else {
return await this.remoteInferencer.code_insertion(refined[0], refined[1], contextfiles, currentFile)
return await this.remoteInferencer.code_insertion( msg_pfx, msg_sfx, contextfiles, currentFile)
}
}

@ -130,32 +130,4 @@ export class CodeCompletionAgent {
return fileContentPairs;
}
// TODO rm context files length
static refineContext(words1: string, words2: string, maxWords: number=6500) {
// Avoid model out of context
const totalWords = words1.length + words2.length;
if (totalWords <= maxWords) {
return [words1, words2];
}
const halfMaxWords = Math.floor(maxWords / 2);
let takeFromText1 = words1.length < halfMaxWords ? words1.length : halfMaxWords;
let takeFromText2 = words2.length < halfMaxWords ? words2.length : halfMaxWords;
// Adjust if one text is taking more than half, we balance by limiting the other text
if (words1.length < halfMaxWords && words2.length + words1.length <= maxWords) {
takeFromText2 = Math.min(words2.length, maxWords - words1.length);
} else if (words2.length < halfMaxWords && words1.length + words2.length <= maxWords) {
takeFromText1 = Math.min(words1.length, maxWords - words2.length);
} else if (words1.length < halfMaxWords && words2.length + words1.length >= maxWords) {
takeFromText2 = Math.min(words2.length, maxWords - words1.length);
} else if (words2.length > halfMaxWords && words1.length + words2.length <= maxWords) {
takeFromText1 = Math.min(words1.length, maxWords - words2.length);
}
const splicedText1 = words1.slice(words1.length - takeFromText1);
const splicedText2 = words2.slice(words2.length - takeFromText2);
return [splicedText1 , splicedText2]
}
}

Loading…
Cancel
Save