( defaultLlm: ILLM, config: ContinueConfig, ide: IDE, input: string, filterDirUri?: string, )
| 32 | } |
| 33 | |
| 34 | export async function requestFilesFromRepoMap( |
| 35 | defaultLlm: ILLM, |
| 36 | config: ContinueConfig, |
| 37 | ide: IDE, |
| 38 | input: string, |
| 39 | filterDirUri?: string, |
| 40 | ): Promise<Chunk[]> { |
| 41 | const llm = getModelByRole(config, "repoMapFileSelection") ?? defaultLlm; |
| 42 | |
| 43 | // Only supported for Claude models right now |
| 44 | if (!isSupportedModel(config, llm.title)) { |
| 45 | return []; |
| 46 | } |
| 47 | |
| 48 | try { |
| 49 | const repoMap = await generateRepoMap(llm, ide, { |
| 50 | dirUris: filterDirUri ? [filterDirUri] : undefined, |
| 51 | includeSignatures: false, |
| 52 | outputRelativeUriPaths: true, |
| 53 | }); |
| 54 | |
| 55 | const prompt = `${repoMap} |
| 56 | |
| 57 | Given the above repo map, your task is to decide which files are most likely to be relevant in answering a question. Before giving your answer, you should write your reasoning about which files/folders are most important. This thinking should start with a <reasoning> tag, followed by a paragraph explaining your reasoning, and then a closing </reasoning> tag on the last line. |
| 58 | |
| 59 | After this, your response should begin with a <results> tag, followed by a list of each file, one per line, and then a closing </results> tag on the last line. You should select between 5 and 10 files. The names that you list should be the exact relative path that you saw in the repo map, not just the basename of the file. |
| 60 | |
| 61 | This is the question that you should select relevant files for: "${input}"`; |
| 62 | |
| 63 | const response = await llm.chat( |
| 64 | [ |
| 65 | { role: "user", content: prompt }, |
| 66 | { role: "assistant", content: "<reasoning>" }, |
| 67 | ], |
| 68 | new AbortController().signal, |
| 69 | ); |
| 70 | const content = renderChatMessage(response); |
| 71 | |
| 72 | if (!content.includes("\n")) { |
| 73 | return []; |
| 74 | } |
| 75 | |
| 76 | const filepaths = content |
| 77 | .split("<results>")[1] |
| 78 | ?.split("</results>")[0] |
| 79 | ?.split("\n") |
| 80 | .filter(Boolean) |
| 81 | .map((filepath) => filepath.trim()); |
| 82 | |
| 83 | const chunks = await Promise.all( |
| 84 | filepaths.map(async (filepath) => { |
| 85 | const uri = await resolveRelativePathInDir(filepath, ide); |
| 86 | if (!uri) { |
| 87 | return undefined; |
| 88 | } |
| 89 | const content = await ide.readFile(uri); |
| 90 | const lineCount = content.split("\n").length; |
| 91 | const chunk: Chunk = { |
no test coverage detected