Merge pull request #2937 from continuedev/nate/fixes
warn users when maxTokens too close to contextLength
This commit is contained in:
commit
dc7a61dfb6
4 changed files with 55 additions and 50 deletions
|
|
@ -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.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ Prompt files provide a convenient way to standardize common patterns and share a
|
|||
|
||||
## Quick start
|
||||
|
||||
:::tip[Prompt library]
|
||||
<!-- :::tip[Prompt library]
|
||||
To assist you in getting started, [we've curated a small library of `.prompt` files](https://github.com/continuedev/prompt-file-examples). We encourage community contributions to this repository, so please consider opening up a pull request with your own prompts!
|
||||
:::
|
||||
::: -->
|
||||
|
||||
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
|
||||
---
|
||||
<system>
|
||||
You are an expert programmer
|
||||
</system>
|
||||
|
||||
{{{ 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 <kbd>cmd/ctrl</kbd> + <kbd>L</kbd> 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 `<system></system>` 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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue