diff --git a/.github/workflows/pr_checks.yaml b/.github/workflows/pr_checks.yaml index c7e37773a..cfd153918 100644 --- a/.github/workflows/pr_checks.yaml +++ b/.github/workflows/pr_checks.yaml @@ -31,6 +31,62 @@ jobs: if: steps.root-cache.outputs.cache-hit != 'true' run: npm ci + install-config-yaml: + needs: install-root + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + + - uses: actions/cache@v4 + with: + path: node_modules + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Install config-yaml dependencies + if: steps.config-yaml-cache.outputs.cache-hit != 'true' + run: | + cd packages/config-yaml + npm ci + + config-yaml-checks: + needs: install-config-yaml + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version-file: ".nvmrc" + + - uses: actions/cache@v4 + with: + path: node_modules + key: ${{ runner.os }}-root-node-modules-${{ hashFiles('package-lock.json') }} + + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build and check config-yaml + run: | + cd packages/config-yaml + npx tsc --noEmit + # Tests are currently failing, commenting out for now + # npm test + npm run build + install-core: needs: install-root runs-on: ubuntu-latest @@ -60,7 +116,7 @@ jobs: npm ci core-checks: - needs: install-core + needs: [install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -81,6 +137,17 @@ jobs: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Type check and lint run: | cd core @@ -90,7 +157,7 @@ jobs: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} install-gui: - needs: [install-root, install-core] + needs: [install-root, install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -115,6 +182,17 @@ jobs: path: gui/node_modules key: ${{ runner.os }}-gui-node-modules-${{ hashFiles('gui/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Install gui dependencies if: steps.gui-cache.outputs.cache-hit != 'true' run: | @@ -147,13 +225,24 @@ jobs: path: gui/node_modules key: ${{ runner.os }}-gui-node-modules-${{ hashFiles('gui/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Type check run: | cd gui npx tsc --noEmit binary-checks: - needs: [install-root, install-core] + needs: [install-root, install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -178,6 +267,17 @@ jobs: path: binary/node_modules key: ${{ runner.os }}-binary-node-modules-${{ hashFiles('binary/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Install binary dependencies if: steps.binary-cache.outputs.cache-hit != 'true' run: | @@ -190,7 +290,7 @@ jobs: npx tsc --noEmit install-vscode: - needs: [install-root, install-core] + needs: [install-root, install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -215,6 +315,17 @@ jobs: path: extensions/vscode/node_modules key: ${{ runner.os }}-vscode-node-modules-${{ hashFiles('extensions/vscode/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Install vscode dependencies if: steps.vscode-cache.outputs.cache-hit != 'true' run: | @@ -249,6 +360,17 @@ jobs: path: extensions/vscode/node_modules key: ${{ runner.os }}-vscode-node-modules-${{ hashFiles('extensions/vscode/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Type check and lint run: | cd extensions/vscode @@ -256,7 +378,7 @@ jobs: npm run lint core-tests: - needs: install-core + needs: [install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -270,6 +392,17 @@ jobs: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Run core tests run: | cd core @@ -285,7 +418,7 @@ jobs: vscode-get-test-file-matrix: runs-on: ubuntu-latest - needs: [install-root, install-vscode] + needs: [install-root, install-vscode, install-config-yaml] outputs: test_file_matrix: ${{ steps.vscode-get-test-file-matrix.outputs.test_file_matrix }} steps: @@ -297,6 +430,17 @@ jobs: path: extensions/vscode/node_modules key: ${{ runner.os }}-vscode-node-modules-${{ hashFiles('extensions/vscode/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Get test files id: vscode-get-test-file-matrix run: | @@ -320,7 +464,7 @@ jobs: vscode-package-extension: runs-on: ubuntu-latest - needs: [install-vscode, install-core] + needs: [install-vscode, install-core, install-config-yaml] steps: - uses: actions/checkout@v4 @@ -340,6 +484,17 @@ jobs: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Package extension run: | cd extensions/vscode @@ -353,7 +508,7 @@ jobs: vscode-download-e2e-dependencies: runs-on: ubuntu-latest - needs: [install-vscode, install-core] + needs: [install-vscode, install-core, install-config-yaml] steps: - uses: actions/checkout@v4 @@ -373,6 +528,17 @@ jobs: path: extensions/vscode/e2e/storage key: ${{ runner.os }}-vscode-storage-${{ hashFiles('extensions/vscode/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Download Dependencies if: steps.storage-cache.outputs.cache-hit != 'true' run: | @@ -394,6 +560,7 @@ jobs: vscode-package-extension, install-vscode, install-core, + install-config-yaml, ] runs-on: ubuntu-latest # Tests requiring secrets need approval from maintainers @@ -434,6 +601,17 @@ jobs: name: vscode-e2e-dependencies path: extensions/vscode/e2e/storage + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Fix VSCode binary permissions run: | chmod +x extensions/vscode/e2e/storage/VSCode-linux-x64/code @@ -476,7 +654,7 @@ jobs: path: extensions/vscode/e2e/storage/screenshots gui-tests: - needs: [install-gui, install-core] + needs: [install-gui, install-core, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -496,6 +674,17 @@ jobs: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Install GUI dependencies if: steps.gui-cache.outputs.cache-hit != 'true' run: cd gui && npm ci @@ -508,7 +697,7 @@ jobs: npm test jetbrains-tests: - needs: [install-root, core-checks] + needs: [install-root, core-checks, install-config-yaml] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -517,6 +706,17 @@ jobs: path: core/node_modules key: ${{ runner.os }}-core-node-modules-${{ hashFiles('core/package-lock.json') }} + - uses: actions/cache@v4 + id: config-yaml-cache + with: + path: packages/config-yaml/node_modules + key: ${{ runner.os }}-config-yaml-node-modules-${{ hashFiles('packages/config-yaml/package-lock.json') }} + + - name: Build config-yaml + run: | + cd packages/config-yaml + npm run build + - name: Setup Java uses: actions/setup-java@v4.5.0 with: @@ -627,6 +827,8 @@ jobs: - vscode-e2e-tests - gui-tests - jetbrains-tests + - config-yaml-checks + - install-config-yaml steps: - name: Decide whether the needed jobs succeeded or failed diff --git a/core/commands/util.ts b/core/commands/util.ts index 5a0ea32e4..3785b4f52 100644 --- a/core/commands/util.ts +++ b/core/commands/util.ts @@ -34,13 +34,18 @@ export function ctxItemToRifWithContents( ): RangeInFileWithContents { let startLine = 0; let endLine = 0; + let adjustLines = linesOffByOne ? 1 : 0; const nameSplit = item.name.split("("); if (nameSplit.length > 1) { const lines = nameSplit[1].split(")")[0].split("-"); - startLine = Number.parseInt(lines[0], 10) - (linesOffByOne ? 1 : 0); - endLine = Number.parseInt(lines[1], 10) - (linesOffByOne ? 1 : 0); + startLine = Number.parseInt(lines[0], 10); + if (startLine === 0) { + adjustLines = 0; // safety to make sure doesn't go negative + } + startLine -= adjustLines; + endLine = Number.parseInt(lines[1], 10) - adjustLines; } const rif: RangeInFileWithContents = { diff --git a/core/config/load.ts b/core/config/load.ts index 2853077fc..6473d3a51 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -70,7 +70,11 @@ import { localPathToUri } from "../util/pathToUri"; import { getSystemPromptDotFile } from "./getSystemPromptDotFile"; import { modifyAnyConfigWithSharedConfig } from "./sharedConfig"; -import { getModelByRole, isSupportedLanceDbCpuTargetForLinux } from "./util"; +import { + getModelByRole, + isSupportedLanceDbCpuTargetForLinux, + serializePromptTemplates, +} from "./util"; import { validateConfig } from "./validation.js"; export function resolveSerializedConfig( @@ -607,8 +611,9 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription { template: llm.template, completionOptions: llm.completionOptions, systemMessage: llm.systemMessage, + baseChatSystemMessage: llm.baseChatSystemMessage, requestOptions: llm.requestOptions, - promptTemplates: llm.promptTemplates as any, + promptTemplates: serializePromptTemplates(llm.promptTemplates), capabilities: llm.capabilities, roles: llm.roles, configurationStatus: llm.getConfigurationStatus(), diff --git a/core/config/util.test.ts b/core/config/util.test.ts new file mode 100644 index 000000000..e7de79e1b --- /dev/null +++ b/core/config/util.test.ts @@ -0,0 +1,45 @@ +import { PromptTemplate } from ".."; +import { serializePromptTemplates } from "./util"; + +describe("serializePromptTemplates", () => { + it("should return undefined for undefined input", () => { + expect(serializePromptTemplates(undefined)).toBeUndefined(); + }); + + it("should convert function templates to empty strings", () => { + const functionTemplate: PromptTemplate = () => "Generated template"; + const templates: Record = { + template1: functionTemplate, + }; + + const result = serializePromptTemplates(templates); + + expect(result).toEqual({ template1: "" }); + }); + + it("should pass through string templates unchanged", () => { + const templates: Record = { + template1: "This is a static template", + template2: "Another static template", + }; + + const result = serializePromptTemplates(templates); + + expect(result).toEqual(templates); + }); + + it("should handle mixed template types", () => { + const functionTemplate: PromptTemplate = () => "Generated template"; + const templates: Record = { + function: functionTemplate, + string: "This is a static template", + }; + + const result = serializePromptTemplates(templates); + + expect(result).toEqual({ + function: "", + string: "This is a static template", + }); + }); +}); diff --git a/core/config/util.ts b/core/config/util.ts index 957e6c6ff..4c70acb38 100644 --- a/core/config/util.ts +++ b/core/config/util.ts @@ -7,6 +7,7 @@ import { IDE, ILLM, ModelDescription, + PromptTemplate, } from "../"; import { GlobalContext } from "../util/GlobalContext"; import { editConfigFile } from "../util/paths"; @@ -169,3 +170,22 @@ async function showUnsupportedCpuToast(ide: IDE) { ); } } + +/** + * This is required because users are only able to define prompt templates as a + * string, while internally we also allow prompt templates to be functions + * @param templates + * @returns + */ +export function serializePromptTemplates( + templates: Record | undefined, +): Record | undefined { + if (!templates) return undefined; + + return Object.fromEntries( + Object.entries(templates).map(([key, template]) => { + const serialized = typeof template === "function" ? "" : template; + return [key, serialized]; + }), + ); +} diff --git a/core/config/yaml/models.ts b/core/config/yaml/models.ts index fa9c92cac..572d7eb70 100644 --- a/core/config/yaml/models.ts +++ b/core/config/yaml/models.ts @@ -66,6 +66,7 @@ async function modelConfigToBaseLLM({ systemMessage: config.systemMessage, rules: config.rules, promptTemplates: model.promptTemplates, + baseChatSystemMessage: model.chatOptions?.baseSystemMessage, capabilities: { tools: model.capabilities?.includes("tool_use"), uploadImage: model.capabilities?.includes("image_input"), diff --git a/core/index.d.ts b/core/index.d.ts index f81f14262..30a977717 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -77,39 +77,19 @@ export type PromptTemplateFunction = ( export type PromptTemplate = string | PromptTemplateFunction; -export interface ILLM extends LLMOptions { +type RequiredLLMOptions = + | "uniqueId" + | "contextLength" + | "embeddingId" + | "maxEmbeddingChunkSize" + | "maxEmbeddingBatchSize" + | "completionOptions"; + +export interface ILLM + extends Omit, + Required> { get providerName(): string; - uniqueId: string; - model: string; - - title?: string; - systemMessage?: string; - contextLength: number; - maxStopWords?: number; - completionOptions: CompletionOptions; - requestOptions?: RequestOptions; - promptTemplates?: Record; - templateMessages?: (messages: ChatMessage[]) => string; - llmLogger?: ILLMLogger; - llmRequestHook?: (model: string, prompt: string) => any; - apiKey?: string; - apiBase?: string; - cacheBehavior?: CacheBehavior; - capabilities?: ModelCapability; - roles?: ModelRole[]; - - deployment?: string; - apiVersion?: string; - apiType?: string; - region?: string; - projectId?: string; - - // Embedding options - embeddingId: string; - maxEmbeddingChunkSize: number; - maxEmbeddingBatchSize: number; - complete( prompt: string, signal: AbortSignal, @@ -580,6 +560,7 @@ export interface LLMOptions { title?: string; uniqueId?: string; systemMessage?: string; + baseChatSystemMessage?: string; contextLength?: number; maxStopWords?: number; completionOptions?: CompletionOptions; @@ -1059,6 +1040,7 @@ export interface ModelDescription { template?: TemplateType; completionOptions?: BaseCompletionOptions; systemMessage?: string; + baseChatSystemMessage?: string; requestOptions?: RequestOptions; promptTemplates?: { [key: string]: string }; cacheBehavior?: CacheBehavior; diff --git a/core/llm/constructMessages.ts b/core/llm/constructMessages.ts index 69425d33e..f3e6b4d07 100644 --- a/core/llm/constructMessages.ts +++ b/core/llm/constructMessages.ts @@ -1,14 +1,41 @@ import { ChatHistoryItem, ChatMessage, MessagePart } from "../"; import { normalizeToMessageParts } from "../util/messageContent"; -const DEFAULT_SYSTEM_MESSAGE = ` - Always include the language and file name in the info string when you write code blocks. If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py'. +const DEFAULT_SYSTEM_MESSAGE = `\ + + Always include the language and file name in the info string when you write code blocks. + If you are editing "src/main.py" for example, your code block should start with '\`\`\`python src/main.py' + + When addressing code modification requests, present a concise code snippet that + emphasizes only the necessary changes and uses abbreviated placeholders for + unmodified sections. For instance: + + \`\`\`typescript /path/to/file + // ... rest of code here ... + + {{ modified code here }} + + // ... rest of code here ... + + {{ another modification }} + + // ... rest of code here ... + \`\`\` + + Since users have access to their complete file, they prefer reading only the + relevant modifications. It's perfectly acceptable to omit unmodified portions + at the beginning, middle, or end of files using these "lazy" comments. Only + provide the complete file when explicitly requested. Include a concise explanation + of changes unless the user specifically asks for code only. `; const CANCELED_TOOL_CALL_MESSAGE = "This tool call was cancelled by the user. You should clarify next steps, as they don't wish for you to use this tool."; -export function constructMessages(history: ChatHistoryItem[]): ChatMessage[] { +export function constructMessages( + history: ChatHistoryItem[], + baseChatSystemMessage: string | undefined, +): ChatMessage[] { const filteredHistory = history.filter( (item) => item.message.role !== "system", ); @@ -16,7 +43,7 @@ export function constructMessages(history: ChatHistoryItem[]): ChatMessage[] { msgs.push({ role: "system", - content: DEFAULT_SYSTEM_MESSAGE, + content: baseChatSystemMessage ?? DEFAULT_SYSTEM_MESSAGE, }); for (let i = 0; i < filteredHistory.length; i++) { diff --git a/core/llm/index.ts b/core/llm/index.ts index 723ab2f45..a380bd5de 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -127,6 +127,7 @@ export abstract class BaseLLM implements ILLM { title?: string; systemMessage?: string; + baseChatSystemMessage?: string; contextLength: number; maxStopWords?: number | undefined; completionOptions: CompletionOptions; @@ -195,6 +196,7 @@ export abstract class BaseLLM implements ILLM { this.title = options.title; this.uniqueId = options.uniqueId ?? "None"; this.systemMessage = options.systemMessage; + this.baseChatSystemMessage = options.baseChatSystemMessage; this.contextLength = options.contextLength ?? llmInfo?.contextLength ?? DEFAULT_CONTEXT_LENGTH; this.maxStopWords = options.maxStopWords ?? this.maxStopWords; diff --git a/core/package-lock.json b/core/package-lock.json index daf8696a4..494992220 100644 --- a/core/package-lock.json +++ b/core/package-lock.json @@ -13,7 +13,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", @@ -108,6 +108,27 @@ "node": ">=20.11.0" } }, + "../packages/config-yaml": { + "name": "@continuedev/config-yaml", + "version": "1.0.78", + "license": "Apache-2.0", + "dependencies": { + "@continuedev/config-types": "^1.0.14", + "yaml": "^2.6.1", + "zod": "^3.24.2" + }, + "bin": { + "config-yaml": "dist/cli.js" + }, + "devDependencies": { + "@types/jest": "^29.5.14", + "@types/node": "^20.0.0", + "cross-env": "^7.0.3", + "jest": "^29.7.0", + "ts-jest": "^29.2.3", + "ts-node": "^10.9.2" + } + }, "node_modules/@75lb/deep-merge": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@75lb/deep-merge/-/deep-merge-1.1.2.tgz", @@ -2977,14 +2998,8 @@ } }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.77", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.77.tgz", - "integrity": "sha512-Vke6jp4bENjJc9fO1tavOnbYXRmmSIEzNhYeQ6DzZVl92+8rWwdO6zhbrK0r4FGjHnH0cJgyK/q0zX9/l+6asw==", - "dependencies": { - "@continuedev/config-types": "^1.0.14", - "yaml": "^2.6.1", - "zod": "^3.24.2" - } + "resolved": "../packages/config-yaml", + "link": true }, "node_modules/@continuedev/fetch": { "version": "1.0.4", diff --git a/core/package.json b/core/package.json index a007fe637..296b8834a 100644 --- a/core/package.json +++ b/core/package.json @@ -47,7 +47,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", diff --git a/docs/docs/customize/model-roles/apply.mdx b/docs/docs/customize/model-roles/apply.mdx index 1ecace184..78574b096 100644 --- a/docs/docs/customize/model-roles/apply.mdx +++ b/docs/docs/customize/model-roles/apply.mdx @@ -13,3 +13,27 @@ When editing code, Chat and Edit model output often doesn't clearly align with e Generally speaking, models proficient in chat and edit can also be used for applying code. Explore apply models in [the hub](https://hub.continue.dev/explore/models?roles=apply). + +## Prompt templating + +You can customize the prompt template used for applying code changes by setting the `promptTemplates.apply` property in your model configuration. Continue uses [Handlebars syntax](https://handlebarsjs.com/guide/) for templating. + +Available variables for the apply template: + +- `{{{original_code}}}` - The original code before changes +- `{{{new_code}}}` - The new code after changes + +Example: + +```yaml +models: + - name: My Custom Apply Template + provider: anthropic + model: claude-3-5-sonnet-latest + promptTemplates: + apply: | + Original: {{{original_code}}} + New: {{{new_code}}} + + Please generate the final code without any markers or explanations. +``` diff --git a/docs/docs/customize/model-roles/edit.mdx b/docs/docs/customize/model-roles/edit.mdx index de817ed42..5e4ad1d5f 100644 --- a/docs/docs/customize/model-roles/edit.mdx +++ b/docs/docs/customize/model-roles/edit.mdx @@ -46,3 +46,37 @@ In Continue, you can add `edit` to a model's roles to specify that it can be use Explore edit models in [the hub](https://hub.continue.dev/explore/models?roles=edit). Generally, our recommendations for Edit overlap with recommendations for Chat. + +## Prompt templating + +You can customize the prompt template used for editing code by setting the `promptTemplates.edit` property in your model configuration. Continue uses [Handlebars syntax](https://handlebarsjs.com/guide/) for templating. + +Available variables for the edit template: + +- `{{{userInput}}}` - The user's edit request/instruction +- `{{{language}}}` - The programming language of the code +- `{{{codeToEdit}}}` - The code that's being edited +- `{{{prefix}}}` - Content before the edit area +- `{{{suffix}}}` - Content after the edit area +- `{{{supportsCompletions}}}` - Whether the model supports completions API +- `{{{supportsPrefill}}}` - Whether the model supports prefill capability + +Example: + +```yaml +models: + - name: My Custom Edit Template + provider: openai + model: gpt-4o + promptTemplates: + edit: | + `Here is the code before editing: + \`\`\`{{{language}}} + {{{codeToEdit}}} + \`\`\` + + Here is the edit requested: + "{{{userInput}}}" + + Here is the code after editing:` +``` diff --git a/docs/docs/customize/tutorials/custom-code-rag.mdx b/docs/docs/customize/tutorials/custom-code-rag.mdx index f5e43dc8e..735e45655 100644 --- a/docs/docs/customize/tutorials/custom-code-rag.mdx +++ b/docs/docs/customize/tutorials/custom-code-rag.mdx @@ -51,8 +51,8 @@ func = get_registry().get("openai").create( class CodeChunks(LanceModel): filename: str text: str = func.SourceField() - # 1536 is the embedding dimension of the `voyage-code-3` model. - vector: Vector(1536) = func.VectorField() + # 1024 is the default dimension for `voyage-code-3`: https://docs.voyageai.com/docs/embeddings#model-choices + vector: Vector(1024) = func.VectorField() table = db.create_table("code_chunks", schema=CodeChunks, mode="overwrite") table.add([ diff --git a/docs/docs/reference.md b/docs/docs/reference.md index b9ae84846..6269a1bb7 100644 --- a/docs/docs/reference.md +++ b/docs/docs/reference.md @@ -145,15 +145,13 @@ The `models` section defines the language models used in your configuration. Mod - `apiBase`: Can be used to override the default API base that is specified per model - `roles`: An array specifying the roles this model can fulfill, such as `chat`, `autocomplete`, `embed`, `rerank`, `edit`, `apply`, `summarize`. The default value is `[chat, edit, apply, summarize]`. Note that the `summarize` role is not currently used. - `capabilities`: Array of strings denoting model capabilities, which will overwrite Continue's autodetection based on provider and model. Supported capabilities include `tool_use` and `image_input`. +- `promptTemplates`: Can be used to override the default prompt templates for different model roles. Valid values are [`edit`](./customize/model-roles/edit.mdx#prompt-templating) and [`apply`](./customize/model-roles/apply.mdx#prompt-templating). +- `chatOptions`: If the model includes role `chat`, these settings apply for Chat and Agent mode: + - `baseSystemMessage`: Can be used to override the default system prompt. - `embedOptions`: If the model includes role `embed`, these settings apply for embeddings: - - `maxChunkSize`: Maximum tokens per document chunk. Minimum is 128 tokens. - `maxBatchSize`: Maximum number of chunks per request. Minimum is 1 chunk. - - `defaultCompletionOptions`: Default completion options for model settings. - - **Properties:** - - `contextLength`: Maximum context length of the model, typically in tokens. - `maxTokens`: Maximum number of tokens to generate in a completion. - `temperature`: Controls the randomness of the completion. Values range from `0.0` (deterministic) to `1.0` (random). @@ -161,11 +159,7 @@ The `models` section defines the language models used in your configuration. Mod - `topK`: Maximum number of tokens considered at each step. - `stop`: An array of stop tokens that will terminate the completion. - `n`: Number of completions to generate. - - `requestOptions`: HTTP request options specific to the model. - - **Properties:** - - `timeout`: Timeout for each request to the language model. - `verifySsl`: Whether to verify SSL certificates for requests. - `caBundlePath`: Path to a custom CA bundle for HTTP requests. @@ -178,7 +172,7 @@ The `models` section defines the language models used in your configuration. Mod - `key`: Path to the client certificate key file. - `passphrase`: Optional passphrase for the client certificate key file. -#### Example: +#### Example ```yaml title="config.yaml" models: diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 89be3b5de..ac76f456e 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -106,7 +106,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", diff --git a/gui/package-lock.json b/gui/package-lock.json index 18a5d148e..c4bd71ae2 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -7,7 +7,7 @@ "name": "gui", "license": "Apache-2.0", "dependencies": { - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@headlessui/react": "^2.2.0", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", @@ -109,7 +109,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", @@ -204,6 +204,27 @@ "node": ">=20.11.0" } }, + "../packages/config-yaml": { + "name": "@continuedev/config-yaml", + "version": "1.0.79", + "license": "Apache-2.0", + "dependencies": { + "@continuedev/config-types": "^1.0.14", + "yaml": "^2.6.1", + "zod": "^3.24.2" + }, + "bin": { + "config-yaml": "dist/cli.js" + }, + "devDependencies": { + "@types/jest": "^29.5.14", + "@types/node": "^20.0.0", + "cross-env": "^7.0.3", + "jest": "^29.7.0", + "ts-jest": "^29.2.3", + "ts-node": "^10.9.2" + } + }, "node_modules/@adobe/css-tools": { "version": "4.4.0", "resolved": "https://registry.npmjs.org/@adobe/css-tools/-/css-tools-4.4.0.tgz", @@ -544,23 +565,9 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, - "node_modules/@continuedev/config-types": { - "version": "1.0.14", - "resolved": "https://registry.npmjs.org/@continuedev/config-types/-/config-types-1.0.14.tgz", - "integrity": "sha512-PVHyHPyRXd2QsaNgnCpiKYU3uHFTlyuQSkqE8OwrBmQqO6/TXUVIr/2EGtyIZGrml4Y+rGMSH40WU4/0t4SGpQ==", - "dependencies": { - "zod": "^3.23.8" - } - }, "node_modules/@continuedev/config-yaml": { - "version": "1.0.77", - "resolved": "https://registry.npmjs.org/@continuedev/config-yaml/-/config-yaml-1.0.77.tgz", - "integrity": "sha512-Vke6jp4bENjJc9fO1tavOnbYXRmmSIEzNhYeQ6DzZVl92+8rWwdO6zhbrK0r4FGjHnH0cJgyK/q0zX9/l+6asw==", - "dependencies": { - "@continuedev/config-types": "^1.0.14", - "yaml": "^2.6.1", - "zod": "^3.24.2" - } + "resolved": "../packages/config-yaml", + "link": true }, "node_modules/@emotion/is-prop-valid": { "version": "1.3.1", @@ -13773,6 +13780,7 @@ "version": "2.6.1", "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.1.tgz", "integrity": "sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==", + "dev": true, "bin": { "yaml": "bin.mjs" }, @@ -13792,14 +13800,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/zod": { - "version": "3.24.2", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", - "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } - }, "node_modules/zwitch": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/zwitch/-/zwitch-2.0.4.tgz", diff --git a/gui/package.json b/gui/package.json index 98db617a0..1a46aa97e 100644 --- a/gui/package.json +++ b/gui/package.json @@ -15,7 +15,7 @@ "test:watch": "vitest" }, "dependencies": { - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "file:../packages/config-yaml", "@headlessui/react": "^2.2.0", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", diff --git a/gui/src/components/mainInput/Lump/EditBlockButton.tsx b/gui/src/components/mainInput/Lump/EditBlockButton.tsx index 53cd82cfb..6cdcac4b0 100644 --- a/gui/src/components/mainInput/Lump/EditBlockButton.tsx +++ b/gui/src/components/mainInput/Lump/EditBlockButton.tsx @@ -4,7 +4,10 @@ import { useContext } from "react"; import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; -type SectionKey = Exclude; +type SectionKey = Exclude< + keyof ConfigYaml, + "name" | "version" | "schema" | "metadata" +>; interface EditBlockButtonProps { blockType: T; diff --git a/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx b/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx index eb63e0ee9..bb153f62a 100644 --- a/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx +++ b/gui/src/components/mainInput/belowMainInput/ContextItemsPeek.tsx @@ -42,7 +42,7 @@ function ContextItemsPeekItem({ contextItem }: ContextItemsPeekItemProps) { const isRangeInFile = name.includes(" (") && name.endsWith(")"); if (isRangeInFile) { - const rif = ctxItemToRifWithContents(contextItem); + const rif = ctxItemToRifWithContents(contextItem, true); ideMessenger.ide.showLines( rif.filepath, rif.range.start.line, diff --git a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx index 0da1c5c7f..541abd78e 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/ApplyActions.tsx @@ -52,9 +52,11 @@ export default function ApplyActions(props: ApplyActionsProps) { case "streaming": return (
- + Applying changes - +
+ +
); diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index aa84f9f33..8191af54b 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -223,7 +223,7 @@ function ModelSelect() { ref={buttonRef} className="h-[18px] gap-1 border-none text-gray-400" > - + {modelSelectTitle(selectedChatModel) || "Select model"} =14.17" } }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true, + "license": "MIT" + }, "node_modules/zod": { - "version": "3.23.8", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", - "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "version": "3.24.2", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.24.2.tgz", + "integrity": "sha512-lY7CDW43ECgW9u1TcT3IoXHflywfVqDYze4waEz812jR/bZ8FHDsl7pFQoSZTz5N+2NqRXs8GBwnAwo3ZNxqhQ==", + "license": "MIT", "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/packages/config-types/package.json b/packages/config-types/package.json index 5c420223f..2cccfe1ab 100644 --- a/packages/config-types/package.json +++ b/packages/config-types/package.json @@ -12,9 +12,10 @@ "author": "Nate Sesti and Ty Dunn", "license": "Apache-2.0", "devDependencies": { + "@types/node": "^20.11.19", "typescript": "^5.5.2" }, "dependencies": { "zod": "^3.24.2" } -} +} \ No newline at end of file diff --git a/packages/config-yaml/package-lock.json b/packages/config-yaml/package-lock.json index 2a8b83224..4e5b8df05 100644 --- a/packages/config-yaml/package-lock.json +++ b/packages/config-yaml/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/config-yaml", - "version": "1.0.72", + "version": "1.0.78", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/config-yaml", - "version": "1.0.72", + "version": "1.0.78", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/packages/config-yaml/src/load/unroll.ts b/packages/config-yaml/src/load/unroll.ts index 1e818c4ca..026c7e181 100644 --- a/packages/config-yaml/src/load/unroll.ts +++ b/packages/config-yaml/src/load/unroll.ts @@ -298,7 +298,7 @@ export async function unrollBlocks( const sections: (keyof Omit< ConfigYaml, - "name" | "version" | "rules" | "schema" + "name" | "version" | "rules" | "schema" | "metadata" >)[] = ["models", "context", "data", "mcpServers", "prompts", "docs"]; // For each section, replace "uses/with" blocks with the real thing diff --git a/packages/config-yaml/src/schemas/models.ts b/packages/config-yaml/src/schemas/models.ts index ff3f6bec3..2334b4c7c 100644 --- a/packages/config-yaml/src/schemas/models.ts +++ b/packages/config-yaml/src/schemas/models.ts @@ -56,6 +56,11 @@ export const embedOptionsSchema = z.object({ }); export type EmbedOptions = z.infer; +export const chatOptionsSchema = z.object({ + baseSystemMessage: z.string().optional(), +}); +export type ChatOptions = z.infer; + /** Prompt templates use Handlebars syntax */ const promptTemplatesSchema = z.object({ apply: z.string().optional(), @@ -73,6 +78,7 @@ const baseModelFields = { defaultCompletionOptions: completionOptionsSchema.optional(), requestOptions: requestOptionsSchema.optional(), embedOptions: embedOptionsSchema.optional(), + chatOptions: chatOptionsSchema.optional(), promptTemplates: promptTemplatesSchema.optional(), env: z .record(z.string(), z.union([z.string(), z.boolean(), z.number()]))