From 514a642a05a2146b99035fd89922dd8737da4ec3 Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Thu, 18 Apr 2024 21:42:32 +0200 Subject: [PATCH 01/22] =?UTF-8?q?=F0=9F=90=9B=20set=20supportsCompletions?= =?UTF-8?q?=20based=20on=20useLegacyCompletionsEndpoint=20model=20setting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #1132 --- core/llm/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/llm/index.ts b/core/llm/index.ts index ed920eaa7..6831ad475 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -52,7 +52,8 @@ export abstract class BaseLLM implements ILLM { if (this.providerName === "openai") { if ( this.apiBase?.includes("api.groq.com") || - this.apiBase?.includes(":1337") + this.apiBase?.includes(":1337") || + this._llmOptions.useLegacyCompletionsEndpoint?.valueOf() === false ) { // Jan + Groq don't support completions : ( return false; From 245936e239455c5af7f4df1abaf36fae830d8dfc Mon Sep 17 00:00:00 2001 From: Roger Meier Date: Thu, 18 Apr 2024 22:00:07 +0200 Subject: [PATCH 02/22] =?UTF-8?q?=F0=9F=93=9D=20useLegacyCompletionsEndpoi?= =?UTF-8?q?nt=20within=20OpenAI=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/reference/Model Providers/openai.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/docs/reference/Model Providers/openai.md b/docs/docs/reference/Model Providers/openai.md index 853d97b43..c15f88b63 100644 --- a/docs/docs/reference/Model Providers/openai.md +++ b/docs/docs/reference/Model Providers/openai.md @@ -52,4 +52,10 @@ If you are [using an OpenAI compatible server / API](../../model-setup/select-pr } ``` +To force usage of `chat/completions` instead of `completions` endpoint you can set + +```json +"useLegacyCompletionsEndpoint": false +``` + [View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/OpenAI.ts) From 388df207837c79f6d7d94a16edb9962ac7423212 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 18 Apr 2024 15:35:17 -0700 Subject: [PATCH 03/22] =?UTF-8?q?=F0=9F=A9=B9=20set=20default=20useLegacyC?= =?UTF-8?q?ompletionsEndpoint=20to=20undefined?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/llms/OpenAI.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index 6544c47ce..d8f4214ac 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -38,12 +38,11 @@ const CHAT_ONLY_MODELS = [ ]; class OpenAI extends BaseLLM { - public useLegacyCompletionsEndpoint = false; + public useLegacyCompletionsEndpoint: boolean | undefined = undefined; constructor(options: LLMOptions) { super(options); - this.useLegacyCompletionsEndpoint = - options.useLegacyCompletionsEndpoint ?? false; + this.useLegacyCompletionsEndpoint = options.useLegacyCompletionsEndpoint; } static providerName: ModelProvider = "openai"; From 6a5c4ecf3a861a5157ebcd09b27d8b6a3d010060 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 19 Apr 2024 10:12:08 -0700 Subject: [PATCH 04/22] =?UTF-8?q?=F0=9F=A9=B9=20look=20for=20bedrock=20cre?= =?UTF-8?q?dentials=20in=20homedir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/llms/Bedrock.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/llm/llms/Bedrock.ts b/core/llm/llms/Bedrock.ts index 138a7f536..1a6a883a8 100644 --- a/core/llm/llms/Bedrock.ts +++ b/core/llm/llms/Bedrock.ts @@ -1,4 +1,5 @@ import * as fs from "fs"; +import os from "os"; import { join as joinPath } from "path"; import { promisify } from "util"; import { BaseLLM } from ".."; @@ -143,7 +144,7 @@ class Bedrock extends BaseLLM { try { const data = await readFile( - joinPath(process.env.HOME!, ".aws", "credentials"), + joinPath(process.env.HOME ?? os.homedir(), ".aws", "credentials"), "utf8", ); const credentials = this._parseCredentialsFile(data); From 1cb0455f6e17dcf5e2a233081227ebafe987e3b0 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Fri, 19 Apr 2024 10:39:27 -0700 Subject: [PATCH 05/22] =?UTF-8?q?=F0=9F=A9=B9=20use=20title=20for=20autode?= =?UTF-8?q?tect?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/llm/autodetect.ts | 13 +++++++++++-- core/llm/index.ts | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 2503dafd1..882f7efa5 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -62,12 +62,21 @@ const MODEL_SUPPORTS_IMAGES: string[] = [ "haiku", ]; -function modelSupportsImages(provider: ModelProvider, model: string): boolean { +function modelSupportsImages( + provider: ModelProvider, + model: string, + title: string | undefined, +): boolean { if (!PROVIDER_SUPPORTS_IMAGES.includes(provider)) { return false; } - if (MODEL_SUPPORTS_IMAGES.includes(model.toLowerCase())) { + const lower = model.toLowerCase(); + if ( + MODEL_SUPPORTS_IMAGES.some( + (modelName) => lower.includes(modelName) || title?.includes(modelName), + ) + ) { return true; } diff --git a/core/llm/index.ts b/core/llm/index.ts index 6831ad475..0e3208ffc 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -45,7 +45,7 @@ export abstract class BaseLLM implements ILLM { } supportsImages(): boolean { - return modelSupportsImages(this.providerName, this.model); + return modelSupportsImages(this.providerName, this.model, this.title); } supportsCompletions(): boolean { From faabd384a106941b0489f4fb1a82df4bfdf69f7f Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 06/22] Fix slash command params loading Existing slash commands expect an object named "params" so mapping to "options" here caused params to be undefined within the run scope. I renamed from 'm' to 's' just to avoid potential confusion with the model property mapping above. --- .prettierrc | 3 ++- core/config/load.ts | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.prettierrc b/.prettierrc index 222861c34..d3be6d22e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { "tabWidth": 2, - "useTabs": false + "useTabs": false, + "trailingComma": "all" } diff --git a/core/config/load.ts b/core/config/load.ts index cdd91aacf..03bd5b416 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -334,10 +334,10 @@ function finalToBrowserConfig( })), systemMessage: final.systemMessage, completionOptions: final.completionOptions, - slashCommands: final.slashCommands?.map((m) => ({ - name: m.name, - description: m.description, - options: m.params, + slashCommands: final.slashCommands?.map((s) => ({ + name: s.name, + description: s.description, + params: s.params, //PZTODO: is this why params aren't referenced properly by slash commands? })), contextProviders: final.contextProviders?.map((c) => c.description), disableIndexing: final.disableIndexing, From fadf70ed61123d6b57c8e28553fdbd9749f01d2a Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 07/22] Add outputDir param to /share --- core/commands/slash/share.ts | 15 ++++++++++----- core/config/default.ts | 6 ++++-- docs/docs/config-file-migration.md | 3 ++- docs/docs/customization/slash-commands.md | 3 ++- docs/docs/walkthroughs/config-file-migration.md | 3 ++- .../constants/ServerConstants.kt | 2 +- gui/src/redux/slices/stateSlice.ts | 3 ++- 7 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 64754960a..151d7e389 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -1,10 +1,11 @@ +import path from "path"; import { SlashCommand } from "../.."; import { stripImages } from "../../llm/countTokens"; const ShareSlashCommand: SlashCommand = { name: "share", description: "Download and share this session", - run: async function* ({ ide, history }) { + run: async function* ({ ide, history, params }) { let content = `This is a session transcript from [Continue](https://continue.dev) on ${new Date().toLocaleString()}.`; for (const msg of history) { @@ -13,10 +14,14 @@ const ShareSlashCommand: SlashCommand = { }\n\n${stripImages(msg.content)}`; } - const continueDir = await ide.getContinueDir(); - const path = `${continueDir}/session.md`; - await ide.writeFile(path, content); - await ide.openFile(path); + let outputDir = params?.outputDir; + if (!outputDir) { + outputDir = await ide.getContinueDir(); + } + + const outPath = path.join(outputDir, `session.md`); + await ide.writeFile(outPath, content); + await ide.openFile(outPath); yield `The session transcript has been saved to a markdown file at \`${path}\`.`; }, diff --git a/core/config/default.ts b/core/config/default.ts index 131479800..4a7bdf628 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -39,7 +39,8 @@ export const defaultConfig: SerializedContinueConfig = { }, { name: "share", - description: "Export this session as markdown", + description: "Export the current chat session to markdown", + params: { ouputDir: "Directory in which to export this session" }, }, { name: "cmd", @@ -110,7 +111,8 @@ export const defaultConfigJetBrains: SerializedContinueConfig = { }, { name: "share", - description: "Export this session as markdown", + description: "Export the current chat session to markdown", + params: { ouputDir: "Directory in which to export this session" }, }, ], customCommands: [ diff --git a/docs/docs/config-file-migration.md b/docs/docs/config-file-migration.md index 5184785d5..d67dad265 100644 --- a/docs/docs/config-file-migration.md +++ b/docs/docs/config-file-migration.md @@ -131,7 +131,8 @@ After the "Full example" these examples will only show the relevant portion of t }, { "name": "share", - "description": "Download and share this session", + "description": "Export the current chat session to markdown", + "params": { "ouputDir": "Directory in which to export this session" }, "step": "ShareSessionStep" }, { diff --git a/docs/docs/customization/slash-commands.md b/docs/docs/customization/slash-commands.md index da8ac0d43..d521b09eb 100644 --- a/docs/docs/customization/slash-commands.md +++ b/docs/docs/customization/slash-commands.md @@ -43,7 +43,8 @@ Type "/share" to generate a shareable markdown transcript of your current chat h ```json { "name": "share", - "description": "Download and share this session" + "description": "Export the current chat session to markdown", + "params": { "ouputDir": "Directory in which to export this session" } } ``` diff --git a/docs/docs/walkthroughs/config-file-migration.md b/docs/docs/walkthroughs/config-file-migration.md index 1a253e18e..47c2efdc0 100644 --- a/docs/docs/walkthroughs/config-file-migration.md +++ b/docs/docs/walkthroughs/config-file-migration.md @@ -130,7 +130,8 @@ After the "Full example" these examples will only show the relevant portion of t }, { "name": "share", - "description": "Download and share this session", + "description": "Export the current chat session to markdown", + "params": { "ouputDir": "Directory in which to save this session" }, "step": "ShareSessionStep" }, { diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/ServerConstants.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/ServerConstants.kt index f27514340..8bea73fc7 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/ServerConstants.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/ServerConstants.kt @@ -41,7 +41,7 @@ const val DEFAULT_CONFIG = """ }, { "name": "share", - "description": "Download and share this session", + "description": "Export the current chat session to markdown", "step": "ShareSessionStep" }, { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 99d52ae72..87ea78705 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -108,7 +108,8 @@ const initialState: State = { }, { name: "share", - description: "Download and share this session", + description: "Export the current chat session to markdown", + params: { ouputDir: "Directory in which to save this session" }, }, { name: "cmd", From 618906a2e12cc733c205dd4a0e62b2ce1e274ae0 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 08/22] Enable basic tilde expansion for /share outputDir --- core/commands/slash/share.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 151d7e389..7840ac086 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -1,10 +1,11 @@ import path from "path"; +import { homedir } from "os"; import { SlashCommand } from "../.."; import { stripImages } from "../../llm/countTokens"; const ShareSlashCommand: SlashCommand = { name: "share", - description: "Download and share this session", + description: "Export the current chat session to markdown", run: async function* ({ ide, history, params }) { let content = `This is a session transcript from [Continue](https://continue.dev) on ${new Date().toLocaleString()}.`; @@ -14,16 +15,19 @@ const ShareSlashCommand: SlashCommand = { }\n\n${stripImages(msg.content)}`; } - let outputDir = params?.outputDir; + let outputDir: string = params?.outputDir; if (!outputDir) { outputDir = await ide.getContinueDir(); } + if (outputDir.startsWith("~")) { + outputDir = outputDir.replace(/~/, homedir); + } const outPath = path.join(outputDir, `session.md`); await ide.writeFile(outPath, content); await ide.openFile(outPath); - yield `The session transcript has been saved to a markdown file at \`${path}\`.`; + yield `The session transcript has been saved to a markdown file at \`${outPath}\`.`; }, }; From 10b47012720c0145d74bc9fd4793b4c9021cc25d Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 09/22] Add ability to specify workspace for /share --- core/commands/slash/share.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 7840ac086..4363ac0aa 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -22,8 +22,18 @@ const ShareSlashCommand: SlashCommand = { if (outputDir.startsWith("~")) { outputDir = outputDir.replace(/~/, homedir); } + const workspaceDirs = await ide.getWorkspaceDirs(); + + // Although the most common situation is to have one directory open in a + // workspace it's also possible to have just a file open without an + // associated directory or to use multi-root workspaces in which multiple + // folders are included. We default to using the first item in the list, if + // it exists. + const workspaceDirectory = workspaceDirs?.[0] || ""; + outputDir = outputDir.replace(/CURRENT_WORKSPACE/, workspaceDirectory); + const outPath = path.join(outputDir, `session.md`); //TODO: more flexible naming + - const outPath = path.join(outputDir, `session.md`); await ide.writeFile(outPath, content); await ide.openFile(outPath); From e44ea2b39186fcedf36d1fe54739d06c143b25d8 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 10/22] Add datetimestamp to exported session filename --- core/commands/slash/share.ts | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 4363ac0aa..eb15ced4e 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -3,11 +3,30 @@ import { homedir } from "os"; import { SlashCommand } from "../.."; import { stripImages } from "../../llm/countTokens"; +// If useful elsewhere, helper funcs should move to core/util/index.ts or similar +function getOffsetDatetime(date: Date): Date { + const offset = date.getTimezoneOffset(); + const offsetHours = Math.floor(offset / 60); + const offsetMinutes = offset % 60; + date.setHours(date.getHours() - offsetHours); + date.setMinutes(date.getMinutes() - offsetMinutes); + + return date; +} + +function asBasicISOString(date: Date): string { + const isoString = date.toISOString(); + + return isoString.replace(/[-:]/g, "").replace(/\.\d+Z/, ""); +} + const ShareSlashCommand: SlashCommand = { name: "share", description: "Export the current chat session to markdown", run: async function* ({ ide, history, params }) { - let content = `This is a session transcript from [Continue](https://continue.dev) on ${new Date().toLocaleString()}.`; + const now = new Date(); + + let content = `This is a session transcript from [Continue](https://continue.dev) on ${now.toLocaleString()}.`; for (const msg of history) { content += `\n\n## ${ @@ -22,8 +41,10 @@ const ShareSlashCommand: SlashCommand = { if (outputDir.startsWith("~")) { outputDir = outputDir.replace(/~/, homedir); } + //TODO: error handling, create path if it doesn't exist? + const workspaceDirs = await ide.getWorkspaceDirs(); - + // Although the most common situation is to have one directory open in a // workspace it's also possible to have just a file open without an // associated directory or to use multi-root workspaces in which multiple @@ -31,8 +52,9 @@ const ShareSlashCommand: SlashCommand = { // it exists. const workspaceDirectory = workspaceDirs?.[0] || ""; outputDir = outputDir.replace(/CURRENT_WORKSPACE/, workspaceDirectory); - const outPath = path.join(outputDir, `session.md`); //TODO: more flexible naming - + const dtString = asBasicISOString(getOffsetDatetime(now)); + const outPath = path.join(outputDir, `${dtString}_session.md`); //TODO: more flexible naming + //TODO: more flexible naming await ide.writeFile(outPath, content); await ide.openFile(outPath); From 91d92ab40af972d8c7e176d209411fbb04d1df96 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 11/22] Use `.`, `./`, or `.\` for current workspace --- core/commands/slash/share.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index eb15ced4e..608459669 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -51,10 +51,16 @@ const ShareSlashCommand: SlashCommand = { // folders are included. We default to using the first item in the list, if // it exists. const workspaceDirectory = workspaceDirs?.[0] || ""; - outputDir = outputDir.replace(/CURRENT_WORKSPACE/, workspaceDirectory); + if ( + outputDir.startsWith("./") || + outputDir.startsWith(`.\\`) || + outputDir === "." + ) { + outputDir = outputDir.replace(".", workspaceDirectory); + } + const dtString = asBasicISOString(getOffsetDatetime(now)); - const outPath = path.join(outputDir, `${dtString}_session.md`); //TODO: more flexible naming - //TODO: more flexible naming + const outPath = path.join(outputDir, `${dtString}_session.md`); //TODO: more flexible naming? await ide.writeFile(outPath, content); await ide.openFile(outPath); From 5f6077d171a147fb417a285a827b62dab5143c47 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 12/22] Add description of outputDir param for /share --- extensions/vscode/config_schema.json | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index df0c2b496..20732b9a3 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -1102,6 +1102,29 @@ } } } + }, + { + "if": { + "properties": { + "name": { + "enum": [ + "share" + ] + } + } + }, + "then": { + "properties": { + "params": { + "properties": { + "outputDir": { + "type": "string", + "markdownDescription": "If outputDir is set to `.` or begins with `./` or `.\\`, file will be saved to the current workspace or a subdirectory thereof, respectively. `~` can similarly be used to specify the user's home directory." + } + } + } + } + } } ], "required": ["name", "description"] From ca44dd4e23bcf46da187f9ef9aabfe40cdfa04e5 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 13/22] Ensure replacement only at start of string --- core/commands/slash/share.ts | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 608459669..72ab08105 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -38,25 +38,23 @@ const ShareSlashCommand: SlashCommand = { if (!outputDir) { outputDir = await ide.getContinueDir(); } + if (outputDir.startsWith("~")) { - outputDir = outputDir.replace(/~/, homedir); - } - //TODO: error handling, create path if it doesn't exist? - - const workspaceDirs = await ide.getWorkspaceDirs(); - - // Although the most common situation is to have one directory open in a - // workspace it's also possible to have just a file open without an - // associated directory or to use multi-root workspaces in which multiple - // folders are included. We default to using the first item in the list, if - // it exists. - const workspaceDirectory = workspaceDirs?.[0] || ""; - if ( + outputDir = outputDir.replace(/^~/, homedir); + } else if ( outputDir.startsWith("./") || outputDir.startsWith(`.\\`) || outputDir === "." ) { - outputDir = outputDir.replace(".", workspaceDirectory); + const workspaceDirs = await ide.getWorkspaceDirs(); + // Although the most common situation is to have one directory open in a + // workspace it's also possible to have just a file open without an + // associated directory or to use multi-root workspaces in which multiple + // folders are included. We default to using the first item in the list, if + // it exists. + const workspaceDirectory = workspaceDirs?.[0] || ""; + outputDir = outputDir.replace(/^./, workspaceDirectory); + } } const dtString = asBasicISOString(getOffsetDatetime(now)); From 41b9ef0f75bc27cb44f77715627b0513f0cd1165 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 14/22] Create user-specified directory if necessary --- core/commands/slash/share.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 72ab08105..9d7d88b1a 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -1,4 +1,5 @@ import path from "path"; +import * as fs from "fs"; import { homedir } from "os"; import { SlashCommand } from "../.."; import { stripImages } from "../../llm/countTokens"; @@ -55,6 +56,9 @@ const ShareSlashCommand: SlashCommand = { const workspaceDirectory = workspaceDirs?.[0] || ""; outputDir = outputDir.replace(/^./, workspaceDirectory); } + + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, { recursive: true }); } const dtString = asBasicISOString(getOffsetDatetime(now)); From 7d697d5bfe0d7c0ab91521ecd930f5f9c5ef215e Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 15/22] Change "Continue" to "Assistant" in export --- core/commands/slash/share.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 9d7d88b1a..605f5cc09 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -31,7 +31,7 @@ const ShareSlashCommand: SlashCommand = { for (const msg of history) { content += `\n\n## ${ - msg.role === "user" ? "User" : "Continue" + msg.role === "user" ? "User" : "Assistant" }\n\n${stripImages(msg.content)}`; } From 81103ff5f1710290872b0c3eda291569b3d0ee9d Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 16/22] Consolidate to single replace regex --- core/commands/slash/share.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 605f5cc09..c13d1d9fb 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -18,7 +18,7 @@ function getOffsetDatetime(date: Date): Date { function asBasicISOString(date: Date): string { const isoString = date.toISOString(); - return isoString.replace(/[-:]/g, "").replace(/\.\d+Z/, ""); + return isoString.replace(/[-:]|(\.\d+Z)/g, ""); } const ShareSlashCommand: SlashCommand = { From 338062016cc2d0adeaeede3de8982469e53c0f64 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 17/22] Reformat markdown code blocks Currently, user-selected code blocks are formatted with range in file (rif) info on the same line as the triple backticks, which means that when exported to markdown they don't have the language info needed on that line for syntax highlighting. This update moves the rif info to the following line as a comment in the language of the file and with the language info in the correct place. Before: ```example.ts (3-6) function fib(n) { if (n <= 1) return n; return fib(n - 2) + fib(n - 1); } ``` After: ```ts // example.ts (3-6) function fib(n) { if (n <= 1) return n; return fib(n - 2) + fib(n - 1); } ``` --- core/commands/slash/share.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index c13d1d9fb..08e91f654 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -2,6 +2,7 @@ import path from "path"; import * as fs from "fs"; import { homedir } from "os"; import { SlashCommand } from "../.."; +import { languageForFilepath } from "../../autocomplete/constructPrompt"; import { stripImages } from "../../llm/countTokens"; // If useful elsewhere, helper funcs should move to core/util/index.ts or similar @@ -21,6 +22,16 @@ function asBasicISOString(date: Date): string { return isoString.replace(/[-:]|(\.\d+Z)/g, ""); } +function reformatCodeBlocks(msgText: string): string { + const codeBlockRegex = /```(.*?\.(\w+)\s*.*)\n/g; + + return msgText.replace(codeBlockRegex, (match, metadata, extension) => { + const filename = metadata.split(" ")[0]; + const lang = languageForFilepath(filename); + return `\`\`\`${extension}\n${lang.comment} ${metadata}\n`; + }); +} + const ShareSlashCommand: SlashCommand = { name: "share", description: "Export the current chat session to markdown", @@ -30,9 +41,17 @@ const ShareSlashCommand: SlashCommand = { let content = `This is a session transcript from [Continue](https://continue.dev) on ${now.toLocaleString()}.`; for (const msg of history) { + let msgText = msg.content; + msgText = stripImages(msg.content); + + // if (msg.role === "user" && msgText.search("```") !== -1) { + if (msg.role === "user" && msgText.search("```") > -1) { + msgText = reformatCodeBlocks(msgText); + } + content += `\n\n## ${ msg.role === "user" ? "User" : "Assistant" - }\n\n${stripImages(msg.content)}`; + }\n\n${msgText}`; } let outputDir: string = params?.outputDir; From 7e0b4e4fb78ec546254c3bce5766f265409ae5a4 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 18/22] Tidy regex to capture filename --- core/commands/slash/share.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 08e91f654..fbcb04f5e 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -25,11 +25,12 @@ function asBasicISOString(date: Date): string { function reformatCodeBlocks(msgText: string): string { const codeBlockRegex = /```(.*?\.(\w+)\s*.*)\n/g; - return msgText.replace(codeBlockRegex, (match, metadata, extension) => { - const filename = metadata.split(" ")[0]; - const lang = languageForFilepath(filename); - return `\`\`\`${extension}\n${lang.comment} ${metadata}\n`; - }); + return msgText.replace(codeBlockRegex, + (match, metadata, filename, extension) => { + const lang = languageForFilepath(filename); + return `\`\`\`${extension}\n${lang.comment} ${metadata}\n`; + }, + ); } const ShareSlashCommand: SlashCommand = { From b82ccb76ad4706d23108a92e3990b136993ff65f Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 19/22] Tidy regex to capture filename --- core/commands/slash/share.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index fbcb04f5e..d9ed1ae95 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -23,7 +23,7 @@ function asBasicISOString(date: Date): string { } function reformatCodeBlocks(msgText: string): string { - const codeBlockRegex = /```(.*?\.(\w+)\s*.*)\n/g; + const codeBlockRegex = /```((.*?\.(\w+))\s*.*)\n/g; return msgText.replace(codeBlockRegex, (match, metadata, filename, extension) => { From 2565fa4f41d874ba723bb0bd4432d476f4728334 Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 20/22] Ensure adjacent codeblocks separated by newline --- core/commands/slash/share.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index d9ed1ae95..55f4eef9c 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -23,14 +23,15 @@ function asBasicISOString(date: Date): string { } function reformatCodeBlocks(msgText: string): string { - const codeBlockRegex = /```((.*?\.(\w+))\s*.*)\n/g; - - return msgText.replace(codeBlockRegex, + const codeBlockFenceRegex = /```((.*?\.(\w+))\s*.*)\n/g; + msgText = msgText.replace(codeBlockFenceRegex, (match, metadata, filename, extension) => { const lang = languageForFilepath(filename); return `\`\`\`${extension}\n${lang.comment} ${metadata}\n`; }, ); + // Appease the markdown linter + return msgText.replace(/```\n```/g, '```\n\n```'); } const ShareSlashCommand: SlashCommand = { From d71f4f70d807eb7952aa5dbc7bb9643a678fd61e Mon Sep 17 00:00:00 2001 From: Peter Zaback Date: Fri, 19 Apr 2024 14:29:30 -0500 Subject: [PATCH 21/22] Aesthetic tweaks to output format --- core/commands/slash/share.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index 55f4eef9c..c78b2ae4c 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -40,19 +40,23 @@ const ShareSlashCommand: SlashCommand = { run: async function* ({ ide, history, params }) { const now = new Date(); - let content = `This is a session transcript from [Continue](https://continue.dev) on ${now.toLocaleString()}.`; + let content = `### [Continue](https://continue.dev) session transcript\n Exported: ${now.toLocaleString()}`; - for (const msg of history) { + // As currently implemented, the /share command is by definition the last + // message in the chat history, this will omit it + for (const msg of history.slice(0, history.length - 1)) { let msgText = msg.content; msgText = stripImages(msg.content); - // if (msg.role === "user" && msgText.search("```") !== -1) { if (msg.role === "user" && msgText.search("```") > -1) { msgText = reformatCodeBlocks(msgText); } - content += `\n\n## ${ - msg.role === "user" ? "User" : "Assistant" + // format messages as blockquotes + msgText = msgText.replace(/^/gm, "> "); + + content += `\n\n#### ${ + msg.role === "user" ? "_User_" : "_Assistant_" }\n\n${msgText}`; } From 8c810186f19337280286103c4f42f000a260ad23 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Wed, 24 Apr 2024 00:11:38 -0700 Subject: [PATCH 22/22] =?UTF-8?q?=F0=9F=A9=B9=20remove=20example=20"output?= =?UTF-8?q?Dir"=20from=20default=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/default.ts | 2 -- docs/docs/config-file-migration.md | 1 - docs/docs/customization/slash-commands.md | 4 +++- docs/docs/walkthroughs/config-file-migration.md | 1 - gui/src/redux/slices/stateSlice.ts | 1 - 5 files changed, 3 insertions(+), 6 deletions(-) diff --git a/core/config/default.ts b/core/config/default.ts index c0d980ead..eec8675e9 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -40,7 +40,6 @@ export const defaultConfig: SerializedContinueConfig = { { name: "share", description: "Export the current chat session to markdown", - params: { ouputDir: "Directory in which to export this session" }, }, { name: "cmd", @@ -112,7 +111,6 @@ export const defaultConfigJetBrains: SerializedContinueConfig = { { name: "share", description: "Export the current chat session to markdown", - params: { ouputDir: "Directory in which to export this session" }, }, ], customCommands: [ diff --git a/docs/docs/config-file-migration.md b/docs/docs/config-file-migration.md index e894c71a8..f479442cf 100644 --- a/docs/docs/config-file-migration.md +++ b/docs/docs/config-file-migration.md @@ -132,7 +132,6 @@ After the "Full example" these examples will only show the relevant portion of t { "name": "share", "description": "Export the current chat session to markdown", - "params": { "ouputDir": "Directory in which to export this session" }, "step": "ShareSessionStep" }, { diff --git a/docs/docs/customization/slash-commands.md b/docs/docs/customization/slash-commands.md index c4cbb9ae6..da46f106c 100644 --- a/docs/docs/customization/slash-commands.md +++ b/docs/docs/customization/slash-commands.md @@ -44,10 +44,12 @@ Type "/share" to generate a shareable markdown transcript of your current chat h { "name": "share", "description": "Export the current chat session to markdown", - "params": { "ouputDir": "Directory in which to export this session" } + "params": { "ouputDir": "~/.continue/session-transcripts" } } ``` +Use the `ouputDir` parameter to specify where you want to the markdown file to be saved. + ### `/cmd` Generate a shell command from natural language and (only in VS Code) automatically paste it into the terminal. diff --git a/docs/docs/walkthroughs/config-file-migration.md b/docs/docs/walkthroughs/config-file-migration.md index 9b2df3650..e7feacb17 100644 --- a/docs/docs/walkthroughs/config-file-migration.md +++ b/docs/docs/walkthroughs/config-file-migration.md @@ -131,7 +131,6 @@ After the "Full example" these examples will only show the relevant portion of t { "name": "share", "description": "Export the current chat session to markdown", - "params": { "ouputDir": "Directory in which to save this session" }, "step": "ShareSessionStep" }, { diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index ff16fc49c..3bc7d6c5d 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -109,7 +109,6 @@ const initialState: State = { { name: "share", description: "Export the current chat session to markdown", - params: { ouputDir: "Directory in which to save this session" }, }, { name: "cmd",