Merge pull request #6303 from uinstinct/no-results-instruction
improve: instruct model when no context results were retrieved
This commit is contained in:
commit
f90fafbe36
12 changed files with 38 additions and 6 deletions
|
|
@ -50,6 +50,7 @@ async function getContextProviderExtras(
|
|||
llm: config.modelsByRole.chat[0],
|
||||
reranker: config.selectedModelByRole.rerank,
|
||||
selectedCode: [],
|
||||
isInAgentMode: true,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -79,14 +79,19 @@ export async function retrieveContextItemsFromEmbeddings(
|
|||
|
||||
if (results.length === 0) {
|
||||
if (extras.config.disableIndexing) {
|
||||
void extras.ide.showToast("warning", "No results found.");
|
||||
return [];
|
||||
} else {
|
||||
void extras.ide.showToast(
|
||||
"warning",
|
||||
"No results found. If you think this is an error, re-index your codebase.",
|
||||
"No results found (Indexing disabled).",
|
||||
);
|
||||
// TODO - add "re-index" option to warning message which clears and reindexes codebase
|
||||
return [];
|
||||
}
|
||||
if (extras.isInAgentMode) {
|
||||
return [
|
||||
{
|
||||
...INSTRUCTIONS_BASE_ITEM,
|
||||
content: "No results were found. Try using other tools.",
|
||||
},
|
||||
];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1071,6 +1071,7 @@ export class Core {
|
|||
query: string;
|
||||
fullInput: string;
|
||||
selectedCode: RangeInFile[];
|
||||
isInAgentMode: boolean;
|
||||
}>,
|
||||
) => {
|
||||
const { config } = await this.configHandler.loadConfig();
|
||||
|
|
@ -1115,6 +1116,7 @@ export class Core {
|
|||
reranker: config.selectedModelByRole.rerank,
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
isInAgentMode: msg.data.isInAgentMode,
|
||||
});
|
||||
|
||||
void Telemetry.capture(
|
||||
|
|
|
|||
1
core/index.d.ts
vendored
1
core/index.d.ts
vendored
|
|
@ -187,6 +187,7 @@ export interface ContextProviderExtras {
|
|||
ide: IDE;
|
||||
selectedCode: RangeInFile[];
|
||||
fetch: FetchFunction;
|
||||
isInAgentMode: boolean;
|
||||
}
|
||||
|
||||
export interface LoadSubmenuItemsArgs {
|
||||
|
|
|
|||
|
|
@ -116,6 +116,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
query: string;
|
||||
fullInput: string;
|
||||
selectedCode: RangeInFile[];
|
||||
isInAgentMode: boolean;
|
||||
},
|
||||
ContextItemWithId[],
|
||||
];
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export const codebaseToolImpl: ToolImpl = async (args, extras) => {
|
|||
ide: extras.ide,
|
||||
selectedCode: [] as RangeInFile[],
|
||||
fetch: extras.fetch,
|
||||
isInAgentMode: true, // always true in tool call
|
||||
};
|
||||
|
||||
// Use the existing retrieval function to get context items
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ export async function getContextProvidersString(
|
|||
selectedCode: [],
|
||||
fetch: (url, init) =>
|
||||
fetchwithRequestOptions(url, init, config.requestOptions),
|
||||
isInAgentMode: false,
|
||||
});
|
||||
}) || [],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
vscQuickInputBackground,
|
||||
} from "../..";
|
||||
import { IdeMessengerContext } from "../../../context/IdeMessenger";
|
||||
import { useAppSelector } from "../../../redux/hooks";
|
||||
import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice";
|
||||
import { fontSize } from "../../../util";
|
||||
import FileIcon from "../../FileIcon";
|
||||
|
|
@ -159,6 +160,9 @@ const AtMentionDropdown = forwardRef((props: AtMentionDropdownProps, ref) => {
|
|||
const dispatch = useDispatch();
|
||||
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const isInAgentMode = useAppSelector(
|
||||
(store) => store.session.mode === "agent",
|
||||
);
|
||||
|
||||
const [selectedIndex, setSelectedIndex] = useState(0);
|
||||
|
||||
|
|
@ -187,6 +191,7 @@ const AtMentionDropdown = forwardRef((props: AtMentionDropdownProps, ref) => {
|
|||
query,
|
||||
fullInput: "",
|
||||
selectedCode,
|
||||
isInAgentMode,
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ export async function getRenderedV1Prompt(
|
|||
name,
|
||||
query: "",
|
||||
selectedCode,
|
||||
isInAgentMode: false,
|
||||
});
|
||||
if (response.status === "success") {
|
||||
return response.content.map((item) => item.content).join("\n\n");
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
import { stripImages } from "core/util/messageContent";
|
||||
import { IIdeMessenger } from "../../../../context/IdeMessenger";
|
||||
import { setIsGatheringContext } from "../../../../redux/slices/sessionSlice";
|
||||
import { RootState } from "../../../../redux/store";
|
||||
import { processEditorContent } from "./processEditorContent";
|
||||
import { renderSlashCommandPrompt } from "./renderSlashCommand";
|
||||
import { GetContextRequest } from "./types";
|
||||
|
|
@ -23,6 +24,7 @@ interface ResolveEditorContentInput {
|
|||
defaultContextProviders: DefaultContextProvider[];
|
||||
availableSlashCommands: SlashCommandDescWithSource[];
|
||||
dispatch: Dispatch;
|
||||
getState: () => RootState;
|
||||
}
|
||||
|
||||
interface ResolveEditorContentOutput {
|
||||
|
|
@ -48,6 +50,7 @@ export async function resolveEditorContent({
|
|||
defaultContextProviders,
|
||||
availableSlashCommands,
|
||||
dispatch,
|
||||
getState,
|
||||
}: ResolveEditorContentInput): Promise<ResolveEditorContentOutput> {
|
||||
const {
|
||||
parts,
|
||||
|
|
@ -87,6 +90,7 @@ export async function resolveEditorContent({
|
|||
defaultContextProviders,
|
||||
parts: slashedParts,
|
||||
selectedCode,
|
||||
getState,
|
||||
});
|
||||
|
||||
if (shouldGatherContext) {
|
||||
|
|
@ -111,6 +115,7 @@ async function gatherContextItems({
|
|||
defaultContextProviders,
|
||||
parts,
|
||||
selectedCode,
|
||||
getState,
|
||||
}: {
|
||||
contextRequests: GetContextRequest[];
|
||||
modifiers: InputModifiers;
|
||||
|
|
@ -118,6 +123,7 @@ async function gatherContextItems({
|
|||
defaultContextProviders: DefaultContextProvider[];
|
||||
parts: MessagePart[];
|
||||
selectedCode: RangeInFile[];
|
||||
getState: () => RootState;
|
||||
}): Promise<ContextItemWithId[]> {
|
||||
const defaultRequests: GetContextRequest[] = defaultContextProviders.map(
|
||||
(def) => ({
|
||||
|
|
@ -139,6 +145,8 @@ async function gatherContextItems({
|
|||
);
|
||||
let contextItems: ContextItemWithId[] = [];
|
||||
|
||||
const isInAgentMode = getState().session.mode === "agent";
|
||||
|
||||
// Process context item attributes
|
||||
for (const item of deduplicatedInputs) {
|
||||
const result = await ideMessenger.request("context/getContextItems", {
|
||||
|
|
@ -146,6 +154,7 @@ async function gatherContextItems({
|
|||
query: item.query ?? "",
|
||||
fullInput: stripImages(parts),
|
||||
selectedCode,
|
||||
isInAgentMode,
|
||||
});
|
||||
if (result.status === "success") {
|
||||
contextItems.push(...result.content);
|
||||
|
|
@ -162,6 +171,7 @@ async function gatherContextItems({
|
|||
query: "",
|
||||
fullInput: stripImages(parts),
|
||||
selectedCode,
|
||||
isInAgentMode,
|
||||
});
|
||||
|
||||
if (result.status === "success") {
|
||||
|
|
@ -181,6 +191,7 @@ async function gatherContextItems({
|
|||
query: "non-mention-usage",
|
||||
fullInput: "",
|
||||
selectedCode: [],
|
||||
isInAgentMode,
|
||||
},
|
||||
);
|
||||
if (currentFileResponse.status === "success") {
|
||||
|
|
|
|||
|
|
@ -35,10 +35,11 @@ export const streamEditThunk = createAsyncThunk<
|
|||
ThunkApiType
|
||||
>(
|
||||
"edit/streamResponse",
|
||||
async ({ editorState, codeToEdit }, { dispatch, extra }) => {
|
||||
async ({ editorState, codeToEdit }, { dispatch, extra, getState }) => {
|
||||
await dispatch(
|
||||
streamThunkWrapper(async () => {
|
||||
dispatch(setActive());
|
||||
|
||||
const { selectedContextItems, content } = await resolveEditorContent({
|
||||
editorState,
|
||||
modifiers: {
|
||||
|
|
@ -49,6 +50,7 @@ export const streamEditThunk = createAsyncThunk<
|
|||
defaultContextProviders: [],
|
||||
availableSlashCommands: [],
|
||||
dispatch,
|
||||
getState,
|
||||
});
|
||||
|
||||
const prompt = [
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@ export const streamResponseThunk = createAsyncThunk<
|
|||
defaultContextProviders,
|
||||
availableSlashCommands: state.config.config.slashCommands,
|
||||
dispatch,
|
||||
getState,
|
||||
});
|
||||
|
||||
// symbols for both context items AND selected codeblocks
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue