handle relative folders in default context
This commit is contained in:
parent
6fbc6c9703
commit
12a8dc6cd5
2 changed files with 30 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ import {
|
|||
ContextProviderExtras,
|
||||
} from "../../index.js";
|
||||
import TransformersJsEmbeddingsProvider from "../../indexing/embeddings/TransformersJsEmbeddingsProvider.js";
|
||||
import { resolveRelativePathInWorkspace } from "../../util/ideUtils.js";
|
||||
import { getRelativePath } from "../../util/index.js";
|
||||
import { RetrievalPipelineOptions } from "./pipelines/BaseRetrievalPipeline.js";
|
||||
import NoRerankerRetrievalPipeline from "./pipelines/NoRerankerRetrievalPipeline.js";
|
||||
|
|
@ -66,6 +67,14 @@ export async function retrieveContextItemsFromEmbeddings(
|
|||
? RerankerRetrievalPipeline
|
||||
: NoRerankerRetrievalPipeline;
|
||||
|
||||
if (filterDirectory) {
|
||||
// Handle relative paths
|
||||
filterDirectory = await resolveRelativePathInWorkspace(
|
||||
filterDirectory,
|
||||
extras.ide,
|
||||
);
|
||||
}
|
||||
|
||||
const pipelineOptions: RetrievalPipelineOptions = {
|
||||
nFinal,
|
||||
nRetrieve,
|
||||
|
|
|
|||
21
core/util/ideUtils.ts
Normal file
21
core/util/ideUtils.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { IDE } from "..";
|
||||
|
||||
export async function resolveRelativePathInWorkspace(
|
||||
path: string,
|
||||
ide: IDE,
|
||||
): Promise<string | undefined> {
|
||||
const pathSep = await ide.pathSep();
|
||||
if (path.startsWith(pathSep)) {
|
||||
return path;
|
||||
}
|
||||
|
||||
const workspaces = await ide.getWorkspaceDirs();
|
||||
for (const workspace of workspaces) {
|
||||
const fullPath = `${workspace}${pathSep}${path}`;
|
||||
if (await ide.fileExists(fullPath)) {
|
||||
return fullPath;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue