Project file path in LLM context for highlighted code (#1509)

This commit is contained in:
Tijs Zwinkels 2024-06-19 03:44:21 +02:00 • committed by GitHub
parent a3b5146374
commit cecbdf3ecc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 6 deletions

View file

@ -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,

View file

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