From cecbdf3ecc5780c6cd151f44610d19bd8f5ff3dd Mon Sep 17 00:00:00 2001 From: Tijs Zwinkels Date: Wed, 19 Jun 2024 03:44:21 +0200 Subject: [PATCH] Project file path in LLM context for highlighted code (#1509) --- gui/src/components/mainInput/TipTapEditor.tsx | 11 ++++++----- gui/src/components/mainInput/resolveInput.ts | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/gui/src/components/mainInput/TipTapEditor.tsx b/gui/src/components/mainInput/TipTapEditor.tsx index 04e3f8c62..062572c97 100644 --- a/gui/src/components/mainInput/TipTapEditor.tsx +++ b/gui/src/components/mainInput/TipTapEditor.tsx @@ -12,7 +12,7 @@ import { RangeInFile, } from "core"; import { modelSupportsImages } from "core/llm/autodetect"; -import { getBasename } from "core/util"; +import { getBasename, getRelativePath } from "core/util"; import { useContext, useEffect, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import styled from "styled-components"; @@ -590,12 +590,13 @@ function TipTapEditor(props: TipTapEditorProps) { const rif: RangeInFile & { contents: string } = data.rangeInFileWithContents; const basename = getBasename(rif.filepath); + const relativePath = getRelativePath(rif.filepath, await ideMessenger.ide.getWorkspaceDirs()); + const rangeStr = `(${rif.range.start.line + 1}-${rif.range.end.line + 1})`; const item: ContextItemWithId = { content: rif.contents, - name: `${basename} (${rif.range.start.line + 1}-${ - rif.range.end.line + 1 - })`, - description: rif.filepath, + name: `${basename} ${rangeStr}`, + // Description is passed on to the LLM to give more context on file path + description: `${relativePath} ${rangeStr}`, id: { providerTitle: "code", itemId: rif.filepath, diff --git a/gui/src/components/mainInput/resolveInput.ts b/gui/src/components/mainInput/resolveInput.ts index 14ac3bf4e..bb628f4ce 100644 --- a/gui/src/components/mainInput/resolveInput.ts +++ b/gui/src/components/mainInput/resolveInput.ts @@ -55,7 +55,7 @@ async function resolveEditorContent( } else if (p.type === "codeBlock") { if (!p.attrs.item.editing) { const text = - "```" + p.attrs.item.name + "\n" + p.attrs.item.content + "\n```"; + "```" + p.attrs.item.description + "\n" + p.attrs.item.content + "\n```"; if (parts[parts.length - 1]?.type === "text") { parts[parts.length - 1].text += "\n" + text; } else {