added file extention context

workspace_completion
STetsing 2 weeks ago
parent 7723356d66
commit 5c062d7f9b
  1. 2
      apps/remix-ide/src/app/plugins/remixAIPlugin.tsx
  2. 18
      libs/remix-ai-core/src/agents/completionAgent.ts
  3. 1
      libs/remix-ai-core/src/inferencers/remote/remoteInference.ts

@ -66,7 +66,6 @@ export class RemixAIPlugin extends ViewPlugin {
}
this.completionAgent = new CodeCompletionAgent(this)
// each 10 seconds update the workspace index
setInterval(() => {
console.log('Indexing workspace')
this.completionAgent.indexWorkspace()
@ -123,7 +122,6 @@ export class RemixAIPlugin extends ViewPlugin {
const currentFile = await this.call('fileManager', 'getCurrentFile')
const contextfiles = await this.completionAgent.getContextFiles()
console.log('completion Context files', contextfiles)
if (this.isOnDesktop && !this.useRemoteInferencer) {
return await this.call(this.remixDesktopPluginName, 'code_completion', prompt, promptAfter)
} else {

@ -25,6 +25,12 @@ export class CodeCompletionAgent {
this.props = props;
this.props.on('fileManager', 'fileAdded', (path) => { });
this.props.on('filePanel', 'workspaceCreated', async () => { });
this.indexer =lunr(function () {
this.ref('id')
this.field('filename')
this.field('content')
this.field('Identifier');
});
}
async getDcocuments() {
@ -45,7 +51,6 @@ export class CodeCompletionAgent {
});
}
}
console.log('Documents', documents);
return documents;
}
@ -69,7 +74,7 @@ export class CodeCompletionAgent {
try {
const currentFile = await this.props.call('fileManager', 'getCurrentFile');
const content = await this.props.call('fileManager', 'readFile', currentFile);
const searchResult = this.indexer.search(content);
const searchResult = this.indexer.search(content)
const fcps = await this.processResults(searchResult, currentFile);
const resolvedFcps = await Promise.all(fcps);
return resolvedFcps;
@ -80,11 +85,12 @@ export class CodeCompletionAgent {
async processResults(results: any, currentFile: string) {
const rmResults = await results.filter(result => {
const document = this.Documents.find(doc => doc.id === Number(result.ref));
return document.filename !== currentFile;
return this.Documents.find(doc => doc.id === Number(result.ref)).filename !== currentFile;
});
const extResults = await rmResults.filter(result => {
return this.Documents.find(doc => doc.id === Number(result.ref)).filename.split('.').pop() === currentFile.split('.').pop();
});
const filteredResults = await rmResults.filter(result => result.score >= this.INDEX_THRESHOLD);
const topResults = filteredResults.slice(0, this.N_MATCHES);
const topResults = await extResults.filter(result => result.score >= this.INDEX_THRESHOLD).slice(0, this.N_MATCHES);
const fileContentPairs = topResults.map(async result => {
const document = this.Documents.find(doc => doc.id === Number(result.ref));

@ -111,7 +111,6 @@ export class RemoteInferencer implements ICompletions {
}
async code_completion(prompt, promptAfter, ctxFiles, fileName, options:IParams=CompletionParams): Promise<any> {
console.log("code_completion", ctxFiles)
const payload = { prompt, 'context':promptAfter, "endpoint":"code_completion",
'ctxFiles':ctxFiles, 'currentFileName':fileName, ...options }
return this._makeRequest(payload, AIRequestType.COMPLETION)

Loading…
Cancel
Save