From b614c43f8dc791e5a1358dfa77c0de0cc9d845bf Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 11:44:41 -0800 Subject: [PATCH 1/4] warn users when maxTokens too close to contextLength --- core/config/validation.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/config/validation.ts b/core/config/validation.ts index ebcbb623d..062c0eaed 100644 --- a/core/config/validation.ts +++ b/core/config/validation.ts @@ -34,6 +34,18 @@ export function validateConfig(config: SerializedContinueConfig) { message: `Model at index ${index} has an invalid 'provider'.`, }); } + + if (model.contextLength && model.completionOptions?.maxTokens) { + const difference = + model.contextLength - model.completionOptions.maxTokens; + + if (difference < 1000) { + errors.push({ + fatal: false, + message: `Model "${model.title}" has a contextLength of ${model.contextLength} and a maxTokens of ${model.completionOptions.maxTokens}. This leaves only ${difference} tokens for input context and will likely result in your inputs being truncated.`, + }); + } + } }); } From 14b406075cc0db5101c71e7ab42be896eb38428a Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 12:20:37 -0800 Subject: [PATCH 2/4] enable images with azure provider --- core/llm/autodetect.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index 17f104a52..bebb8ead1 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -49,7 +49,7 @@ const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [ "mistral", "sambanova", "vertexai", - "watsonx" + "watsonx", ]; const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [ @@ -63,7 +63,8 @@ const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [ "sagemaker", "continue-proxy", "openrouter", - "vertexai" + "vertexai", + "azure", ]; const MODEL_SUPPORTS_IMAGES: string[] = [ @@ -121,7 +122,7 @@ const PARALLEL_PROVIDERS: ModelProvider[] = [ "together", "sambanova", "nebius", - "vertexai" + "vertexai", ]; function llmCanGenerateInParallel( From 3e4580d9f9a2dfaf200abfb1b8cdbc99cad60a11 Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 12:37:45 -0800 Subject: [PATCH 3/4] fix empty messages bug for all providers --- core/llm/countTokens.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/llm/countTokens.ts b/core/llm/countTokens.ts index 7ae3da1b7..9b30ad4bc 100644 --- a/core/llm/countTokens.ts +++ b/core/llm/countTokens.ts @@ -323,6 +323,27 @@ function pruneChatHistory( return chatHistory; } +function messageIsEmpty(message: ChatMessage): boolean { + if (typeof message.content === "string") { + return message.content.trim() === ""; + } + if (Array.isArray(message.content)) { + return message.content.every( + (item) => !item.imageUrl && item.text?.trim() === "", + ); + } + return false; +} + +function addSpaceToAnyEmptyMessages(messages: ChatMessage[]): ChatMessage[] { + return messages.map((message) => { + if (messageIsEmpty(message)) { + message.content = " "; + } + return message; + }); +} + function compileChatMessages( modelName: string, msgs: ChatMessage[] | undefined, @@ -333,12 +354,14 @@ function compileChatMessages( functions: any[] | undefined = undefined, systemMessage: string | undefined = undefined, ): ChatMessage[] { - const msgsCopy = msgs + let msgsCopy = msgs ? msgs .map((msg) => ({ ...msg })) .filter((msg) => msg.content !== "" && msg.role !== "system") : []; + msgsCopy = addSpaceToAnyEmptyMessages(msgsCopy); + if (prompt) { const promptMsg: ChatMessage = { role: "user", From 9d40e64169722282972b02c1d4b4bfaa5875eccf Mon Sep 17 00:00:00 2001 From: Nate Date: Thu, 14 Nov 2024 20:32:57 -0800 Subject: [PATCH 4/4] docs for prompt files v2 --- .../docs/customize/deep-dives/prompt-files.md | 61 +++++-------------- 1 file changed, 15 insertions(+), 46 deletions(-) diff --git a/docs/docs/customize/deep-dives/prompt-files.md b/docs/docs/customize/deep-dives/prompt-files.md index 928e01543..91f3557ea 100644 --- a/docs/docs/customize/deep-dives/prompt-files.md +++ b/docs/docs/customize/deep-dives/prompt-files.md @@ -6,9 +6,9 @@ Prompt files provide a convenient way to standardize common patterns and share a ## Quick start -:::tip[Prompt library] + Below is a quick example of setting up a prompt file to write unit tests using Jest. @@ -17,31 +17,19 @@ Below is a quick example of setting up a prompt file to write unit tests using J 3. Write the following contents to `test.prompt` and save. ``` -temperature: 0.5 -maxTokens: 4096 +name: Rails Project +description: Information about this project --- - -You are an expert programmer - - -{{{ input }}} - -Write unit tests for the above selected code, following each of these instructions: -- Use `jest` -- Properly set up and tear down -- Include important edge cases -- The tests should be complete and sophisticated -- Give the tests just as chat output, don't edit any file -- Don't explain how to set up `jest` +Attached is a summary of the current Ruby on Rails application, including the @Gemfile and database schema in @db/schema.rb ``` Now to use this prompt, you can highlight code and use cmd/ctrl + L to select it in the Continue sidebar. -Then, type "/" to see the list of slash commands and choose the one called "test". Press enter and the LLM will respond given the instructions from your prompt file. +Then, type "@", select "Prompt files", and choose the one called "Rails Project". You can now ask any question as usual and the LLM will have the information from your .prompt file. ## Format -The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to use context providers and built-in variables using [Handlebars syntax](https://handlebarsjs.com/guide/). +The format is inspired by [HumanLoops's .prompt file](https://docs.humanloop.com/docs/prompt-file-format), with additional templating to reference files, URLs, and context providers. :::info The current state of this format is experimental and subject to change @@ -51,38 +39,19 @@ The current state of this format is experimental and subject to change The "preamble" is everything above the `---` separator, and lets you specify model parameters. It uses YAML syntax and currently supports the following parameters: -- `name` -- `temperature` -- `topP` -- `topK` -- `minP` -- `presencePenalty` -- `frequencyPenalty` -- `mirostat` -- `stop` -- `maxTokens` -- `description` +- `name` - The display title +- `description` - The description you will see in the dropdown +- `version` - Can be either "1" (for legacy prompt files) or "2" (this is the default and does not need to be set) If you don't need any of these parameters, you can leave out the preamble and do not need to include the `---` separator. -### System message +### Context -To add a system message, start the body with `` tags like in the example above and place your system message inside. +Many [context provider](../context-providers.md) can be referenced by typing "@" followed by the name of the context provider. -### Built-in variables - -The following built-in variables are currently available: - -- `{{{ input }}}` - The full text from the input box in the sidebar that is sent along with the slash command -- `{{{ currentFile }}}` - The currently open file in your IDE -- `{{{ ./path/to/file.js }}}` - Any file can be directly referenced - -### Context providers - -Any [context provider](../context-providers.md) that you have added to your config can be referenced using the name of the context provider. Context providers that receive an input are also supported. - -- `{{{ terminal }}}` - The contents of the terminal -- `{{{ url "https://github.com/continuedev/continue" }}}` - The contents of a URL +- `@terminal` - The contents of the terminal +- `@https://github.com/continuedev/continue` - The contents of a URL +- `@src/index.ts` - The contents of a file ## Feedback