Merge branch 'preview' into nate/vertical-diff

This commit is contained in:
Nate Sesti 2024-01-01 15:07:00 -05:00
commit 8a1900f91a
16 changed files with 124 additions and 68 deletions

View file

@ -0,0 +1,4 @@
project: extensions/intellij
kind: Added
body: diff context provider
time: 2023-12-29T10:58:15.432508-05:00

View file

@ -13,10 +13,6 @@ const defaultConfig: SerializedContinueConfig = {
model: "gpt-3.5-turbo",
},
],
modelRoles: {
default: "GPT-4",
summarize: "GPT-3.5-Turbo",
},
slashCommands: [
{
name: "edit",

View file

@ -441,7 +441,6 @@ declare global {
disallowedSteps?: string[];
allowAnonymousTelemetry?: boolean;
models: ModelDescription[];
modelRoles: ModelRoles;
systemMessage?: string;
completionOptions?: BaseCompletionOptions;
slashCommands?: SlashCommandDescription[];

1
core/index.d.ts vendored
View file

@ -453,7 +453,6 @@ export interface SerializedContinueConfig {
disallowedSteps?: string[];
allowAnonymousTelemetry?: boolean;
models: ModelDescription[];
modelRoles: ModelRoles;
systemMessage?: string;
completionOptions?: BaseCompletionOptions;
slashCommands?: SlashCommandDescription[];

View file

@ -14,7 +14,7 @@ If you need any help migrating, please reach out to us on Discord.
## Configuration as Code
> Continue has moved to using Typescript configuration. To learn about this, please see [Configuration as Code](../customization/code-config.md).
> Continue has moved to using Typescript configuration. To learn about this, please see [Configuration as Code](./customization/code-config.md).
For configuration that requires code, we now provide a simpler interface that works alongside config.json. In the same folder, `~/.continue`, create a file named `config.py` (the same name as before) and add a function called `modify_config`. This function should take a [`ContinueConfig`](https://github.com/continuedev/continue/blob/main/server/continuedev/core/config.py) object as its only argument, and return a `ContinueConfig` object. This object is essentially the same as the one that was previously defined in `config.py`. This allows you to modify the initial configuration object defined in your `config.json`. Here's an example that cuts the temperature in half:

View file

@ -54,33 +54,42 @@ However, if neither of these are the case, you will need to wire up a new LLM ob
## Customizing the Chat Template
Most open-source models expect a specific chat format, for example llama2 and codellama expect the input to look like `"[INST] How do I write bubble sort in Rust? [/INST]"`. Continue will automatically attempt to detect the correct prompt format based on the `model`value that you provide, but if you are receiving nonsense responses, you can use the`template`property to explicitly set the format that you expect. The options are:`["llama2", "alpaca", "zephyr", "phind", "anthropic", "chatml"]`.
Most open-source models expect a specific chat format, for example llama2 and codellama expect the input to look like `"[INST] How do I write bubble sort in Rust? [/INST]"`. Continue will automatically attempt to detect the correct prompt format based on the `model`value that you provide, but if you are receiving nonsense responses, you can use the`template`property to explicitly set the format that you expect. The options are:`["llama2", "alpaca", "zephyr", "phind", "anthropic", "chatml", "openchat", "none"]`.
If you want to create an entirely new chat template, this can be done in [config.ts](../customization/code-config.md) by defining a function and adding it to the `templateMessages` property of your `LLM`. Here is an example of `templateMessages` for the Alpaca/Vicuna format:
```python
def template_alpaca_messages(msgs: List[Dict[str, str]]) -> str:
prompt = ""
```typescript
function templateAlpacaMessages(msgs: ChatMessage[]): string {
let prompt = "";
if msgs[0]["role"] == "system":
prompt += f"{msgs[0]['content']}\n"
msgs.pop(0)
if (msgs[0].role === "system") {
prompt += `${msgs[0].content}\n`;
msgs.pop(0);
}
prompt += "### Instruction:\n"
for msg in msgs:
prompt += f"{msg['content']}\n"
prompt += "### Instruction:\n";
for (let msg of msgs) {
prompt += `${msg.content}\n`;
}
prompt += "### Response:\n"
prompt += "### Response:\n";
return prompt
return prompt;
}
```
It can then be used like this:
```python title="~/.continue/config.py"
def modify_config(config: ContinueConfig) -> ContinueConfig:
config.models.default.template_messages = template_alpaca_messages
return config
```typescript title="~/.continue/config.ts"
function modifyConfig(config: Config): Config {
const model = config.models.find(
(model) => model.title === "My Alpaca Model"
);
if (model) {
model.templateMessages = templateAlpacaMessages;
}
return config;
}
```
This exact function and a few other default implementations are available in [`continuedev.libs.llm.prompts.chat`](https://github.com/continuedev/continue/blob/main/server/continuedev/libs/llm/prompts/chat.py).
@ -89,28 +98,29 @@ This exact function and a few other default implementations are available in [`c
You also have access to customize the prompt used in the '/edit' slash command. We already have a well-engineered prompt for GPT-4 and sensible defaults for less powerful open-source models, but you might wish to play with the prompt and try to find a more reliable alternative if you are for example getting English as well as code in your output.
To customize the prompt, use the `prompt_templates` property of any `LLM`, which is a dictionary, and set the "edit" key to a template string with Mustache syntax. The 'file_prefix', 'file_suffix', 'code_to_edit', 'context_items', and 'user_input' variables are available in the template. Here is an example (the default for non-GPT-4 models):
To customize the prompt, use the `promptTemplates` property of any `LLM`, which is a dictionary, and set the "edit" key to a template string with Mustache syntax. The 'filePrefix', 'fileSuffix', 'codeToEdit', 'contextItems', and 'userInput' variables are available in the template. Here is an example (the default for non-GPT-4 models):
````python
"""
```typescript
`
[INST] Consider the following code:
```
{{{code_to_edit}}}
\`\`\`
{{{codeToEdit}}}
```
\`\`\`
Edit the code to perfectly satisfy the following user request:
{{{user_input}}}
{{{userInput}}}
Output nothing except for the code. No code block, no English explanation, no start/end tags.
[/INST]
"""
````
`;
```
It can then be used like this in `config.py`:
```python title="~/.continue/config.py"
def modify_config(config: ContinueConfig) -> ContinueConfig:
config.models.edit.prompt_templates["edit"] = "<INSERT_TEMPLATE_HERE>"
return config
```typescript title="~/.continue/config.py"
function modifyConfig(config: Config): Config {
config.models[0].promptTemplates["edit"] = "<INSERT_TEMPLATE_HERE>";
return config;
}
```
A few pre-made templates are available in [`continuedev.libs.llm.prompts.edit`](https://github.com/continuedev/continue/blob/main/server/continuedev/libs/llm/prompts/edit.py).

View file

@ -15,7 +15,7 @@ Continue makes it easy to swap out different LLM providers. You can either click
You can run a model on your local computer using:
- [Ollama](../reference/Model%20Providers/ollama.md)
- [LM Studio](../reference/Model%20Providers/ggml.md)
- [LM Studio](../reference/Model%20Providers/lmstudio.md)
- [Llama.cpp](../reference/Model%20Providers/llamacpp.md)
- [LocalAI](../reference/Model%20Providers/openai.md) (OpenAI compatible server)
- [Text generation web UI](../reference/Model%20Providers/openai.md) (OpenAI compatible server)
@ -54,4 +54,4 @@ You can use commercial LLMs via APIs using:
- [Azure OpenAI Service](../reference/Model%20Providers/openai.md) (OpenAI compatible API)
- [Anthrophic API](../reference/Model%20Providers/anthropicllm.md)
- [Google PaLM API](../reference/Model%20Providers/googlepalmapi.md)
- [OpenAI free trial](../reference/Model%20Providers/openaifreetrial.md)
- [OpenAI free trial](../reference/Model%20Providers/freetrial.md)

View file

@ -0,0 +1,17 @@
# LM Studio
[LM Studio](https://lmstudio.ai) is an application for Mac, Windows, and Linux that makes it easy to locally run open-source models and comes with a great UI. To get started with LM Studio, download from the website, use the UI to download a model, and then start the local inference server. Continue can then be configured to use the `LMStudio` LLM class:
```json title="~/.continue/config.json"
{
"models": [
{
"title": "LM Studio",
"provider": "lmstudio",
"model": "llama2-7b"
}
]
}
```
[View the source](https://github.com/continuedev/continue/blob/main/core/llm/llms/LMStudio.ts)

View file

@ -50,7 +50,6 @@ const sidebars = {
"walkthroughs/codellama",
"walkthroughs/manually-run-continue",
"walkthroughs/running-continue-without-internet",
"walkthroughs/headless-mode",
"walkthroughs/codebase-embeddings",
"walkthroughs/config-file-migration",
],

View file

@ -1,5 +1,6 @@
package com.github.continuedev.continueintellijextension.constants
import java.io.File
import java.nio.file.Files
import java.nio.file.Paths
@ -132,4 +133,22 @@ fun getDevDataFilepath(filename: String): String {
Files.createFile(path)
}
return path.toString()
}
fun getMigrationsFolderPath(): String {
val path = Paths.get(getContinueGlobalPath(), ".migrations")
if (Files.notExists(path)) {
Files.createDirectories(path)
}
return path.toString()
}
fun migrate(id: String, callback: () -> Unit) {
val migrationsPath = getMigrationsFolderPath()
val migrationPath = Paths.get(migrationsPath, id).toString()
val migrationFile = File(migrationPath)
if (!migrationFile.exists()) {
migrationFile.writeText("")
callback()
}
}

View file

@ -1,16 +1,18 @@
package com.github.continuedev.continueintellijextension.`continue`
import com.github.continuedev.continueintellijextension.*
import com.github.continuedev.continueintellijextension.constants.getConfigJsPath
import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath
import com.github.continuedev.continueintellijextension.constants.getContinueGlobalPath
import com.github.continuedev.continueintellijextension.constants.getDevDataFilepath
import com.github.continuedev.continueintellijextension.constants.*
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import com.google.gson.JsonObject
import com.google.gson.reflect.TypeToken
import com.intellij.execution.ExecutionManager
import com.intellij.execution.process.ProcessAdapter
import com.intellij.execution.process.ProcessEvent
import com.intellij.execution.ui.RunContentDescriptor
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.ServiceManager
@ -32,15 +34,13 @@ import com.intellij.ui.awt.RelativePoint
import kotlinx.coroutines.*
import net.minidev.json.JSONObject
import org.jetbrains.annotations.NotNull
import java.io.File
import java.io.FileInputStream
import java.io.FileReader
import java.io.FileWriter
import java.io.*
import java.net.NetworkInterface
import java.nio.charset.Charset
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import kotlin.coroutines.ContinuationInterceptor
fun uuid(): String {
@ -278,11 +278,37 @@ class IdeProtocolClient (
// NEW //
"getDiff" -> {
respond(null);
val builder = ProcessBuilder("git", "diff")
builder.directory(File(workspacePath ?: "."))
val process = builder.start()
val reader = BufferedReader(InputStreamReader(process.inputStream))
val output = StringBuilder()
var line: String? = reader.readLine()
while (line != null) {
output.append(line)
output.append("\n")
line = reader.readLine()
}
process.waitFor()
respond(output.toString());
}
"getSerializedConfig" -> {
val configPath = getConfigJsonPath()
val config = File(configPath).readText()
var config = File(configPath).readText()
migrate("camelCaseConfig") {
if (config.contains("_")) {
config = config
.replace(Regex("(_\\w)")) { it.value[1].uppercase() }
.replace("openai-aiohttp", "openai")
// Rewrite to config.json
File(configPath).writeText(config)
}
}
val mapType = object : TypeToken<Map<String, Any>>() {}.type
val parsed: Map<String, Any> = Gson().fromJson(config, mapType)
respond(parsed)

View file

@ -844,21 +844,6 @@
"$ref": "#/definitions/ModelDescription"
}
},
"modelRoles": {
"title": "Model Roles",
"description": "Roles for models. Each entry should be the title of a model in the models array.",
"default": {
"default": "GPT-4 (trial)",
"chat": null,
"edit": null,
"summarize": null
},
"allOf": [
{
"$ref": "#/definitions/ModelRoles"
}
]
},
"systemMessage": {
"title": "System Message",
"description": "A system message that will always be followed by the LLM",

View file

@ -1,12 +1,12 @@
{
"name": "continue",
"version": "0.7.61",
"version": "0.7.62",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "continue",
"version": "0.7.61",
"version": "0.7.62",
"license": "Apache-2.0",
"dependencies": {
"@electron/rebuild": "^3.2.10",

View file

@ -1,7 +1,7 @@
{
"name": "continue",
"icon": "media/icon.png",
"version": "0.7.61",
"version": "0.7.62",
"repository": {
"type": "git",
"url": "https://github.com/continuedev/continue"

View file

@ -276,7 +276,7 @@ function TipTapEditor(props: TipTapEditorProps) {
return;
}
if (editor && document.hasFocus()) {
editor.commands.focus()
editor.commands.focus();
}
const handler = async (event: any) => {
if (!editor) return;

View file

@ -18,7 +18,9 @@ function useSetup(dispatch: Dispatch<any>) {
try {
const ide = new ExtensionIde();
let serialized = await ide.getSerializedConfig();
console.log("serialized: ", serialized);
let intermediate = serializedToIntermediateConfig(serialized);
console.log("i1", intermediate);
const configJsUrl = await ide.getConfigJsUrl();
if (configJsUrl) {