Skip to content

Commit

Permalink
Merge pull request #2887 from continuedev/nate/small-fixes
Browse files Browse the repository at this point in the history
second new prompt file
  • Loading branch information
sestinj authored Nov 12, 2024
2 parents 98b2699 + 3a5329e commit a2af40e
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 31 deletions.
5 changes: 4 additions & 1 deletion core/config/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ async function serializedToIntermediateConfig(
promptFiles.push(...readAllGlobalPromptFiles());

for (const file of promptFiles) {
slashCommands.push(slashCommandFromPromptFile(file.path, file.content));
const slashCommand = slashCommandFromPromptFile(file.path, file.content);
if (slashCommand) {
slashCommands.push(slashCommand);
}
}
}

Expand Down
27 changes: 21 additions & 6 deletions core/config/promptFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import path from "path";
import Handlebars from "handlebars";
import * as YAML from "yaml";

import { BaseContextProvider } from "../context";
import { walkDir } from "../indexing/walkDir";
import { stripImages } from "../llm/images";
import { renderTemplatedString } from "../promptFiles/v1/renderTemplatedString";
import { getBasename } from "../util/index";

import type { ChatHistory, ChatHistoryItem, ChatMessage, ContextItem, ContinueSDK, IContextProvider, IDE, SlashCommand } from "..";
import type {
ChatMessage,
ContextItem,
ContinueSDK,
IContextProvider,
IDE,
SlashCommand,
} from "..";

export const DEFAULT_PROMPTS_FOLDER = ".prompts";

Expand Down Expand Up @@ -93,12 +99,16 @@ export async function createNewPromptFile(
export function slashCommandFromPromptFile(
path: string,
content: string,
): SlashCommand {
const { name, description, systemMessage, prompt } = parsePromptFile(
): SlashCommand | null {
const { name, description, systemMessage, prompt, version } = parsePromptFile(
path,
content,
);

if (version !== 1) {
return null;
}

return {
name,
description,
Expand Down Expand Up @@ -134,14 +144,15 @@ function parsePromptFile(path: string, content: string) {
const preamble = YAML.parse(preambleRaw) ?? {};
const name = preamble.name ?? getBasename(path).split(".prompt")[0];
const description = preamble.description ?? name;
const version = preamble.version ?? 2;

let systemMessage: string | undefined = undefined;
if (prompt.includes("<system>")) {
systemMessage = prompt.split("<system>")[1].split("</system>")[0].trim();
prompt = prompt.split("</system>")[1].trim();
}

return { name, description, systemMessage, prompt };
return { name, description, systemMessage, prompt, version };
}

function extractUserInput(input: string, commandName: string): string {
Expand All @@ -151,7 +162,11 @@ function extractUserInput(input: string, commandName: string): string {
return input;
}

async function renderPrompt(prompt: string, context: ContinueSDK, userInput: string) {
async function renderPrompt(
prompt: string,
context: ContinueSDK,
userInput: string,
) {
const helpers = getContextProviderHelpers(context);

// A few context providers that don't need to be in config.json to work in .prompt files
Expand Down
20 changes: 12 additions & 8 deletions core/indexing/docs/DocsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,16 @@ export default class DocsService {
isPreIndexedDoc: !!preIndexedDocs[startUrl],
});

const docs: LanceDbDocsRow[] = await table
.search(vector)
.limit(nRetrieve)
.where(`starturl = '${startUrl}'`)
.execute();
let docs: LanceDbDocsRow[] = [];
try {
docs = await table
.search(vector)
.limit(nRetrieve)
.where(`starturl = '${startUrl}'`)
.execute();
} catch (e: any) {
console.error("Error retrieving chunks from LanceDB", e);
}

const hasIndexedDoc = await this.hasIndexedDoc(startUrl);

Expand Down Expand Up @@ -553,9 +558,8 @@ export default class DocsService {
private async getLanceTableNameFromEmbeddingsProvider(
isPreIndexedDoc: boolean,
) {
const embeddingsProvider = await this.getEmbeddingsProvider(
isPreIndexedDoc,
);
const embeddingsProvider =
await this.getEmbeddingsProvider(isPreIndexedDoc);

const tableName = this.sanitizeLanceTableName(
`${DocsService.lanceTableName}${embeddingsProvider.id}`,
Expand Down
5 changes: 5 additions & 0 deletions core/indexing/docs/preIndexedDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,11 @@ const preIndexedDocs: Record<
rootUrl: "https://awscli.amazonaws.com/v2/documentation/api/latest/",
faviconUrl: "https://docs.aws.amazon.com/favicon.ico",
},
"https://llama-stack.readthedocs.io/": {
title: "Llama Stack",
startUrl: "https://llama-stack.readthedocs.io/",
rootUrl: "https://llama-stack.readthedocs.io/",
},
};

export default preIndexedDocs;
5 changes: 4 additions & 1 deletion core/promptFiles/v2/createNewPromptFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,14 @@ export async function createNewPromptFileV2(
counter++;
} while (await ide.fileExists(promptFilePath));

const globalContext = new GlobalContext();
const PROMPT_FILE =
new GlobalContext().get("hasAlreadyCreatedAPromptFile") === true
globalContext.get("hasAlreadyCreatedAPromptFile") === true
? DEFAULT_PROMPT_FILE
: FIRST_TIME_DEFAULT_PROMPT_FILE;

globalContext.update("hasAlreadyCreatedAPromptFile", true);

await ide.writeFile(promptFilePath, PROMPT_FILE);
await ide.openFile(promptFilePath);
}
4 changes: 2 additions & 2 deletions extensions/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion extensions/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "continue",
"icon": "media/icon.png",
"author": "Continue Dev, Inc",
"version": "0.9.227",
"version": "0.9.228",
"repository": {
"type": "git",
"url": "https://github.com/continuedev/continue"
Expand Down
8 changes: 7 additions & 1 deletion extensions/vscode/src/lang-server/promptFileCompletions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
const lineText = document.lineAt(position).text;
const textBeforeCursor = lineText.substring(0, position.character);

// 0. If no delimiter in the file, return no completions
const fullContent = document.getText();
if (!fullContent.includes("---")) {
return undefined;
}

// 1. Check if the cursor is in YAML section (before --- delimiter)
const beforeDelimiter = isCursorBeforeDelimiter(document, position);

Expand All @@ -160,7 +166,7 @@ class YamlKeysCompletionItemProvider implements vscode.CompletionItemProvider {
vscode.CompletionItemKind.Property,
);
item.documentation = new vscode.MarkdownString(key.description);
item.insertText = key + ": ";
item.insertText = key.key + ": ";
return item;
});

Expand Down
39 changes: 28 additions & 11 deletions gui/src/pages/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import { Editor, JSONContent } from "@tiptap/core";
import { InputModifiers } from "core";
import { stripImages } from "core/llm/images";
import { getBasename } from "core/util";
import { usePostHog } from "posthog-js/react";
import { useContext, useEffect, useState } from "react";
Expand Down Expand Up @@ -71,7 +72,17 @@ const EditHistoryDiv = styled.div`
}
`;

const EDIT_ALLOWS_CONTEXT_PROVIDERS = ["file", "code"];
const EDIT_DISALLOWED_CONTEXT_PROVIDERS = [
"codebase",
"tree",
"open",
"web",
"diff",
"folder",
"search",
"debugger",
"repo-map",
];

function Edit() {
const posthog = usePostHog();
Expand Down Expand Up @@ -174,7 +185,7 @@ function Edit() {
border={`1px solid #aa0`}
availableContextProviders={availableContextProviders.filter(
(provider) =>
EDIT_ALLOWS_CONTEXT_PROVIDERS.includes(provider.title),
!EDIT_DISALLOWED_CONTEXT_PROVIDERS.includes(provider.title),
)}
historyKey="edit"
availableSlashCommands={[]}
Expand All @@ -184,15 +195,21 @@ function Edit() {
modifiers: InputModifiers,
editor: Editor,
): Promise<void> {
const [_, __, prompt] = await resolveEditorContent(
editorState,
{
noContext: true,
useCodebase: false,
},
ideMessenger,
[],
);
const [contextItems, __, userInstructions] =
await resolveEditorContent(
editorState,
{
noContext: true,
useCodebase: false,
},
ideMessenger,
[],
);

const prompt = [
...contextItems.map((item) => item.content),
stripImages(userInstructions),
].join("\n\n");
ideMessenger.request("edit/sendPrompt", {
prompt,
range: editModeState.highlightedCode,
Expand Down

0 comments on commit a2af40e

Please sign in to comment.