added local import files to context

workspace_completion
STetsing 4 days ago
parent 3232af0877
commit 8f4ad2398b
  1. 32
      libs/remix-ai-core/src/agents/completionAgent.ts
  2. 2
      libs/remix-ai-core/src/inferencers/remote/remoteInference.ts

@ -74,6 +74,30 @@ export class CodeCompletionAgent {
}
}
async getLocalImports(fileContent: string, currentFile: string) {
try {
const lines = fileContent.split('\n');
const imports = [];
for (const line of lines) {
const trimmedLine = line.trim();
if (trimmedLine.startsWith('import')) {
const parts = trimmedLine.split(' ');
if (parts.length >= 2) {
const importPath = parts[1].replace(/['";]/g, '');
imports.push(importPath);
}
}
}
// Only local imports are those files that are in the workspace
const localImports = this.Documents.length >0 ? imports.filter((imp) => {return this.Documents.find((doc) => doc.filename === imp);}) : [];
return localImports;
} catch (error) {
return [];
}
}
indexWorkspace() {
this.getDcocuments().then((documents) => {
this.indexer =lunr(function () {
@ -131,6 +155,14 @@ export class CodeCompletionAgent {
const currentContent = await this.props.call('fileManager', 'readFile', document.filename);
return { file: document.filename, content: currentContent };
});
const localImports = await this.getLocalImports(await this.props.call('fileManager', 'readFile', currentFile), currentFile);
// check if the local import is in fileContentPairs file
for (const li of localImports) {
if (fileContentPairs.find(fcp => fcp.file === li)) continue;
const currentContent = await this.props.call('fileManager', 'readFile', li);
fileContentPairs.push({ file: li, content: currentContent });
}
return fileContentPairs;
}

@ -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) {

Loading…
Cancel
Save