From 16c0f1d8f0785486b8bc57309304a514b0a80e0e Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 13 Nov 2023 18:26:17 -0800 Subject: [PATCH 01/15] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20introducing=20config?= =?UTF-8?q?.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/reference/Models/textgenui.md | 47 -- .../vscode/SerializedContinueConfig.json | 514 +++++++++++++ extensions/vscode/package.json | 6 + schema/json/ContinueConfig.json | 727 ------------------ schema/json/LLM.json | 6 + schema/json/Models.json | 6 + schema/json/SerializedContinueConfig.json | 514 +++++++++++++ server/config.py | 6 +- server/continuedev/__init__.py | 2 +- server/continuedev/__main__.py | 2 +- server/continuedev/core/autopilot.py | 2 +- .../continuedev/core/{ => config}/config.py | 113 +-- .../core/config/serialized_config.py | 197 +++++ server/continuedev/core/config/shared.py | 137 ++++ server/continuedev/core/models.py | 44 +- server/continuedev/core/sdk.py | 2 +- server/continuedev/headless/__init__.py | 2 +- server/continuedev/libs/index/build_index.py | 2 +- server/continuedev/libs/llm/base.py | 61 +- .../models/generate_json_schema.py | 4 +- server/continuedev/plugins/policies/commit.py | 2 +- .../continuedev/plugins/policies/default.py | 2 +- .../continuedev/plugins/policies/headless.py | 2 +- server/continuedev/server/main.py | 2 +- server/continuedev/server/protocols/gui.py | 4 +- server/continuedev/server/window_manager.py | 2 +- server/tests/step_test.py | 2 +- server/tests/util/config.py | 2 +- 28 files changed, 1503 insertions(+), 909 deletions(-) delete mode 100644 docs/docs/reference/Models/textgenui.md create mode 100644 extensions/vscode/SerializedContinueConfig.json delete mode 100644 schema/json/ContinueConfig.json create mode 100644 schema/json/SerializedContinueConfig.json rename server/continuedev/core/{ => config}/config.py (70%) create mode 100644 server/continuedev/core/config/serialized_config.py create mode 100644 server/continuedev/core/config/shared.py diff --git a/docs/docs/reference/Models/textgenui.md b/docs/docs/reference/Models/textgenui.md deleted file mode 100644 index 2f772611c..000000000 --- a/docs/docs/reference/Models/textgenui.md +++ /dev/null @@ -1,47 +0,0 @@ -import ClassPropertyRef from '@site/src/components/ClassPropertyRef.tsx'; - -# TextGenUI - -TextGenUI is a comprehensive, open-source language model UI and local server. You can set it up with an OpenAI-compatible server plugin, but if for some reason that doesn't work, you can use this class like so: - -```python title="~/.continue/config.py" -from continuedev.libs.llm.text_gen_interface import TextGenUI - -config = ContinueConfig( - ... - models=Models( - default=TextGenUI( - model="", - ) - ) -) -``` - -[View the source](https://github.com/continuedev/continue/tree/main/server/continuedev/libs/llm/text_gen_interface.py) - -## Properties - - - - - -### Inherited Properties - - - - - - - - - - - - - - - - - - - diff --git a/extensions/vscode/SerializedContinueConfig.json b/extensions/vscode/SerializedContinueConfig.json new file mode 100644 index 000000000..059755036 --- /dev/null +++ b/extensions/vscode/SerializedContinueConfig.json @@ -0,0 +1,514 @@ +{ + "title": "SerializedContinueConfig", + "$ref": "#/definitions/continuedev__core__config__serialized_config__SerializedContinueConfig", + "definitions": { + "StepWithParams": { + "title": "StepWithParams", + "type": "object", + "properties": { + "step": { + "title": "Step", + "enum": [ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep" + ], + "type": "string" + }, + "params": { + "title": "Params", + "type": "object" + } + }, + "required": [ + "step", + "params" + ] + }, + "BaseCompletionOptions": { + "title": "BaseCompletionOptions", + "type": "object", + "properties": { + "temperature": { + "title": "Temperature", + "description": "The temperature of the completion.", + "type": "number" + }, + "top_p": { + "title": "Top P", + "description": "The top_p of the completion.", + "type": "number" + }, + "top_k": { + "title": "Top K", + "description": "The top_k of the completion.", + "type": "integer" + }, + "presence_penalty": { + "title": "Presence Penalty", + "description": "The presence penalty Aof the completion.", + "type": "number" + }, + "frequency_penalty": { + "title": "Frequency Penalty", + "description": "The frequency penalty of the completion.", + "type": "number" + }, + "stop": { + "title": "Stop", + "description": "The stop tokens of the completion.", + "type": "array", + "items": { + "type": "string" + } + }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + } + } + }, + "RequestOptions": { + "title": "RequestOptions", + "type": "object", + "properties": { + "timeout": { + "title": "Timeout", + "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + "default": 300, + "type": "integer" + }, + "verify_ssl": { + "title": "Verify Ssl", + "description": "Whether to verify SSL certificates for requests.", + "type": "boolean" + }, + "ca_bundle_path": { + "title": "Ca Bundle Path", + "description": "Path to a custom CA bundle to use when making the HTTP request", + "type": "string" + }, + "proxy": { + "title": "Proxy", + "description": "Proxy URL to use when making the HTTP request", + "type": "string" + }, + "headers": { + "title": "Headers", + "description": "Headers to use when making the HTTP request", + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "ModelDescription": { + "title": "ModelDescription", + "type": "object", + "properties": { + "title": { + "title": "Title", + "description": "The title you wish to give your model.", + "type": "string" + }, + "provider": { + "title": "Provider", + "description": "The provider of the model. This is used to determine the type of model, and how to interact with it.", + "enum": [ + "openai", + "openai-free-trial", + "openai-aiohttp", + "anthropic", + "together", + "ollama", + "huggingface-tgi", + "huggingface-inference-api", + "llama.cpp", + "replicate", + "text-gen-webui", + "google-palm" + ], + "type": "string" + }, + "model": { + "title": "Model", + "description": "The name of the model. Used to autodetect prompt template.", + "type": "string" + }, + "api_key": { + "title": "Api Key", + "description": "OpenAI, Anthropic, Together, or other API key", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "The base URL of the LLM API.", + "type": "string" + }, + "context_length": { + "title": "Context Length", + "description": "The maximum context length of the LLM in tokens, as counted by count_tokens.", + "default": 2048, + "type": "integer" + }, + "template": { + "title": "Template", + "description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here.", + "enum": [ + "llama2", + "alpaca", + "zephyr", + "phind", + "anthropic", + "chatml" + ], + "type": "string" + }, + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "request_options": { + "title": "Request Options", + "description": "Options for the HTTP request to the LLM.", + "default": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "allOf": [ + { + "$ref": "#/definitions/RequestOptions" + } + ] + } + }, + "required": [ + "title", + "provider", + "model" + ] + }, + "ModelRoles": { + "title": "ModelRoles", + "type": "object", + "properties": { + "default": { + "title": "Default", + "description": "The default model. If other model roles are not set, they will fall back to default.", + "type": "string" + }, + "chat": { + "title": "Chat", + "description": "The model to use for chat. If not set, will fall back to default.", + "type": "string" + }, + "edit": { + "title": "Edit", + "description": "The model to use for editing. If not set, will fall back to default.", + "type": "string" + }, + "summarize": { + "title": "Summarize", + "description": "The model to use for summarization. If not set, will fall back to default.", + "type": "string" + } + }, + "required": [ + "default" + ] + }, + "SlashCommand": { + "title": "SlashCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "step": { + "title": "Step" + }, + "params": { + "title": "Params", + "default": {}, + "type": "object" + } + }, + "required": [ + "name", + "description", + "step" + ] + }, + "CustomCommand": { + "title": "CustomCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "prompt": { + "title": "Prompt", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + } + }, + "required": [ + "name", + "prompt", + "description" + ] + }, + "RetrievalSettings": { + "title": "RetrievalSettings", + "type": "object", + "properties": { + "n_retrieve": { + "title": "N Retrieve", + "description": "Number of results to initially retrieve from vector database", + "default": 50, + "type": "integer" + }, + "n_final": { + "title": "N Final", + "description": "Final number of results to use after re-ranking", + "default": 10, + "type": "integer" + }, + "use_reranking": { + "title": "Use Reranking", + "description": "Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", + "default": true, + "type": "boolean" + }, + "rerank_group_size": { + "title": "Rerank Group Size", + "description": "Number of results to group together when re-ranking. Each group will be processed in parallel.", + "default": 5, + "type": "integer" + }, + "ignore_files": { + "title": "Ignore Files", + "description": "Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "openai_api_key": { + "title": "Openai Api Key", + "description": "OpenAI API key", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "OpenAI API base URL", + "type": "string" + }, + "api_type": { + "title": "Api Type", + "description": "OpenAI API type", + "type": "string" + }, + "api_version": { + "title": "Api Version", + "description": "OpenAI API version", + "type": "string" + }, + "organization_id": { + "title": "Organization Id", + "description": "OpenAI organization ID", + "type": "string" + } + } + }, + "continuedev__core__config__serialized_config__SerializedContinueConfig": { + "title": "SerializedContinueConfig", + "type": "object", + "properties": { + "steps_on_startup": { + "title": "Steps On Startup", + "description": "Steps that will be automatically run at the beginning of a new session", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/StepWithParams" + } + }, + "disallowed_steps": { + "title": "Disallowed Steps", + "description": "Steps that are not allowed to be run, and will be skipped if attempted", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "allow_anonymous_telemetry": { + "title": "Allow Anonymous Telemetry", + "description": "If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", + "default": true, + "type": "boolean" + }, + "models": { + "title": "Models", + "default": [ + { + "title": "GPT-4 (trial)", + "provider": "openai-free-trial", + "model": "gpt-4", + "api_key": "" + } + ], + "type": "array", + "items": { + "$ref": "#/definitions/ModelDescription" + } + }, + "model_roles": { + "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" + } + ] + }, + "completion_options": { + "title": "Completion Options", + "description": "Default options for completion. These will be overriden by any options set for a specific model.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "slash_commands": { + "title": "Slash Commands", + "description": "An array of slash commands that let you map custom Steps to a shortcut.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/SlashCommand" + } + }, + "custom_commands": { + "title": "Custom Commands", + "description": "An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", + "default": [ + { + "name": "test", + "prompt": "Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", + "description": "This is an example custom command. Use /config to edit it and create more" + } + ], + "type": "array", + "items": { + "$ref": "#/definitions/CustomCommand" + } + }, + "context_providers": { + "title": "Context Providers", + "description": "A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/StepWithParams" + } + }, + "user_token": { + "title": "User Token", + "description": "An optional token to identify the user.", + "type": "string" + }, + "data_server_url": { + "title": "Data Server Url", + "description": "The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", + "default": "https://us-west1-autodebug.cloudfunctions.net", + "type": "string" + }, + "disable_summaries": { + "title": "Disable Summaries", + "description": "If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", + "default": false, + "type": "boolean" + }, + "disable_indexing": { + "title": "Disable Indexing", + "description": "If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", + "default": false, + "type": "boolean" + }, + "retrieval_settings": { + "title": "Retrieval Settings", + "description": "Settings for the retrieval system. Read more about the retrieval system in the documentation.", + "default": { + "n_retrieve": 50, + "n_final": 10, + "use_reranking": true, + "rerank_group_size": 5, + "ignore_files": [], + "openai_api_key": null, + "api_base": null, + "api_type": null, + "api_version": null, + "organization_id": null + }, + "allOf": [ + { + "$ref": "#/definitions/RetrievalSettings" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 06d4a1a77..549fb2d9e 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -274,6 +274,12 @@ } ] } + ], + "jsonValidation": [ + { + "fileMatch": "config.json", + "url": "./SerializedContinueConfig.json" + } ] }, "scripts": { diff --git a/schema/json/ContinueConfig.json b/schema/json/ContinueConfig.json deleted file mode 100644 index 71a76c055..000000000 --- a/schema/json/ContinueConfig.json +++ /dev/null @@ -1,727 +0,0 @@ -{ - "title": "ContinueConfig", - "$ref": "#/definitions/continuedev__core__config__ContinueConfig", - "definitions": { - "FunctionCall": { - "title": "FunctionCall", - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string" - }, - "arguments": { - "title": "Arguments", - "type": "string" - } - }, - "required": [ - "name", - "arguments" - ] - }, - "ChatMessage": { - "title": "ChatMessage", - "type": "object", - "properties": { - "role": { - "title": "Role", - "enum": [ - "assistant", - "user", - "system", - "function" - ], - "type": "string" - }, - "content": { - "title": "Content", - "type": "string" - }, - "name": { - "title": "Name", - "type": "string" - }, - "summary": { - "title": "Summary", - "type": "string" - }, - "function_call": { - "$ref": "#/definitions/FunctionCall" - } - }, - "required": [ - "role", - "summary" - ] - }, - "Step": { - "title": "Step", - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string" - }, - "hide": { - "title": "Hide", - "default": false, - "type": "boolean" - }, - "description": { - "title": "Description", - "default": "", - "type": "string" - }, - "class_name": { - "title": "Class Name", - "default": "Step", - "type": "string" - }, - "system_message": { - "title": "System Message", - "type": "string" - }, - "chat_context": { - "title": "Chat Context", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/ChatMessage" - } - }, - "manage_own_chat_context": { - "title": "Manage Own Chat Context", - "default": false, - "type": "boolean" - } - } - }, - "LLM": { - "title": "LLM", - "type": "object", - "properties": { - "title": { - "title": "Title", - "description": "A title that will identify this model in the model selection dropdown", - "type": "string" - }, - "unique_id": { - "title": "Unique Id", - "description": "The unique ID of the user.", - "type": "string" - }, - "model": { - "title": "Model", - "description": "The name of the model to be used (e.g. gpt-4, codellama)", - "type": "string" - }, - "system_message": { - "title": "System Message", - "description": "A system message that will always be followed by the LLM", - "type": "string" - }, - "context_length": { - "title": "Context Length", - "description": "The maximum context length of the LLM in tokens, as counted by count_tokens.", - "default": 2048, - "type": "integer" - }, - "stop_tokens": { - "title": "Stop Tokens", - "description": "Tokens that will stop the completion.", - "type": "array", - "items": { - "type": "string" - } - }, - "temperature": { - "title": "Temperature", - "description": "The temperature of the completion.", - "type": "number" - }, - "top_p": { - "title": "Top P", - "description": "The top_p of the completion.", - "type": "number" - }, - "top_k": { - "title": "Top K", - "description": "The top_k of the completion.", - "type": "integer" - }, - "presence_penalty": { - "title": "Presence Penalty", - "description": "The presence penalty Aof the completion.", - "type": "number" - }, - "frequency_penalty": { - "title": "Frequency Penalty", - "description": "The frequency penalty of the completion.", - "type": "number" - }, - "timeout": { - "title": "Timeout", - "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", - "default": 300, - "type": "integer" - }, - "verify_ssl": { - "title": "Verify Ssl", - "description": "Whether to verify SSL certificates for requests.", - "type": "boolean" - }, - "ca_bundle_path": { - "title": "Ca Bundle Path", - "description": "Path to a custom CA bundle to use when making the HTTP request", - "type": "string" - }, - "proxy": { - "title": "Proxy", - "description": "Proxy URL to use when making the HTTP request", - "type": "string" - }, - "headers": { - "title": "Headers", - "description": "Headers to use when making the HTTP request", - "type": "object", - "additionalProperties": { - "type": "string" - } - }, - "prompt_templates": { - "title": "Prompt Templates", - "description": "A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the \"edit\" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information.", - "default": {}, - "type": "object" - }, - "api_key": { - "title": "Api Key", - "description": "The API key for the LLM provider.", - "type": "string" - } - }, - "required": [ - "model" - ] - }, - "Models": { - "title": "Models", - "description": "Main class that holds the current model configuration", - "type": "object", - "properties": { - "default": { - "$ref": "#/definitions/LLM" - }, - "summarize": { - "$ref": "#/definitions/LLM" - }, - "edit": { - "$ref": "#/definitions/LLM" - }, - "chat": { - "$ref": "#/definitions/LLM" - }, - "saved": { - "title": "Saved", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/LLM" - } - }, - "temperature": { - "title": "Temperature", - "type": "number" - }, - "system_message": { - "title": "System Message", - "type": "string" - } - }, - "required": [ - "default" - ] - }, - "CustomCommand": { - "title": "CustomCommand", - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string" - }, - "prompt": { - "title": "Prompt", - "type": "string" - }, - "description": { - "title": "Description", - "type": "string" - } - }, - "required": [ - "name", - "prompt", - "description" - ] - }, - "SlashCommand": { - "title": "SlashCommand", - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string" - }, - "description": { - "title": "Description", - "type": "string" - }, - "step": { - "title": "Step" - }, - "params": { - "title": "Params", - "default": {}, - "type": "object" - } - }, - "required": [ - "name", - "description", - "step" - ] - }, - "Policy": { - "title": "Policy", - "description": "A rule that determines which step to take next", - "type": "object", - "properties": {} - }, - "ContextItemId": { - "title": "ContextItemId", - "description": "A ContextItemId is a unique identifier for a ContextItem.", - "type": "object", - "properties": { - "provider_title": { - "title": "Provider Title", - "type": "string" - }, - "item_id": { - "title": "Item Id", - "type": "string" - } - }, - "required": [ - "provider_title", - "item_id" - ] - }, - "ContextItemDescription": { - "title": "ContextItemDescription", - "description": "A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'.\n\nThe id can be used to retrieve the ContextItem from the ContextManager.", - "type": "object", - "properties": { - "name": { - "title": "Name", - "type": "string" - }, - "description": { - "title": "Description", - "type": "string" - }, - "id": { - "$ref": "#/definitions/ContextItemId" - } - }, - "required": [ - "name", - "description", - "id" - ] - }, - "ContextItem": { - "title": "ContextItem", - "description": "A ContextItem is a single item that is stored in the ContextManager.", - "type": "object", - "properties": { - "description": { - "$ref": "#/definitions/ContextItemDescription" - }, - "content": { - "title": "Content", - "type": "string" - }, - "editing": { - "title": "Editing", - "default": false, - "type": "boolean" - }, - "editable": { - "title": "Editable", - "default": false, - "type": "boolean" - } - }, - "required": [ - "description", - "content" - ] - }, - "ContextProvider": { - "title": "ContextProvider", - "description": "The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'.\nWhen you type '@', the context provider will be asked to populate a list of options.\nThese options will be updated on each keystroke.\nWhen you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object).", - "type": "object", - "properties": { - "title": { - "title": "Title", - "description": "The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider.", - "type": "string" - }, - "ide": { - "title": "Ide" - }, - "display_title": { - "title": "Display Title", - "description": "The display title of the ContextProvider shown in the dropdown menu", - "type": "string" - }, - "description": { - "title": "Description", - "description": "A description of the ContextProvider displayed in the dropdown menu", - "type": "string" - }, - "dynamic": { - "title": "Dynamic", - "description": "Indicates whether the ContextProvider is dynamic", - "type": "boolean" - }, - "requires_query": { - "title": "Requires Query", - "description": "Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query.", - "default": false, - "type": "boolean" - }, - "selected_items": { - "title": "Selected Items", - "description": "List of selected items in the ContextProvider", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/ContextItem" - } - } - }, - "required": [ - "title", - "display_title", - "description", - "dynamic" - ] - }, - "RetrievalSettings": { - "title": "RetrievalSettings", - "type": "object", - "properties": { - "n_retrieve": { - "title": "N Retrieve", - "description": "Number of results to initially retrieve from vector database", - "default": 50, - "type": "integer" - }, - "n_final": { - "title": "N Final", - "description": "Final number of results to use after re-ranking", - "default": 10, - "type": "integer" - }, - "use_reranking": { - "title": "Use Reranking", - "description": "Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", - "default": true, - "type": "boolean" - }, - "rerank_group_size": { - "title": "Rerank Group Size", - "description": "Number of results to group together when re-ranking. Each group will be processed in parallel.", - "default": 5, - "type": "integer" - }, - "ignore_files": { - "title": "Ignore Files", - "description": "Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", - "default": [], - "type": "array", - "items": { - "type": "string" - } - }, - "openai_api_key": { - "title": "Openai Api Key", - "description": "OpenAI API key", - "type": "string" - }, - "api_base": { - "title": "Api Base", - "description": "OpenAI API base URL", - "type": "string" - }, - "api_type": { - "title": "Api Type", - "description": "OpenAI API type", - "type": "string" - }, - "api_version": { - "title": "Api Version", - "description": "OpenAI API version", - "type": "string" - }, - "organization_id": { - "title": "Organization Id", - "description": "OpenAI organization ID", - "type": "string" - } - } - }, - "continuedev__core__config__ContinueConfig": { - "title": "ContinueConfig", - "description": "Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\\.continue\\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session.", - "type": "object", - "properties": { - "steps_on_startup": { - "title": "Steps On Startup", - "description": "Steps that will be automatically run at the beginning of a new session", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/Step" - } - }, - "disallowed_steps": { - "title": "Disallowed Steps", - "description": "Steps that are not allowed to be run, and will be skipped if attempted", - "default": [], - "type": "array", - "items": { - "type": "string" - } - }, - "allow_anonymous_telemetry": { - "title": "Allow Anonymous Telemetry", - "description": "If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", - "default": true, - "type": "boolean" - }, - "models": { - "title": "Models", - "description": "Configuration for the models used by Continue. Read more about how to configure models in the documentation.", - "default": { - "default": { - "title": null, - "model": "gpt-4", - "system_message": null, - "context_length": 2048, - "stop_tokens": null, - "temperature": null, - "top_p": null, - "top_k": null, - "presence_penalty": null, - "frequency_penalty": null, - "timeout": 300, - "verify_ssl": null, - "ca_bundle_path": null, - "proxy": null, - "headers": null, - "prompt_templates": {}, - "template_messages": null, - "api_key": null, - "llm": null, - "class_name": "OpenAIFreeTrial" - }, - "summarize": { - "title": null, - "model": "gpt-3.5-turbo", - "system_message": null, - "context_length": 2048, - "stop_tokens": null, - "temperature": null, - "top_p": null, - "top_k": null, - "presence_penalty": null, - "frequency_penalty": null, - "timeout": 300, - "verify_ssl": null, - "ca_bundle_path": null, - "proxy": null, - "headers": null, - "prompt_templates": {}, - "template_messages": null, - "api_key": null, - "llm": null, - "class_name": "OpenAIFreeTrial" - }, - "edit": { - "title": null, - "model": "gpt-4", - "system_message": null, - "context_length": 2048, - "stop_tokens": null, - "temperature": null, - "top_p": null, - "top_k": null, - "presence_penalty": null, - "frequency_penalty": null, - "timeout": 300, - "verify_ssl": null, - "ca_bundle_path": null, - "proxy": null, - "headers": null, - "prompt_templates": {}, - "template_messages": null, - "api_key": null, - "llm": null, - "class_name": "OpenAIFreeTrial" - }, - "chat": { - "title": null, - "model": "gpt-4", - "system_message": null, - "context_length": 2048, - "stop_tokens": null, - "temperature": null, - "top_p": null, - "top_k": null, - "presence_penalty": null, - "frequency_penalty": null, - "timeout": 300, - "verify_ssl": null, - "ca_bundle_path": null, - "proxy": null, - "headers": null, - "prompt_templates": {}, - "template_messages": null, - "api_key": null, - "llm": null, - "class_name": "OpenAIFreeTrial" - }, - "saved": [], - "temperature": null, - "system_message": null - }, - "allOf": [ - { - "$ref": "#/definitions/Models" - } - ] - }, - "temperature": { - "title": "Temperature", - "description": "The temperature parameter for sampling from the LLM. Higher temperatures will result in more random output, while lower temperatures will result in more predictable output. This value ranges from 0 to 1.", - "default": 0.5, - "type": "number" - }, - "custom_commands": { - "title": "Custom Commands", - "description": "An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", - "default": [ - { - "name": "test", - "prompt": "Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", - "description": "This is an example custom command. Use /config to edit it and create more" - } - ], - "type": "array", - "items": { - "$ref": "#/definitions/CustomCommand" - } - }, - "slash_commands": { - "title": "Slash Commands", - "description": "An array of slash commands that let you map custom Steps to a shortcut.", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/SlashCommand" - } - }, - "on_traceback": { - "title": "On Traceback", - "description": "The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R)", - "allOf": [ - { - "$ref": "#/definitions/Step" - } - ] - }, - "system_message": { - "title": "System Message", - "description": "A system message that will always be followed by the LLM", - "type": "string" - }, - "policy_override": { - "title": "Policy Override", - "description": "A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time.", - "allOf": [ - { - "$ref": "#/definitions/Policy" - } - ] - }, - "context_providers": { - "title": "Context Providers", - "description": "A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/ContextProvider" - } - }, - "user_token": { - "title": "User Token", - "description": "An optional token to identify the user.", - "type": "string" - }, - "data_server_url": { - "title": "Data Server Url", - "description": "The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", - "default": "https://us-west1-autodebug.cloudfunctions.net", - "type": "string" - }, - "disable_summaries": { - "title": "Disable Summaries", - "description": "If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", - "default": false, - "type": "boolean" - }, - "disable_indexing": { - "title": "Disable Indexing", - "description": "If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", - "default": false, - "type": "boolean" - }, - "retrieval_settings": { - "title": "Retrieval Settings", - "description": "Settings for the retrieval system. Read more about the retrieval system in the documentation.", - "default": { - "n_retrieve": 50, - "n_final": 10, - "use_reranking": true, - "rerank_group_size": 5, - "ignore_files": [], - "openai_api_key": null, - "api_base": null, - "api_type": null, - "api_version": null, - "organization_id": null - }, - "allOf": [ - { - "$ref": "#/definitions/RetrievalSettings" - } - ] - } - } - } - } -} \ No newline at end of file diff --git a/schema/json/LLM.json b/schema/json/LLM.json index cde480e86..be340014d 100644 --- a/schema/json/LLM.json +++ b/schema/json/LLM.json @@ -32,6 +32,12 @@ "default": 2048, "type": "integer" }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + }, "stop_tokens": { "title": "Stop Tokens", "description": "Tokens that will stop the completion.", diff --git a/schema/json/Models.json b/schema/json/Models.json index 10f4f8546..26812b3df 100644 --- a/schema/json/Models.json +++ b/schema/json/Models.json @@ -32,6 +32,12 @@ "default": 2048, "type": "integer" }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + }, "stop_tokens": { "title": "Stop Tokens", "description": "Tokens that will stop the completion.", diff --git a/schema/json/SerializedContinueConfig.json b/schema/json/SerializedContinueConfig.json new file mode 100644 index 000000000..059755036 --- /dev/null +++ b/schema/json/SerializedContinueConfig.json @@ -0,0 +1,514 @@ +{ + "title": "SerializedContinueConfig", + "$ref": "#/definitions/continuedev__core__config__serialized_config__SerializedContinueConfig", + "definitions": { + "StepWithParams": { + "title": "StepWithParams", + "type": "object", + "properties": { + "step": { + "title": "Step", + "enum": [ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep" + ], + "type": "string" + }, + "params": { + "title": "Params", + "type": "object" + } + }, + "required": [ + "step", + "params" + ] + }, + "BaseCompletionOptions": { + "title": "BaseCompletionOptions", + "type": "object", + "properties": { + "temperature": { + "title": "Temperature", + "description": "The temperature of the completion.", + "type": "number" + }, + "top_p": { + "title": "Top P", + "description": "The top_p of the completion.", + "type": "number" + }, + "top_k": { + "title": "Top K", + "description": "The top_k of the completion.", + "type": "integer" + }, + "presence_penalty": { + "title": "Presence Penalty", + "description": "The presence penalty Aof the completion.", + "type": "number" + }, + "frequency_penalty": { + "title": "Frequency Penalty", + "description": "The frequency penalty of the completion.", + "type": "number" + }, + "stop": { + "title": "Stop", + "description": "The stop tokens of the completion.", + "type": "array", + "items": { + "type": "string" + } + }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + } + } + }, + "RequestOptions": { + "title": "RequestOptions", + "type": "object", + "properties": { + "timeout": { + "title": "Timeout", + "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + "default": 300, + "type": "integer" + }, + "verify_ssl": { + "title": "Verify Ssl", + "description": "Whether to verify SSL certificates for requests.", + "type": "boolean" + }, + "ca_bundle_path": { + "title": "Ca Bundle Path", + "description": "Path to a custom CA bundle to use when making the HTTP request", + "type": "string" + }, + "proxy": { + "title": "Proxy", + "description": "Proxy URL to use when making the HTTP request", + "type": "string" + }, + "headers": { + "title": "Headers", + "description": "Headers to use when making the HTTP request", + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "ModelDescription": { + "title": "ModelDescription", + "type": "object", + "properties": { + "title": { + "title": "Title", + "description": "The title you wish to give your model.", + "type": "string" + }, + "provider": { + "title": "Provider", + "description": "The provider of the model. This is used to determine the type of model, and how to interact with it.", + "enum": [ + "openai", + "openai-free-trial", + "openai-aiohttp", + "anthropic", + "together", + "ollama", + "huggingface-tgi", + "huggingface-inference-api", + "llama.cpp", + "replicate", + "text-gen-webui", + "google-palm" + ], + "type": "string" + }, + "model": { + "title": "Model", + "description": "The name of the model. Used to autodetect prompt template.", + "type": "string" + }, + "api_key": { + "title": "Api Key", + "description": "OpenAI, Anthropic, Together, or other API key", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "The base URL of the LLM API.", + "type": "string" + }, + "context_length": { + "title": "Context Length", + "description": "The maximum context length of the LLM in tokens, as counted by count_tokens.", + "default": 2048, + "type": "integer" + }, + "template": { + "title": "Template", + "description": "The chat template used to format messages. This is auto-detected for most models, but can be overridden here.", + "enum": [ + "llama2", + "alpaca", + "zephyr", + "phind", + "anthropic", + "chatml" + ], + "type": "string" + }, + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "request_options": { + "title": "Request Options", + "description": "Options for the HTTP request to the LLM.", + "default": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "allOf": [ + { + "$ref": "#/definitions/RequestOptions" + } + ] + } + }, + "required": [ + "title", + "provider", + "model" + ] + }, + "ModelRoles": { + "title": "ModelRoles", + "type": "object", + "properties": { + "default": { + "title": "Default", + "description": "The default model. If other model roles are not set, they will fall back to default.", + "type": "string" + }, + "chat": { + "title": "Chat", + "description": "The model to use for chat. If not set, will fall back to default.", + "type": "string" + }, + "edit": { + "title": "Edit", + "description": "The model to use for editing. If not set, will fall back to default.", + "type": "string" + }, + "summarize": { + "title": "Summarize", + "description": "The model to use for summarization. If not set, will fall back to default.", + "type": "string" + } + }, + "required": [ + "default" + ] + }, + "SlashCommand": { + "title": "SlashCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "step": { + "title": "Step" + }, + "params": { + "title": "Params", + "default": {}, + "type": "object" + } + }, + "required": [ + "name", + "description", + "step" + ] + }, + "CustomCommand": { + "title": "CustomCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "prompt": { + "title": "Prompt", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + } + }, + "required": [ + "name", + "prompt", + "description" + ] + }, + "RetrievalSettings": { + "title": "RetrievalSettings", + "type": "object", + "properties": { + "n_retrieve": { + "title": "N Retrieve", + "description": "Number of results to initially retrieve from vector database", + "default": 50, + "type": "integer" + }, + "n_final": { + "title": "N Final", + "description": "Final number of results to use after re-ranking", + "default": 10, + "type": "integer" + }, + "use_reranking": { + "title": "Use Reranking", + "description": "Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", + "default": true, + "type": "boolean" + }, + "rerank_group_size": { + "title": "Rerank Group Size", + "description": "Number of results to group together when re-ranking. Each group will be processed in parallel.", + "default": 5, + "type": "integer" + }, + "ignore_files": { + "title": "Ignore Files", + "description": "Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "openai_api_key": { + "title": "Openai Api Key", + "description": "OpenAI API key", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "OpenAI API base URL", + "type": "string" + }, + "api_type": { + "title": "Api Type", + "description": "OpenAI API type", + "type": "string" + }, + "api_version": { + "title": "Api Version", + "description": "OpenAI API version", + "type": "string" + }, + "organization_id": { + "title": "Organization Id", + "description": "OpenAI organization ID", + "type": "string" + } + } + }, + "continuedev__core__config__serialized_config__SerializedContinueConfig": { + "title": "SerializedContinueConfig", + "type": "object", + "properties": { + "steps_on_startup": { + "title": "Steps On Startup", + "description": "Steps that will be automatically run at the beginning of a new session", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/StepWithParams" + } + }, + "disallowed_steps": { + "title": "Disallowed Steps", + "description": "Steps that are not allowed to be run, and will be skipped if attempted", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "allow_anonymous_telemetry": { + "title": "Allow Anonymous Telemetry", + "description": "If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", + "default": true, + "type": "boolean" + }, + "models": { + "title": "Models", + "default": [ + { + "title": "GPT-4 (trial)", + "provider": "openai-free-trial", + "model": "gpt-4", + "api_key": "" + } + ], + "type": "array", + "items": { + "$ref": "#/definitions/ModelDescription" + } + }, + "model_roles": { + "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" + } + ] + }, + "completion_options": { + "title": "Completion Options", + "description": "Default options for completion. These will be overriden by any options set for a specific model.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "slash_commands": { + "title": "Slash Commands", + "description": "An array of slash commands that let you map custom Steps to a shortcut.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/SlashCommand" + } + }, + "custom_commands": { + "title": "Custom Commands", + "description": "An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", + "default": [ + { + "name": "test", + "prompt": "Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", + "description": "This is an example custom command. Use /config to edit it and create more" + } + ], + "type": "array", + "items": { + "$ref": "#/definitions/CustomCommand" + } + }, + "context_providers": { + "title": "Context Providers", + "description": "A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/StepWithParams" + } + }, + "user_token": { + "title": "User Token", + "description": "An optional token to identify the user.", + "type": "string" + }, + "data_server_url": { + "title": "Data Server Url", + "description": "The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", + "default": "https://us-west1-autodebug.cloudfunctions.net", + "type": "string" + }, + "disable_summaries": { + "title": "Disable Summaries", + "description": "If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", + "default": false, + "type": "boolean" + }, + "disable_indexing": { + "title": "Disable Indexing", + "description": "If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", + "default": false, + "type": "boolean" + }, + "retrieval_settings": { + "title": "Retrieval Settings", + "description": "Settings for the retrieval system. Read more about the retrieval system in the documentation.", + "default": { + "n_retrieve": 50, + "n_final": 10, + "use_reranking": true, + "rerank_group_size": 5, + "ignore_files": [], + "openai_api_key": null, + "api_base": null, + "api_type": null, + "api_version": null, + "organization_id": null + }, + "allOf": [ + { + "$ref": "#/definitions/RetrievalSettings" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/server/config.py b/server/config.py index 513fee2c7..b023a4d24 100644 --- a/server/config.py +++ b/server/config.py @@ -5,7 +5,11 @@ See https://continue.dev/docs/customization to for documentation of the availabl """ from continuedev.core.models import Models -from continuedev.core.config import CustomCommand, SlashCommand, ContinueConfig +from continuedev.core.config.serialized_config import ( + CustomCommand, + SlashCommand, + ContinueConfig, +) from continuedev.libs.llm import OpenAIFreeTrial from continuedev.plugins.context_providers import ( diff --git a/server/continuedev/__init__.py b/server/continuedev/__init__.py index 9a26baeea..2fa7e7f47 100644 --- a/server/continuedev/__init__.py +++ b/server/continuedev/__init__.py @@ -1,7 +1,7 @@ import asyncio from typing import Union -from .core.config import ContinueConfig +from .core.config.serialized_config import ContinueConfig from .core.main import Step # from .headless import start_headless_session diff --git a/server/continuedev/__main__.py b/server/continuedev/__main__.py index 4fcdbd494..7d5714de3 100644 --- a/server/continuedev/__main__.py +++ b/server/continuedev/__main__.py @@ -3,7 +3,7 @@ import os from typing import Optional from tqdm import tqdm -from .core.config import ContinueConfig +from .core.config.serialized_config import ContinueConfig from .headless.headless_ide import LocalIdeProtocol from .libs.index.build_index import build_index from .libs.util.ext_to_lang import ext_to_lang diff --git a/server/continuedev/core/autopilot.py b/server/continuedev/core/autopilot.py index ba9946bbf..8bc15fb57 100644 --- a/server/continuedev/core/autopilot.py +++ b/server/continuedev/core/autopilot.py @@ -25,7 +25,7 @@ from ..server.protocols.ide_protocol import AbstractIdeProtocolServer from ..plugins.policies.default import DefaultPolicy from ..plugins.steps.on_traceback import DefaultOnTracebackStep -from .config import ContinueConfig +from .config.serialized_config import ContinueConfig from .main import ( AutopilotGenerator, AutopilotGeneratorOutput, diff --git a/server/continuedev/core/config.py b/server/continuedev/core/config/config.py similarity index 70% rename from server/continuedev/core/config.py rename to server/continuedev/core/config/config.py index 2267b6a6d..a5def0ac1 100644 --- a/server/continuedev/core/config.py +++ b/server/continuedev/core/config/config.py @@ -1,79 +1,29 @@ from typing import Dict, List, Optional, Type -from ..libs.util.edit_config import ( +from ...libs.llm.base import BaseCompletionOptions + +from .serialized_config import ( + CustomCommand, + RetrievalSettings, + SerializedContinueConfig, + SlashCommand, +) + +from ...libs.util.edit_config import ( create_bool_node, create_obj_node, display_llm_class, edit_config_property, ) -from ..libs.util.paths import convertConfigImports, getConfigFilePath +from ...libs.util.paths import convertConfigImports, getConfigFilePath from pydantic import BaseModel, Field, validator -from ..libs.llm.openai_free_trial import OpenAIFreeTrial -from .context import ContextProvider -from .main import ContextProviderDescription, Policy, SlashCommandDescription, Step -from .models import Models -from ..libs.util.telemetry import posthog_logger - - -class SlashCommand(BaseModel): - name: str - description: str - step: Type[Step] - params: Optional[Dict] = {} - - def dict(self, *args, **kwargs): - return { - "name": self.name, - "description": self.description, - "params": self.params, - "step": self.step.__name__, - } - - def slash_command_description(self) -> SlashCommandDescription: - return SlashCommandDescription( - name=self.name, - description=self.description, - ) - - -class CustomCommand(BaseModel): - name: str - prompt: str - description: str - - def slash_command_description(self) -> SlashCommandDescription: - return SlashCommandDescription( - name=self.name, - description=self.description, - ) - - -class RetrievalSettings(BaseModel): - n_retrieve: Optional[int] = Field( - 50, description="Number of results to initially retrieve from vector database" - ) - n_final: Optional[int] = Field( - 10, description="Final number of results to use after re-ranking" - ) - use_reranking: bool = Field( - True, - description="Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", - ) - rerank_group_size: int = Field( - 5, - description="Number of results to group together when re-ranking. Each group will be processed in parallel.", - ) - ignore_files: List[str] = Field( - [], - description="Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", - ) - openai_api_key: Optional[str] = Field(None, description="OpenAI API key") - api_base: Optional[str] = Field(None, description="OpenAI API base URL") - api_type: Optional[str] = Field(None, description="OpenAI API type") - api_version: Optional[str] = Field(None, description="OpenAI API version") - organization_id: Optional[str] = Field(None, description="OpenAI organization ID") +from ...libs.llm.openai_free_trial import OpenAIFreeTrial +from ..context import ContextProvider +from ..main import ContextProviderDescription, Policy, SlashCommandDescription, Step +from ..models import Models +from ...libs.util.telemetry import posthog_logger class ContinueConfig(BaseModel): @@ -100,9 +50,9 @@ class ContinueConfig(BaseModel): ), description="Configuration for the models used by Continue. Read more about how to configure models in the documentation.", ) - temperature: Optional[float] = Field( - 0.5, - description="The temperature parameter for sampling from the LLM. Higher temperatures will result in more random output, while lower temperatures will result in more predictable output. This value ranges from 0 to 1.", + completion_options: BaseCompletionOptions = Field( + BaseCompletionOptions(), + description="Options for the completion endpoint. Read more about the completion options in the documentation.", ) custom_commands: Optional[List[CustomCommand]] = Field( [ @@ -122,9 +72,6 @@ class ContinueConfig(BaseModel): None, description="The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R)", ) - system_message: Optional[str] = Field( - None, description="A system message that will always be followed by the LLM" - ) policy_override: Optional[Policy] = Field( None, description="A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time.", @@ -153,15 +100,27 @@ class ContinueConfig(BaseModel): description="Settings for the retrieval system. Read more about the retrieval system in the documentation.", ) - @classmethod - def schema(cls, *args, **kwargs): - # kwargs.setdefault("exclude", {"ide"}) - return super().schema(*args, **kwargs) - @validator("temperature", pre=True) def temperature_validator(cls, v): return max(0.0, min(1.0, v)) + @staticmethod + def from_serialized_config(config: SerializedContinueConfig) -> "ContinueConfig": + return ContinueConfig( + disallowed_steps=config.disallowed_steps, + allow_anonymous_telemetry=config.allow_anonymous_telemetry, + models=Models.from_serialized_config(config), + completion_options=config.completion_options, + custom_commands=config.custom_commands, + slash_commands=config.slash_commands, + context_providers=config.context_providers, + user_token=config.user_token, + data_server_url=config.data_server_url, + disable_summaries=config.disable_summaries, + disable_indexing=config.disable_indexing, + retrieval_settings=config.retrieval_settings, + ) + @staticmethod def from_filepath(filepath: str, retry: bool = True) -> "ContinueConfig": # Use importlib to load the config file config.py at the given path diff --git a/server/continuedev/core/config/serialized_config.py b/server/continuedev/core/config/serialized_config.py new file mode 100644 index 000000000..ee31d5e47 --- /dev/null +++ b/server/continuedev/core/config/serialized_config.py @@ -0,0 +1,197 @@ +from typing import Any, Dict, List, Literal, Optional, Type +from .shared import ModelProvider, RequestOptions, StepName, TemplateType +from pydantic import BaseModel, Field + +from ...libs.llm.base import BaseCompletionOptions +from ..main import SlashCommandDescription, Step + + +class StepWithParams(BaseModel): + step: StepName + params: Dict[str, Any] + + +class SlashCommand(BaseModel): + name: str + description: str + step: Type[Step] + params: Optional[Dict] = {} + + def dict(self, *args, **kwargs): + return { + "name": self.name, + "description": self.description, + "params": self.params, + "step": self.step.__name__, + } + + def slash_command_description(self) -> SlashCommandDescription: + return SlashCommandDescription( + name=self.name, + description=self.description, + ) + + +class CustomCommand(BaseModel): + name: str + prompt: str + description: str + + def slash_command_description(self) -> SlashCommandDescription: + return SlashCommandDescription( + name=self.name, + description=self.description, + ) + + +class RetrievalSettings(BaseModel): + n_retrieve: Optional[int] = Field( + 50, description="Number of results to initially retrieve from vector database" + ) + n_final: Optional[int] = Field( + 10, description="Final number of results to use after re-ranking" + ) + use_reranking: bool = Field( + True, + description="Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", + ) + rerank_group_size: int = Field( + 5, + description="Number of results to group together when re-ranking. Each group will be processed in parallel.", + ) + ignore_files: List[str] = Field( + [], + description="Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", + ) + openai_api_key: Optional[str] = Field(None, description="OpenAI API key") + api_base: Optional[str] = Field(None, description="OpenAI API base URL") + api_type: Optional[str] = Field(None, description="OpenAI API type") + api_version: Optional[str] = Field(None, description="OpenAI API version") + organization_id: Optional[str] = Field(None, description="OpenAI organization ID") + + +class ModelDescription(BaseModel): + title: str = Field( + ..., + description="The title you wish to give your model.", + ) + + provider: ModelProvider = Field( + ..., + description="The provider of the model. This is used to determine the type of model, and how to interact with it.", + ) + model: str = Field( + ..., + description="The name of the model. Used to autodetect prompt template.", + ) + api_key: Optional[str] = Field( + None, description="OpenAI, Anthropic, Together, or other API key" + ) + api_base: Optional[str] = Field(None, description="The base URL of the LLM API.") + + context_length: int = Field( + 2048, + description="The maximum context length of the LLM in tokens, as counted by count_tokens.", + ) + template: Optional[TemplateType] = Field( + None, + description="The chat template used to format messages. This is auto-detected for most models, but can be overridden here.", + ) + completion_options: BaseCompletionOptions = Field( + BaseCompletionOptions(), + description="Options for the completion endpoint. Read more about the completion options in the documentation.", + ) + system_message: Optional[str] = Field( + None, + description="A system message that will always be followed by the LLM", + ) + + request_options: RequestOptions = Field( + RequestOptions(), + description="Options for the HTTP request to the LLM.", + ) + + +class ModelRoles(BaseModel): + default: str = Field( + ..., + description="The default model. If other model roles are not set, they will fall back to default.", + ) + chat: Optional[str] = Field( + None, + description="The model to use for chat. If not set, will fall back to default.", + ) + edit: Optional[str] = Field( + None, + description="The model to use for editing. If not set, will fall back to default.", + ) + summarize: Optional[str] = Field( + None, + description="The model to use for summarization. If not set, will fall back to default.", + ) + + +class SerializedContinueConfig(BaseModel): + disallowed_steps: Optional[List[str]] = Field( + [], + description="Steps that are not allowed to be run, and will be skipped if attempted", + ) + allow_anonymous_telemetry: Optional[bool] = Field( + True, + description="If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", + ) + models: List[ModelDescription] = Field( + [ + { + "title": "GPT-4 (trial)", + "provider": "openai-free-trial", + "model": "gpt-4", + "api_key": "", + } + ] + ) + model_roles: ModelRoles = Field( + ModelRoles(default="GPT-4 (trial)"), + description="Roles for models. Each entry should be the title of a model in the models array.", + ) + completion_options: BaseCompletionOptions = Field( + BaseCompletionOptions(), + description="Default options for completion. These will be overriden by any options set for a specific model.", + ) + slash_commands: Optional[List[SlashCommand]] = Field( + [], + description="An array of slash commands that let you map custom Steps to a shortcut.", + ) + custom_commands: Optional[List[CustomCommand]] = Field( + [ + CustomCommand( + name="test", + description="This is an example custom command. Use /config to edit it and create more", + prompt="Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", + ) + ], + description="An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", + ) + context_providers: List[StepWithParams] = Field( + [], + description="A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", + ) + user_token: Optional[str] = Field( + None, description="An optional token to identify the user." + ) + data_server_url: Optional[str] = Field( + "https://us-west1-autodebug.cloudfunctions.net", + description="The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", + ) + disable_summaries: Optional[bool] = Field( + False, + description="If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", + ) + disable_indexing: Optional[bool] = Field( + False, + description="If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", + ) + retrieval_settings: Optional[RetrievalSettings] = Field( + RetrievalSettings(), + description="Settings for the retrieval system. Read more about the retrieval system in the documentation.", + ) diff --git a/server/continuedev/core/config/shared.py b/server/continuedev/core/config/shared.py new file mode 100644 index 000000000..675fa46aa --- /dev/null +++ b/server/continuedev/core/config/shared.py @@ -0,0 +1,137 @@ +from typing import Dict, Literal, Optional +from pydantic import BaseModel, Field + +from ...libs.llm.prompts.chat import ( + llama2_template_messages, + template_alpaca_messages, + phind_template_messages, + zephyr_template_messages, + chatml_template_messages, + anthropic_template_messages, +) + +from ...libs.llm.prompts.edit import ( + codellama_edit_prompt, + alpaca_edit_prompt, + simplest_edit_prompt, +) # TODO: Prompts for the rest of the template types + + +StepName = Literal[ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep", +] + +TemplateType = Literal["llama2", "alpaca", "zephyr", "phind", "anthropic", "chatml"] + + +def autodetect_template_type(model: str) -> Optional[TemplateType]: + lower = model.lower() + if "gpt" in lower or "chat-bison" in lower: + return None + + if "phind" in lower: + return "phind" + + if "llama" in lower: + return "llama2" + + if "zephyr" in lower: + return "zephyr" + + if "claude" in lower: + return "anthropic" + + if "alpaca" in lower or "wizard" in lower: + return "alpaca" + + return "chatml" + + +def autodetect_template_function(model: str): + template_type = autodetect_template_type(model) + return { + "llama2": llama2_template_messages, + "alpaca": template_alpaca_messages, + "phind": phind_template_messages, + "zephyr": zephyr_template_messages, + "anthropic": anthropic_template_messages, + "chatml": chatml_template_messages, + }[template_type] + + +def autodetect_prompt_templates(model: str): + template_type = autodetect_template_type(model) + + templates = {} + + edit_template = None + if template_type == "llama2": + edit_template = codellama_edit_prompt + elif template_type == "alpaca": + edit_template = alpaca_edit_prompt + elif template_type is not None: + edit_template = simplest_edit_prompt + + if edit_template is not None: + templates["edit"] = edit_template + + return templates + + +ModelProvider = Literal[ + "openai", + "openai-free-trial", + "openai-aiohttp", + "anthropic", + "together", + "ollama", + "huggingface-tgi", + "huggingface-inference-api", + "llama.cpp", + "replicate", + "text-gen-webui", + "google-palm", +] + +MODEL_PROVIDER_TO_MODEL_CLASS = { + "openai": "OpenAI", + "openai-free-trial": "OpenAIFreeTrial", + "openai-aiohttp": "OpenAIFreeTrial", + "anthropic": "AnthropicLLM", + "together": "TogetherLLM", + "ollama": "Ollama", + "huggingface-tgi": "HuggingFaceTGI", + "huggingface-inference-api": "HuggingFaceInferenceAPI", + "llama.cpp": "LlamaCpp", + "replicate": "ReplicateLLM", + "text-gen-webui": "TextGenWebUI", + "google-palm": "GooglePaLMAPI", +} + + +class RequestOptions(BaseModel): + timeout: Optional[int] = Field( + 300, + description="Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + ) + verify_ssl: Optional[bool] = Field( + None, description="Whether to verify SSL certificates for requests." + ) + ca_bundle_path: str = Field( + None, + description="Path to a custom CA bundle to use when making the HTTP request", + ) + proxy: Optional[str] = Field( + None, + description="Proxy URL to use when making the HTTP request", + ) + headers: Optional[Dict[str, str]] = Field( + None, + description="Headers to use when making the HTTP request", + ) diff --git a/server/continuedev/core/models.py b/server/continuedev/core/models.py index 2e94d4b7b..7e887ec59 100644 --- a/server/continuedev/core/models.py +++ b/server/continuedev/core/models.py @@ -1,5 +1,6 @@ -from typing import Callable, List, Optional +from typing import Callable, Dict, List, Optional import uuid +from .config.serialized_config import ModelDescription, SerializedContinueConfig from pydantic import BaseModel, validator @@ -16,6 +17,11 @@ from ..libs.llm.openai_free_trial import OpenAIFreeTrial from ..libs.llm.replicate import ReplicateLLM from ..libs.llm.together import TogetherLLM from ..libs.llm.text_gen_webui import TextGenWebUI +from ..core.config.shared import ( + MODEL_PROVIDER_TO_MODEL_CLASS, + autodetect_prompt_templates, + autodetect_template_function, +) class ContinueSDK(BaseModel): @@ -29,7 +35,7 @@ ALL_MODEL_ROLES = [ "chat", ] -MODEL_CLASSES = { +MODEL_CLASSES: Dict[str, LLM] = { cls.__name__: cls for cls in [ OpenAI, @@ -88,6 +94,40 @@ class Models(BaseModel): return values["default"] return v + @staticmethod + def from_serialized_config(config: SerializedContinueConfig) -> "Models": + def model_with_title(title: str, fallback: ModelDescription): + return next(filter(lambda x: x.title == title, config.models), fallback) + + default = model_with_title(config.model_roles.default, config.models[0]) + chat = model_with_title(config.model_roles.chat, default) + edit = model_with_title(config.model_roles.edit, default) + summarize = model_with_title(config.model_roles.summarize, default) + + def create_llm(model: ModelDescription) -> LLM: + model_class = MODEL_CLASSES[MODEL_PROVIDER_TO_MODEL_CLASS[model.provider]] + completion_options = config.completion_options.dict() + completion_options.update(model.completion_options.dict(exclude_none=True)) + model_class.system_message = model.system_message + return LLM( + api_key=model.api_key, + completion_options=completion_options, + request_options=model.request_options, + system_message=model.system_message, + api_base=model.api_base, # TODO + model=model.model, + template_messages=autodetect_template_function(model.model), + prompt_templates=autodetect_prompt_templates(model.model), + context_length=model.context_length, + ) # TODO: This doesn't yet match up with all of the fields. Check individual model types. Update them. Update the docs. + + return Models( + default=create_llm(default), + chat=create_llm(chat), + edit=create_llm(edit), + summarize=create_llm(summarize), + ) + def dict(self, **kwargs): original_dict = super().dict(**kwargs) return original_dict diff --git a/server/continuedev/core/sdk.py b/server/continuedev/core/sdk.py index bd83eac97..62261eafc 100644 --- a/server/continuedev/core/sdk.py +++ b/server/continuedev/core/sdk.py @@ -17,7 +17,7 @@ from ..models.filesystem_edit import ( from ..models.main import Range from ..server.protocols.ide_protocol import AbstractIdeProtocolServer from ..server.protocols.gui_protocol import AbstractGUIProtocolServer -from .config import ContinueConfig +from .config.serialized_config import ContinueConfig from .lsp import ContinueLSPClient from .main import ( ChatMessage, diff --git a/server/continuedev/headless/__init__.py b/server/continuedev/headless/__init__.py index 5bebf3cc7..b6df59f51 100644 --- a/server/continuedev/headless/__init__.py +++ b/server/continuedev/headless/__init__.py @@ -6,7 +6,7 @@ from ..core.context import ContextManager, ContextProvider from ..core.main import SessionState from ..core.autopilot import Autopilot from .headless_ide import LocalIdeProtocol -from ..core.config import ContinueConfig +from ..core.config.serialized_config import ContinueConfig async def get_headless_autopilot( diff --git a/server/continuedev/libs/index/build_index.py b/server/continuedev/libs/index/build_index.py index 30dfa3409..5d38939a3 100644 --- a/server/continuedev/libs/index/build_index.py +++ b/server/continuedev/libs/index/build_index.py @@ -1,6 +1,6 @@ import asyncio from typing import AsyncGenerator -from ...core.config import ContinueConfig +from ...core.config.serialized_config import ContinueConfig from ...server.protocols.ide_protocol import AbstractIdeProtocolServer from ...libs.index.chunkers.chunk_directory import ( stream_chunk_directory, diff --git a/server/continuedev/libs/llm/base.py b/server/continuedev/libs/llm/base.py index c72d8052f..97b8e3a90 100644 --- a/server/continuedev/libs/llm/base.py +++ b/server/continuedev/libs/llm/base.py @@ -5,6 +5,7 @@ from typing import Any, Callable, Coroutine, Dict, Generator, List, Optional, Un import aiohttp import certifi +from ...core.config.shared import RequestOptions from ..util.templating import render_templated_string from pydantic import Field, validator @@ -24,9 +25,7 @@ from ..util.telemetry import posthog_logger from ..util.logging import logger -class CompletionOptions(ContinueBaseModel): - """Options for the completion.""" - +class BaseCompletionOptions(ContinueBaseModel): @validator( "*", pre=True, @@ -35,7 +34,6 @@ class CompletionOptions(ContinueBaseModel): def ignore_none_and_set_default(cls, value, field): return value if value is not None else field.default - model: Optional[str] = Field(None, description="The model name") temperature: Optional[float] = Field( None, description="The temperature of the completion." ) @@ -53,6 +51,20 @@ class CompletionOptions(ContinueBaseModel): max_tokens: int = Field( DEFAULT_MAX_TOKENS, description="The maximum number of tokens to generate." ) + + +class CompletionOptions(BaseCompletionOptions): + """Options for the completion.""" + + @validator( + "*", + pre=True, + always=True, + ) + def ignore_none_and_set_default(cls, value, field): + return value if value is not None else field.default + + model: Optional[str] = Field(None, description="The model name") functions: Optional[List[Any]] = Field( None, description="The functions/tools to make available to the model." ) @@ -82,44 +94,17 @@ class LLM(ContinueBaseModel): 2048, description="The maximum context length of the LLM in tokens, as counted by count_tokens.", ) - max_tokens: int = Field( - DEFAULT_MAX_TOKENS, description="The maximum number of tokens to generate." + + completion_options: BaseCompletionOptions = Field( + BaseCompletionOptions(), + description="Options for the completion endpoint. Read more about the completion options in the documentation.", ) - stop_tokens: Optional[List[str]] = Field( - None, description="Tokens that will stop the completion." - ) - temperature: Optional[float] = Field( - None, description="The temperature of the completion." - ) - top_p: Optional[float] = Field(None, description="The top_p of the completion.") - top_k: Optional[int] = Field(None, description="The top_k of the completion.") - presence_penalty: Optional[float] = Field( - None, description="The presence penalty Aof the completion." - ) - frequency_penalty: Optional[float] = Field( - None, description="The frequency penalty of the completion." + request_options: RequestOptions = Field( + RequestOptions(), + description="Options for the HTTP request to the LLM.", ) - timeout: Optional[int] = Field( - 300, - description="Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", - ) - verify_ssl: Optional[bool] = Field( - None, description="Whether to verify SSL certificates for requests." - ) - ca_bundle_path: str = Field( - None, - description="Path to a custom CA bundle to use when making the HTTP request", - ) - proxy: Optional[str] = Field( - None, - description="Proxy URL to use when making the HTTP request", - ) - headers: Optional[Dict[str, str]] = Field( - None, - description="Headers to use when making the HTTP request", - ) prompt_templates: dict = Field( {}, description='A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information.', diff --git a/server/continuedev/models/generate_json_schema.py b/server/continuedev/models/generate_json_schema.py index abe8b4003..fef9f2a5f 100644 --- a/server/continuedev/models/generate_json_schema.py +++ b/server/continuedev/models/generate_json_schema.py @@ -2,7 +2,7 @@ import os from pydantic import schema_json_of -from ..core.config import ContinueConfig +from ..core.config.serialized_config import SerializedContinueConfig from ..core.context import ContextItem, ContextItemId from ..core.main import ( SessionInfo, @@ -31,7 +31,7 @@ MODELS_TO_GENERATE = ( SlashCommandDescription, ContextProviderDescription, ] - + [ContinueConfig] + + [SerializedContinueConfig] + [ContextItem, ContextItemId] + [Models] + [LLM] diff --git a/server/continuedev/plugins/policies/commit.py b/server/continuedev/plugins/policies/commit.py index 2e649aec7..0ff002c09 100644 --- a/server/continuedev/plugins/policies/commit.py +++ b/server/continuedev/plugins/policies/commit.py @@ -12,7 +12,7 @@ from textwrap import dedent from typing import Literal -from ...core.config import ContinueConfig +from ...core.config.serialized_config import ContinueConfig from ...core.main import Policy, SessionState, Step from ...core.observation import TextObservation from ...core.sdk import ContinueSDK diff --git a/server/continuedev/plugins/policies/default.py b/server/continuedev/plugins/policies/default.py index e1b06d29e..9a881b1cf 100644 --- a/server/continuedev/plugins/policies/default.py +++ b/server/continuedev/plugins/policies/default.py @@ -7,7 +7,7 @@ from ..steps.clear_history import ClearHistoryStep from ..steps.comment_code import CommentCodeStep from ..steps.share_session import ShareSessionStep from ..steps.codebase import AnswerQuestionChroma -from ...core.config import ContinueConfig +from ...core.config.serialized_config import ContinueConfig from ...core.main import Policy, SessionState, Step from ..steps.chat import SimpleChatStep from ..steps.custom_command import CustomCommandStep diff --git a/server/continuedev/plugins/policies/headless.py b/server/continuedev/plugins/policies/headless.py index 19f36a88a..3dcc4a007 100644 --- a/server/continuedev/plugins/policies/headless.py +++ b/server/continuedev/plugins/policies/headless.py @@ -1,4 +1,4 @@ -from ...core.config import ContinueConfig +from ...core.config.serialized_config import ContinueConfig from ...core.main import Policy, SessionState, Step from ...core.observation import TextObservation from ...core.steps import ShellCommandsStep diff --git a/server/continuedev/server/main.py b/server/continuedev/server/main.py index ab003bb26..60de242bb 100644 --- a/server/continuedev/server/main.py +++ b/server/continuedev/server/main.py @@ -7,7 +7,7 @@ from typing import List, Optional from pydantic import BaseModel from ..core.main import ContextProviderDescription, SlashCommandDescription -from ..core.config import ContinueConfig +from ..core.config.serialized_config import ContinueConfig from ..libs.util.devdata import dev_data_logger import uvicorn diff --git a/server/continuedev/server/protocols/gui.py b/server/continuedev/server/protocols/gui.py index 6ca543bcd..e4b50f2e3 100644 --- a/server/continuedev/server/protocols/gui.py +++ b/server/continuedev/server/protocols/gui.py @@ -1,6 +1,6 @@ from typing import Any, Callable, Dict, List, Optional, TypeVar -from ...core.config import ContinueConfig +from ...core.config.serialized_config import ContinueConfig from ...core.autopilot import Autopilot import socketio import uuid @@ -15,7 +15,7 @@ from ...libs.llm.prompts.chat import ( llama2_template_messages, sqlcoder_template_messages, template_alpaca_messages, - phind_template_messages + phind_template_messages, ) from ...libs.llm.prompts.edit import codellama_edit_prompt, alpaca_edit_prompt from ...libs.util.create_async_task import create_async_task diff --git a/server/continuedev/server/window_manager.py b/server/continuedev/server/window_manager.py index 972625e85..be7554990 100644 --- a/server/continuedev/server/window_manager.py +++ b/server/continuedev/server/window_manager.py @@ -16,7 +16,7 @@ from ..plugins.context_providers.file import FileContextProvider from ..core.main import SessionState from ..core.autopilot import Autopilot from ..libs.util.paths import getConfigFilePath, getDiffsFolderPath -from ..core.config import ContinueConfig +from ..core.config.serialized_config import ContinueConfig from .protocols.ide import IdeProtocolServer, WindowInfo from .protocols.gui import GUIProtocolServer from ..libs.util.logging import logger diff --git a/server/tests/step_test.py b/server/tests/step_test.py index a9132dd3b..62a53b5fc 100644 --- a/server/tests/step_test.py +++ b/server/tests/step_test.py @@ -1,5 +1,5 @@ import pytest -from continuedev.core.config import ContinueConfig +from continuedev.core.config.serialized_config import ContinueConfig from continuedev.core.steps import UserInputStep from continuedev.headless import start_headless_session from continuedev.models.filesystem import Range, RangeInFileWithContents diff --git a/server/tests/util/config.py b/server/tests/util/config.py index 370933a00..7a62b5d22 100644 --- a/server/tests/util/config.py +++ b/server/tests/util/config.py @@ -1,4 +1,4 @@ -from continuedev.core.config import ContinueConfig +from continuedev.core.config.serialized_config import ContinueConfig from continuedev.core.models import Models from continuedev.libs.llm.openai_free_trial import OpenAIFreeTrial From 2acf5c2a3f43201c5258e8fc06d04da4ec5961b4 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 13 Nov 2023 21:07:25 -0800 Subject: [PATCH 02/15] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20update=20LLM=20subcl?= =?UTF-8?q?asses=20arguments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/continuedev/libs/llm/base.py | 99 +++++++------------ server/continuedev/libs/llm/ggml.py | 41 +------- .../continuedev/libs/llm/hf_inference_api.py | 14 +-- server/continuedev/libs/llm/hf_tgi.py | 12 +-- server/continuedev/libs/llm/llamacpp.py | 11 +-- server/continuedev/libs/llm/ollama.py | 24 ++--- server/continuedev/libs/llm/openai.py | 35 +++---- .../continuedev/libs/llm/openai_free_trial.py | 10 +- server/continuedev/libs/llm/proxy_server.py | 7 +- server/continuedev/libs/llm/replicate.py | 4 - server/continuedev/libs/llm/text_gen_webui.py | 15 +-- server/continuedev/libs/llm/together.py | 16 +-- server/tests/llm_test.py | 2 +- 13 files changed, 88 insertions(+), 202 deletions(-) diff --git a/server/continuedev/libs/llm/base.py b/server/continuedev/libs/llm/base.py index 97b8e3a90..ab33c62c4 100644 --- a/server/continuedev/libs/llm/base.py +++ b/server/continuedev/libs/llm/base.py @@ -122,6 +122,7 @@ class LLM(ContinueBaseModel): api_key: Optional[str] = Field( None, description="The API key for the LLM provider." ) + api_base: Optional[str] = Field(None, description="The base URL of the LLM API.") class Config: arbitrary_types_allowed = True @@ -136,48 +137,16 @@ class LLM(ContinueBaseModel): "context_length": { "description": "The maximum context length of the LLM in tokens, as counted by count_tokens." }, - "max_tokens": {"description": "The maximum number of tokens to generate."}, "unique_id": {"description": "The unique ID of the user."}, "model": { "description": "The name of the model to be used (e.g. gpt-4, codellama)" }, - "timeout": { - "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts." - }, "prompt_templates": { "description": 'A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation OR an instance of the PromptTemplate class if you want to control other parameters. See the documentation for more information.' }, "template_messages": { "description": "A function that takes a list of messages and returns a prompt. This ensures that models like llama2, which are trained on specific chat formats, will always receive input in that format." }, - "write_log": { - "description": "A function that is called upon every prompt and completion, by default to log to the file which can be viewed by clicking on the magnifying glass." - }, - "api_key": {"description": "The API key for the LLM provider."}, - "verify_ssl": { - "description": "Whether to verify SSL certificates for requests." - }, - "ca_bundle_path": { - "description": "Path to a custom CA bundle to use when making the HTTP request" - }, - "headers": {"description": "Headers to use when making the HTTP request"}, - "proxy": {"description": "Proxy URL to use when making the HTTP request"}, - "stop_tokens": {"description": "Tokens that will stop the completion."}, - "temperature": { - "description": "The sampling temperature used for generation." - }, - "top_p": { - "description": "The top_p sampling parameter used for generation." - }, - "top_k": { - "description": "The top_k sampling parameter used for generation." - }, - "presence_penalty": { - "description": "The presence penalty used for completions." - }, - "frequency_penalty": { - "description": "The frequency penalty used for completions." - }, } def dict(self, **kwargs): @@ -205,23 +174,25 @@ class LLM(ContinueBaseModel): self._config_temperature = temperature def create_client_session(self): - if self.verify_ssl is False: + if self.request_options.verify_ssl is False: return aiohttp.ClientSession( connector=aiohttp.TCPConnector(verify_ssl=False), - timeout=aiohttp.ClientTimeout(total=self.timeout), - headers=self.headers, + timeout=aiohttp.ClientTimeout(total=self.request_options.timeout), + headers=self.request_options.headers, trust_env=True, ) else: ca_bundle_path = ( - certifi.where() if self.ca_bundle_path is None else self.ca_bundle_path + certifi.where() + if self.request_options.ca_bundle_path is None + else self.request_options.ca_bundle_path ) if os.path.exists(ca_bundle_path): ssl_context = ssl.create_default_context(cafile=ca_bundle_path) return aiohttp.ClientSession( connector=aiohttp.TCPConnector(ssl_context=ssl_context), - timeout=aiohttp.ClientTimeout(total=self.timeout), - headers=self.headers, + timeout=aiohttp.ClientTimeout(total=self.request_options.timeout), + headers=self.request_options.headers, trust_env=True, ) else: @@ -230,8 +201,8 @@ class LLM(ContinueBaseModel): ca_bundle_path, ) return aiohttp.ClientSession( - timeout=aiohttp.ClientTimeout(total=self.timeout), - headers=self.headers, + timeout=aiohttp.ClientTimeout(total=self.request_options.timeout), + headers=self.request_options.headers, trust_env=True, ) @@ -328,13 +299,15 @@ Settings: """Yield completion response, either streamed or not.""" options = CompletionOptions( model=model or self.model, - temperature=temperature or self.temperature, - top_p=top_p or self.top_p, - top_k=top_k or self.top_k, - presence_penalty=presence_penalty or self.presence_penalty, - frequency_penalty=frequency_penalty or self.frequency_penalty, - stop=stop or self.stop_tokens, - max_tokens=max_tokens or self.max_tokens, + temperature=temperature or self.completion_options.temperature, + top_p=top_p or self.completion_options.top_p, + top_k=top_k or self.completion_options.top_k, + presence_penalty=presence_penalty + or self.completion_options.presence_penalty, + frequency_penalty=frequency_penalty + or self.completion_options.frequency_penalty, + stop=stop or self.completion_options.stop, + max_tokens=max_tokens or self.completion_options.max_tokens, functions=functions, ) @@ -376,13 +349,15 @@ Settings: """Yield completion response, either streamed or not.""" options = CompletionOptions( model=model or self.model, - temperature=temperature or self.temperature, - top_p=top_p or self.top_p, - top_k=top_k or self.top_k, - presence_penalty=presence_penalty or self.presence_penalty, - frequency_penalty=frequency_penalty or self.frequency_penalty, - stop=stop or self.stop_tokens, - max_tokens=max_tokens or self.max_tokens, + temperature=temperature or self.completion_options.temperature, + top_p=top_p or self.completion_options.top_p, + top_k=top_k or self.completion_options.top_k, + presence_penalty=presence_penalty + or self.completion_options.presence_penalty, + frequency_penalty=frequency_penalty + or self.completion_options.frequency_penalty, + stop=stop or self.completion_options.stop, + max_tokens=max_tokens or self.completion_options.max_tokens, functions=functions, ) @@ -422,13 +397,15 @@ Settings: """Yield completion response, either streamed or not.""" options = CompletionOptions( model=model or self.model, - temperature=temperature or self.temperature, - top_p=top_p or self.top_p, - top_k=top_k or self.top_k, - presence_penalty=presence_penalty or self.presence_penalty, - frequency_penalty=frequency_penalty or self.frequency_penalty, - stop=stop or self.stop_tokens, - max_tokens=max_tokens or self.max_tokens, + temperature=temperature or self.completion_options.temperature, + top_p=top_p or self.completion_options.top_p, + top_k=top_k or self.completion_options.top_k, + presence_penalty=presence_penalty + or self.completion_options.presence_penalty, + frequency_penalty=frequency_penalty + or self.completion_options.frequency_penalty, + stop=stop or self.completion_options.stop, + max_tokens=max_tokens or self.completion_options.max_tokens, functions=functions, ) diff --git a/server/continuedev/libs/llm/ggml.py b/server/continuedev/libs/llm/ggml.py index 2c4d3246a..025096250 100644 --- a/server/continuedev/libs/llm/ggml.py +++ b/server/continuedev/libs/llm/ggml.py @@ -31,7 +31,7 @@ class GGML(LLM): ``` """ - server_url: str = Field( + api_base: str = Field( "http://localhost:8000", description="URL of the OpenAI-compatible server where the model is being served", ) @@ -39,8 +39,6 @@ class GGML(LLM): "ggml", description="The name of the model to use (optional for the GGML class)" ) - api_base: Optional[str] = Field(None, description="OpenAI API base URL.") - api_type: Optional[Literal["azure", "openai"]] = Field( None, description="OpenAI API type." ) @@ -53,28 +51,6 @@ class GGML(LLM): None, description="OpenAI engine. For use with Azure OpenAI Service." ) - api_base: Optional[str] = Field(None, description="OpenAI API base URL.") - - api_type: Optional[Literal["azure", "openai"]] = Field( - None, description="OpenAI API type." - ) - - api_version: Optional[str] = Field( - None, description="OpenAI API version. For use with Azure OpenAI Service." - ) - - engine: Optional[str] = Field( - None, description="OpenAI engine. For use with Azure OpenAI Service." - ) - - template_messages: Optional[ - Callable[[List[Dict[str, str]]], str] - ] = llama2_template_messages - - prompt_templates = { - "edit": codellama_edit_prompt, - } - class Config: arbitrary_types_allowed = True @@ -101,20 +77,7 @@ class GGML(LLM): return f"{self.api_base}/openai/deployments/{self.engine}/{endpoint}?api-version={self.api_version}" else: - return f"{self.server_url}/v1/{endpoint}" - - def get_full_server_url(self, endpoint: str): - endpoint = endpoint.lstrip("/").rstrip("/") - - if self.api_type == "azure": - if self.engine is None or self.api_version is None or self.api_base is None: - raise Exception( - "For Azure OpenAI Service, you must specify engine, api_version, and api_base." - ) - - return f"{self.api_base}/openai/deployments/{self.engine}/{endpoint}?api-version={self.api_version}" - else: - return f"{self.server_url}/v1/{endpoint}" + return f"{self.api_base}/v1/{endpoint}" async def _raw_stream_complete(self, prompt, options): args = self.collect_args(options) diff --git a/server/continuedev/libs/llm/hf_inference_api.py b/server/continuedev/libs/llm/hf_inference_api.py index 0e161d762..09b6a5068 100644 --- a/server/continuedev/libs/llm/hf_inference_api.py +++ b/server/continuedev/libs/llm/hf_inference_api.py @@ -31,19 +31,11 @@ class HuggingFaceInferenceAPI(LLM): "Hugging Face Inference API", description="The name of the model to use (optional for the HuggingFaceInferenceAPI class)", ) - hf_token: str = Field(..., description="Your Hugging Face API token") - endpoint_url: str = Field( + api_key: str = Field(..., description="Your Hugging Face API token") + api_base: str = Field( None, description="Your Hugging Face Inference API endpoint URL" ) - template_messages: Union[ - Callable[[List[Dict[str, str]]], str], None - ] = llama2_template_messages - - prompt_templates = { - "edit": codellama_edit_prompt, - } - class Config: arbitrary_types_allowed = True @@ -63,7 +55,7 @@ class HuggingFaceInferenceAPI(LLM): async def _stream_complete(self, prompt, options): args = self.collect_args(options) - client = InferenceClient(self.endpoint_url, token=self.hf_token) + client = InferenceClient(self.api_base, token=self.api_key) stream = client.text_generation(prompt, stream=True, details=True, **args) diff --git a/server/continuedev/libs/llm/hf_tgi.py b/server/continuedev/libs/llm/hf_tgi.py index b4b8b1c0e..27fd86237 100644 --- a/server/continuedev/libs/llm/hf_tgi.py +++ b/server/continuedev/libs/llm/hf_tgi.py @@ -12,15 +12,7 @@ from .prompts.edit import codellama_edit_prompt class HuggingFaceTGI(LLM): model: str = "huggingface-tgi" - server_url: str = Field( - "http://localhost:8080", description="URL of your TGI server" - ) - - template_messages: Callable[[List[ChatMessage]], str] = llama2_template_messages - - prompt_templates = { - "edit": codellama_edit_prompt, - } + api_base: str = Field("http://localhost:8080", description="URL of your TGI server") class Config: arbitrary_types_allowed = True @@ -42,7 +34,7 @@ class HuggingFaceTGI(LLM): async with self.create_client_session() as client_session: async with client_session.post( - f"{self.server_url}/generate_stream", + f"{self.api_base}/generate_stream", json={"inputs": prompt, "parameters": args}, headers={"Content-Type": "application/json"}, proxy=self.proxy, diff --git a/server/continuedev/libs/llm/llamacpp.py b/server/continuedev/libs/llm/llamacpp.py index 152e43db1..5fc7405b1 100644 --- a/server/continuedev/libs/llm/llamacpp.py +++ b/server/continuedev/libs/llm/llamacpp.py @@ -33,18 +33,13 @@ class LlamaCpp(LLM): """ model: str = "llamacpp" - server_url: str = Field("http://localhost:8080", description="URL of the server") + api_base: str = Field("http://localhost:8080", description="URL of the server") llama_cpp_args: Dict[str, Any] = Field( {"stop": ["[INST]"]}, description="A list of additional arguments to pass to llama.cpp. See [here](https://github.com/ggerganov/llama.cpp/tree/master/examples/server#api-endpoints) for the complete catalog of options.", ) - template_messages: Callable = llama2_template_messages - prompt_templates = { - "edit": codellama_edit_prompt, - } - class Config: arbitrary_types_allowed = True @@ -71,10 +66,10 @@ class LlamaCpp(LLM): async def server_generator(): async with self.create_client_session() as client_session: async with client_session.post( - f"{self.server_url}/completion", + f"{self.api_base}/completion", json={"prompt": prompt, "stream": True, **args}, headers=headers, - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: async for line in resp.content: content = line.decode("utf-8") diff --git a/server/continuedev/libs/llm/ollama.py b/server/continuedev/libs/llm/ollama.py index ff1527fd7..a7d4d1038 100644 --- a/server/continuedev/libs/llm/ollama.py +++ b/server/continuedev/libs/llm/ollama.py @@ -1,14 +1,10 @@ import json from typing import Any, Callable, Dict - -import aiohttp from pydantic import Field from ...core.main import ContinueCustomException from ..util.logging import logger from .base import LLM, CompletionOptions -from .prompts.chat import llama2_template_messages -from .prompts.edit import codellama_edit_prompt class Ollama(LLM): @@ -28,16 +24,10 @@ class Ollama(LLM): """ model: str = "llama2" - server_url: str = Field( + api_base: str = Field( "http://localhost:11434", description="URL of the Ollama server" ) - template_messages: Callable = llama2_template_messages - - prompt_templates = { - "edit": codellama_edit_prompt, - } - class Config: arbitrary_types_allowed = True @@ -55,8 +45,8 @@ class Ollama(LLM): try: async with self.create_client_session() as session: async with session.post( - f"{self.server_url}/api/generate", - proxy=self.proxy, + f"{self.api_base}/api/generate", + proxy=self.request_options.proxy, json={ "prompt": "", "model": self.model, @@ -69,8 +59,8 @@ class Ollama(LLM): async def get_downloaded_models(self): async with self.create_client_session() as session: async with session.get( - f"{self.server_url}/api/tags", - proxy=self.proxy, + f"{self.api_base}/api/tags", + proxy=self.request_options.proxy, ) as resp: js_data = await resp.json() return list(map(lambda x: x["name"], js_data["models"])) @@ -78,14 +68,14 @@ class Ollama(LLM): async def _stream_complete(self, prompt, options): async with self.create_client_session() as session: async with session.post( - f"{self.server_url}/api/generate", + f"{self.api_base}/api/generate", json={ "template": prompt, "model": self.model, "system": self.system_message, "options": self.collect_args(options), }, - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: if resp.status == 400: txt = await resp.text() diff --git a/server/continuedev/libs/llm/openai.py b/server/continuedev/libs/llm/openai.py index 969a2f897..1fcf13af9 100644 --- a/server/continuedev/libs/llm/openai.py +++ b/server/continuedev/libs/llm/openai.py @@ -18,7 +18,7 @@ CHAT_MODELS = { "gpt-4", "gpt-3.5-turbo-0613", "gpt-4-32k", - "gpt-4-1106-preview" + "gpt-4-1106-preview", } NON_CHAT_MODELS = { "gpt-3.5-turbo-instruct", @@ -71,8 +71,6 @@ class OpenAI(LLM): description="OpenAI API key", ) - proxy: Optional[str] = Field(None, description="Proxy URL to use for requests.") - api_base: Optional[str] = Field(None, description="OpenAI API base URL.") api_type: Optional[Literal["azure", "openai"]] = Field( @@ -83,15 +81,15 @@ class OpenAI(LLM): None, description="OpenAI API version. For use with Azure OpenAI Service." ) + engine: Optional[str] = Field( + None, description="OpenAI engine. For use with Azure OpenAI Service." + ) + use_legacy_completions_endpoint: bool = Field( False, description="Manually specify to use the legacy completions endpoint instead of chat completions.", ) - engine: Optional[str] = Field( - None, description="OpenAI engine. For use with Azure OpenAI Service." - ) - @validator("context_length") def context_length_for_model(cls, v, values): return CONTEXT_LENGTH_FOR_MODEL.get(values["model"], 4096) @@ -110,13 +108,16 @@ class OpenAI(LLM): if self.api_version is not None: openai.api_version = self.api_version - if self.verify_ssl is not None and self.verify_ssl is False: + if ( + self.request_options.verify_ssl is not None + and self.request_options.verify_ssl is False + ): openai.verify_ssl_certs = False - if self.proxy is not None: - openai.proxy = self.proxy + if self.request_options.proxy is not None: + openai.proxy = self.request_options.proxy - openai.ca_bundle_path = self.ca_bundle_path or certifi.where() + openai.ca_bundle_path = self.request_options.ca_bundle_path or certifi.where() session = self.create_client_session() openai.aiosession.set(session) @@ -142,13 +143,13 @@ class OpenAI(LLM): async for chunk in await openai.ChatCompletion.acreate( messages=[{"role": "user", "content": prompt}], **args, - headers=self.headers, + headers=self.request_options.headers, ): if len(chunk.choices) > 0 and "content" in chunk.choices[0].delta: yield chunk.choices[0].delta.content else: async for chunk in await openai.Completion.acreate( - prompt=prompt, **args, headers=self.headers + prompt=prompt, **args, headers=self.request_options.headers ): if len(chunk.choices) > 0: yield chunk.choices[0].text @@ -164,7 +165,7 @@ class OpenAI(LLM): messages=messages, stream=True, **args, - headers=self.headers, + headers=self.request_options.headers, ): if not hasattr(chunk, "choices") or len(chunk.choices) == 0: continue @@ -183,7 +184,7 @@ class OpenAI(LLM): prompt=template_alpaca_messages(messages), stream=True, **args, - headers=self.headers, + headers=self.request_options.headers, ): if len(chunk.choices) > 0: yield { @@ -204,7 +205,7 @@ class OpenAI(LLM): resp = await openai.ChatCompletion.acreate( messages=[{"role": "user", "content": prompt}], **args, - headers=self.headers, + headers=self.request_options.headers, ) return resp.choices[0].message.content except RateLimitError as e: @@ -217,7 +218,7 @@ class OpenAI(LLM): return ( ( await openai.Completion.acreate( - prompt=prompt, **args, headers=self.headers + prompt=prompt, **args, headers=self.request_options.headers ) ) .choices[0] diff --git a/server/continuedev/libs/llm/openai_free_trial.py b/server/continuedev/libs/llm/openai_free_trial.py index fc464904b..09f45e997 100644 --- a/server/continuedev/libs/llm/openai_free_trial.py +++ b/server/continuedev/libs/llm/openai_free_trial.py @@ -35,8 +35,6 @@ class OpenAIFreeTrial(LLM): These classes support any models available through the OpenAI API, assuming your API key has access, including "gpt-4", "gpt-3.5-turbo", "gpt-3.5-turbo-16k", and "gpt-4-32k". """ - api_key: Optional[str] = None - llm: Optional[LLM] = None @validator("context_length", pre=True, always=True) @@ -52,15 +50,15 @@ class OpenAIFreeTrial(LLM): if self.api_key is None or self.api_key.strip() == "": self.llm = ProxyServer( model=self.model, - verify_ssl=self.verify_ssl, - ca_bundle_path=self.ca_bundle_path, + verify_ssl=self.request_options.verify_ssl, + ca_bundle_path=self.request_options.ca_bundle_path, ) else: self.llm = OpenAI( api_key=self.api_key, model=self.model, - verify_ssl=self.verify_ssl, - ca_bundle_path=self.ca_bundle_path, + verify_ssl=self.request_options.verify_ssl, + ca_bundle_path=self.request_options.ca_bundle_path, ) await self.llm.start(unique_id=unique_id) diff --git a/server/continuedev/libs/llm/proxy_server.py b/server/continuedev/libs/llm/proxy_server.py index e8da5d104..98330e67b 100644 --- a/server/continuedev/libs/llm/proxy_server.py +++ b/server/continuedev/libs/llm/proxy_server.py @@ -3,7 +3,6 @@ import json import traceback from typing import List -import aiohttp from pydantic import validator from ..util.count_tokens import CONTEXT_LENGTH_FOR_MODEL @@ -41,7 +40,7 @@ class ProxyServer(LLM): f"{SERVER_URL}/complete", json={"messages": [{"role": "user", "content": prompt}], **args}, headers=self.get_headers(), - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: resp_text = await resp.text() if resp.status != 200: @@ -56,7 +55,7 @@ class ProxyServer(LLM): f"{SERVER_URL}/stream_chat", json={"messages": messages, **args}, headers=self.get_headers(), - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: if resp.status != 200: raise Exception(await resp.text()) @@ -100,7 +99,7 @@ class ProxyServer(LLM): f"{SERVER_URL}/stream_complete", json={"messages": [{"role": "user", "content": prompt}], **args}, headers=self.get_headers(), - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: if resp.status != 200: raise Exception(await resp.text()) diff --git a/server/continuedev/libs/llm/replicate.py b/server/continuedev/libs/llm/replicate.py index 4ac6ca82f..05c464197 100644 --- a/server/continuedev/libs/llm/replicate.py +++ b/server/continuedev/libs/llm/replicate.py @@ -36,10 +36,6 @@ class ReplicateLLM(LLM): _client: replicate.Client = None - prompt_templates = { - "edit": codellama_edit_prompt, - } - async def start(self, *args, **kwargs): await super().start(*args, **kwargs) self._client = replicate.Client(api_token=self.api_key) diff --git a/server/continuedev/libs/llm/text_gen_webui.py b/server/continuedev/libs/llm/text_gen_webui.py index 1d52c08be..6c1acf521 100644 --- a/server/continuedev/libs/llm/text_gen_webui.py +++ b/server/continuedev/libs/llm/text_gen_webui.py @@ -1,13 +1,10 @@ import json -from typing import Any, Callable, Dict, List, Union - +from typing import Any, List import websockets from pydantic import Field from ...core.main import ChatMessage from .base import LLM -from .prompts.chat import llama2_template_messages -from .prompts.edit import simplest_edit_prompt class TextGenWebUI(LLM): @@ -29,7 +26,7 @@ class TextGenWebUI(LLM): """ model: str = "text-gen-webui" - server_url: str = Field( + api_base: str = Field( "http://localhost:5000", description="URL of your TextGenWebUI server" ) streaming_url: str = Field( @@ -37,14 +34,6 @@ class TextGenWebUI(LLM): description="URL of your TextGenWebUI streaming server (separate from main server URL)", ) - prompt_templates = { - "edit": simplest_edit_prompt, - } - - template_messages: Union[ - Callable[[List[Dict[str, str]]], str], None - ] = llama2_template_messages - class Config: arbitrary_types_allowed = True diff --git a/server/continuedev/libs/llm/together.py b/server/continuedev/libs/llm/together.py index 026bdb4a5..1c462cae7 100644 --- a/server/continuedev/libs/llm/together.py +++ b/server/continuedev/libs/llm/together.py @@ -32,30 +32,24 @@ class TogetherLLM(LLM): api_key: str = Field(..., description="Together API key") model: str = "togethercomputer/RedPajama-INCITE-7B-Instruct" - base_url: str = Field( + api_base: str = Field( "https://api.together.xyz", description="The base URL for your Together API instance", ) - template_messages: Callable = llama2_template_messages - - prompt_templates = { - "edit": codellama_edit_prompt, - } - async def _stream_complete(self, prompt, options): args = self.collect_args(options) async with self.create_client_session() as session: async with session.post( - f"{self.base_url}/inference", + f"{self.api_base}/inference", json={ "prompt": prompt, "stream_tokens": True, **args, }, headers={"Authorization": f"Bearer {self.api_key}"}, - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: async for line in resp.content.iter_chunks(): if line[1]: @@ -92,10 +86,10 @@ class TogetherLLM(LLM): async with self.create_client_session() as session: async with session.post( - f"{self.base_url}/inference", + f"{self.api_base}/inference", json={"prompt": prompt, **args}, headers={"Authorization": f"Bearer {self.api_key}"}, - proxy=self.proxy, + proxy=self.request_options.proxy, ) as resp: text = await resp.text() j = json.loads(text) diff --git a/server/tests/llm_test.py b/server/tests/llm_test.py index a016b4647..57825c60b 100644 --- a/server/tests/llm_test.py +++ b/server/tests/llm_test.py @@ -142,7 +142,7 @@ class TestGGML(TestBaseLLM): model="gpt-3.5-turbo", context_length=cls.context_length, system_message=cls.system_message, - server_url="https://api.openai.com", + api_base="https://api.openai.com", api_key=os.environ["OPENAI_API_KEY"], ) start_model(cls.llm) From 31a4e5cb359b50d44ca894d458f610cfbb006be3 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 13 Nov 2023 23:24:17 -0800 Subject: [PATCH 03/15] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20more=20refactoring?= =?UTF-8?q?=20for=20.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extensions/vscode/schema/ContinueConfig.d.ts | 406 ------------------ extensions/vscode/schema/LLM.d.ts | 5 + extensions/vscode/schema/Models.d.ts | 5 + .../schema/SerializedContinueConfig.d.ts | 323 ++++++++++++++ gui/src/components/ComboBox.tsx | 10 - .../AbstractContinueGUIClientProtocol.ts | 2 - gui/src/hooks/ContinueGUIClientProtocol.ts | 4 - gui/src/schema/ContinueConfig.d.ts | 406 ------------------ gui/src/schema/LLM.d.ts | 5 + gui/src/schema/Models.d.ts | 5 + gui/src/schema/SerializedContinueConfig.d.ts | 323 ++++++++++++++ server/continuedev/__init__.py | 2 +- server/continuedev/core/config/config.py | 60 +-- server/continuedev/core/config/context.py | 17 + .../core/config/serialized_config.py | 85 ++-- server/continuedev/core/config/shared.py | 61 +-- server/continuedev/core/context.py | 17 +- server/continuedev/core/models.py | 24 +- server/continuedev/libs/llm/anthropic.py | 19 +- server/continuedev/libs/llm/base.py | 152 +++---- server/continuedev/libs/llm/prompts/edit.py | 2 +- server/continuedev/libs/util/types.py | 4 + .../models/generate_json_schema.py | 8 +- server/continuedev/models/llm.py | 87 ++++ server/continuedev/server/protocols/gui.py | 122 +----- 25 files changed, 974 insertions(+), 1180 deletions(-) delete mode 100644 extensions/vscode/schema/ContinueConfig.d.ts create mode 100644 extensions/vscode/schema/SerializedContinueConfig.d.ts delete mode 100644 gui/src/schema/ContinueConfig.d.ts create mode 100644 gui/src/schema/SerializedContinueConfig.d.ts create mode 100644 server/continuedev/core/config/context.py create mode 100644 server/continuedev/libs/util/types.py create mode 100644 server/continuedev/models/llm.py diff --git a/extensions/vscode/schema/ContinueConfig.d.ts b/extensions/vscode/schema/ContinueConfig.d.ts deleted file mode 100644 index bd52f1440..000000000 --- a/extensions/vscode/schema/ContinueConfig.d.ts +++ /dev/null @@ -1,406 +0,0 @@ -/* eslint-disable */ -/** - * This file was automatically generated by json-schema-to-typescript. - * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, - * and run json-schema-to-typescript to regenerate this file. - */ - -export type ContinueConfig = ContinueConfig1; -export type Name = string; -export type Hide = boolean; -export type Description = string; -export type ClassName = string; -export type SystemMessage = string; -export type Role = "assistant" | "user" | "system" | "function"; -export type Content = string; -export type Name1 = string; -export type Summary = string; -export type Name2 = string; -export type Arguments = string; -export type ChatContext = ChatMessage[]; -export type ManageOwnChatContext = boolean; -/** - * Steps that will be automatically run at the beginning of a new session - */ -export type StepsOnStartup = Step[]; -/** - * Steps that are not allowed to be run, and will be skipped if attempted - */ -export type DisallowedSteps = string[]; -/** - * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. - */ -export type AllowAnonymousTelemetry = boolean; -/** - * Configuration for the models used by Continue. Read more about how to configure models in the documentation. - */ -export type Models = Models1; -/** - * A title that will identify this model in the model selection dropdown - */ -export type Title = string; -/** - * The unique ID of the user. - */ -export type UniqueId = string; -/** - * The name of the model to be used (e.g. gpt-4, codellama) - */ -export type Model = string; -/** - * A system message that will always be followed by the LLM - */ -export type SystemMessage1 = string; -/** - * The maximum context length of the LLM in tokens, as counted by count_tokens. - */ -export type ContextLength = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; -/** - * The temperature of the completion. - */ -export type Temperature = number; -/** - * The top_p of the completion. - */ -export type TopP = number; -/** - * The top_k of the completion. - */ -export type TopK = number; -/** - * The presence penalty Aof the completion. - */ -export type PresencePenalty = number; -/** - * The frequency penalty of the completion. - */ -export type FrequencyPenalty = number; -/** - * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. - */ -export type Timeout = number; -/** - * Whether to verify SSL certificates for requests. - */ -export type VerifySsl = boolean; -/** - * Path to a custom CA bundle to use when making the HTTP request - */ -export type CaBundlePath = string; -/** - * Proxy URL to use when making the HTTP request - */ -export type Proxy = string; -/** - * The API key for the LLM provider. - */ -export type ApiKey = string; -export type Saved = LLM[]; -export type Temperature1 = number; -export type SystemMessage2 = string; -/** - * The temperature parameter for sampling from the LLM. Higher temperatures will result in more random output, while lower temperatures will result in more predictable output. This value ranges from 0 to 1. - */ -export type Temperature2 = number; -export type Name3 = string; -export type Prompt = string; -export type Description1 = string; -/** - * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. - */ -export type CustomCommands = CustomCommand[]; -export type Name4 = string; -export type Description2 = string; -/** - * An array of slash commands that let you map custom Steps to a shortcut. - */ -export type SlashCommands = SlashCommand[]; -/** - * The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R) - */ -export type OnTraceback = Step; -/** - * A system message that will always be followed by the LLM - */ -export type SystemMessage3 = string; -/** - * A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time. - */ -export type PolicyOverride = Policy; -/** - * The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider. - */ -export type Title1 = string; -/** - * The display title of the ContextProvider shown in the dropdown menu - */ -export type DisplayTitle = string; -/** - * A description of the ContextProvider displayed in the dropdown menu - */ -export type Description3 = string; -/** - * Indicates whether the ContextProvider is dynamic - */ -export type Dynamic = boolean; -/** - * Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query. - */ -export type RequiresQuery = boolean; -export type Name5 = string; -export type Description4 = string; -export type ProviderTitle = string; -export type ItemId = string; -export type Content1 = string; -export type Editing = boolean; -export type Editable = boolean; -/** - * List of selected items in the ContextProvider - */ -export type SelectedItems = ContextItem[]; -/** - * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. - */ -export type ContextProviders = ContextProvider[]; -/** - * An optional token to identify the user. - */ -export type UserToken = string; -/** - * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. - */ -export type DataServerUrl = string; -/** - * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. - */ -export type DisableSummaries = boolean; -/** - * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. - */ -export type DisableIndexing = boolean; -/** - * Settings for the retrieval system. Read more about the retrieval system in the documentation. - */ -export type RetrievalSettings = RetrievalSettings1; -/** - * Number of results to initially retrieve from vector database - */ -export type NRetrieve = number; -/** - * Final number of results to use after re-ranking - */ -export type NFinal = number; -/** - * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results - */ -export type UseReranking = boolean; -/** - * Number of results to group together when re-ranking. Each group will be processed in parallel. - */ -export type RerankGroupSize = number; -/** - * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. - */ -export type IgnoreFiles = string[]; -/** - * OpenAI API key - */ -export type OpenaiApiKey = string; -/** - * OpenAI API base URL - */ -export type ApiBase = string; -/** - * OpenAI API type - */ -export type ApiType = string; -/** - * OpenAI API version - */ -export type ApiVersion = string; -/** - * OpenAI organization ID - */ -export type OrganizationId = string; - -/** - * Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\.continue\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session. - */ -export interface ContinueConfig1 { - steps_on_startup?: StepsOnStartup; - disallowed_steps?: DisallowedSteps; - allow_anonymous_telemetry?: AllowAnonymousTelemetry; - models?: Models; - temperature?: Temperature2; - custom_commands?: CustomCommands; - slash_commands?: SlashCommands; - on_traceback?: OnTraceback; - system_message?: SystemMessage3; - policy_override?: PolicyOverride; - context_providers?: ContextProviders; - user_token?: UserToken; - data_server_url?: DataServerUrl; - disable_summaries?: DisableSummaries; - disable_indexing?: DisableIndexing; - retrieval_settings?: RetrievalSettings; - [k: string]: unknown; -} -export interface Step { - name?: Name; - hide?: Hide; - description?: Description; - class_name?: ClassName; - system_message?: SystemMessage; - chat_context?: ChatContext; - manage_own_chat_context?: ManageOwnChatContext; - [k: string]: unknown; -} -export interface ChatMessage { - role: Role; - content?: Content; - name?: Name1; - summary: Summary; - function_call?: FunctionCall; - [k: string]: unknown; -} -export interface FunctionCall { - name: Name2; - arguments: Arguments; - [k: string]: unknown; -} -/** - * Main class that holds the current model configuration - */ -export interface Models1 { - default: LLM; - summarize?: LLM; - edit?: LLM; - chat?: LLM; - saved?: Saved; - temperature?: Temperature1; - system_message?: SystemMessage2; - [k: string]: unknown; -} -export interface LLM { - title?: Title; - unique_id?: UniqueId; - model: Model; - system_message?: SystemMessage1; - context_length?: ContextLength; - stop_tokens?: StopTokens; - temperature?: Temperature; - top_p?: TopP; - top_k?: TopK; - presence_penalty?: PresencePenalty; - frequency_penalty?: FrequencyPenalty; - timeout?: Timeout; - verify_ssl?: VerifySsl; - ca_bundle_path?: CaBundlePath; - proxy?: Proxy; - headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; - [k: string]: unknown; -} -/** - * Headers to use when making the HTTP request - */ -export interface Headers { - [k: string]: string; -} -/** - * A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information. - */ -export interface PromptTemplates { - [k: string]: unknown; -} -export interface CustomCommand { - name: Name3; - prompt: Prompt; - description: Description1; - [k: string]: unknown; -} -export interface SlashCommand { - name: Name4; - description: Description2; - step: Step1; - params?: Params; - [k: string]: unknown; -} -export interface Step1 { - [k: string]: unknown; -} -export interface Params { - [k: string]: unknown; -} -/** - * A rule that determines which step to take next - */ -export interface Policy { - [k: string]: unknown; -} -/** - * The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'. - * When you type '@', the context provider will be asked to populate a list of options. - * These options will be updated on each keystroke. - * When you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object). - */ -export interface ContextProvider { - title: Title1; - ide?: Ide; - display_title: DisplayTitle; - description: Description3; - dynamic: Dynamic; - requires_query?: RequiresQuery; - selected_items?: SelectedItems; - [k: string]: unknown; -} -export interface Ide { - [k: string]: unknown; -} -/** - * A ContextItem is a single item that is stored in the ContextManager. - */ -export interface ContextItem { - description: ContextItemDescription; - content: Content1; - editing?: Editing; - editable?: Editable; - [k: string]: unknown; -} -/** - * A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'. - * - * The id can be used to retrieve the ContextItem from the ContextManager. - */ -export interface ContextItemDescription { - name: Name5; - description: Description4; - id: ContextItemId; - [k: string]: unknown; -} -/** - * A ContextItemId is a unique identifier for a ContextItem. - */ -export interface ContextItemId { - provider_title: ProviderTitle; - item_id: ItemId; - [k: string]: unknown; -} -export interface RetrievalSettings1 { - n_retrieve?: NRetrieve; - n_final?: NFinal; - use_reranking?: UseReranking; - rerank_group_size?: RerankGroupSize; - ignore_files?: IgnoreFiles; - openai_api_key?: OpenaiApiKey; - api_base?: ApiBase; - api_type?: ApiType; - api_version?: ApiVersion; - organization_id?: OrganizationId; - [k: string]: unknown; -} diff --git a/extensions/vscode/schema/LLM.d.ts b/extensions/vscode/schema/LLM.d.ts index f17f969a1..663ceb1d2 100644 --- a/extensions/vscode/schema/LLM.d.ts +++ b/extensions/vscode/schema/LLM.d.ts @@ -26,6 +26,10 @@ export type SystemMessage = string; * The maximum context length of the LLM in tokens, as counted by count_tokens. */ export type ContextLength = number; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; /** * Tokens that will stop the completion. */ @@ -77,6 +81,7 @@ export interface LLM1 { model: Model; system_message?: SystemMessage; context_length?: ContextLength; + max_tokens?: MaxTokens; stop_tokens?: StopTokens; temperature?: Temperature; top_p?: TopP; diff --git a/extensions/vscode/schema/Models.d.ts b/extensions/vscode/schema/Models.d.ts index 7c1c814e6..52547c4a2 100644 --- a/extensions/vscode/schema/Models.d.ts +++ b/extensions/vscode/schema/Models.d.ts @@ -26,6 +26,10 @@ export type SystemMessage = string; * The maximum context length of the LLM in tokens, as counted by count_tokens. */ export type ContextLength = number; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; /** * Tokens that will stop the completion. */ @@ -93,6 +97,7 @@ export interface LLM { model: Model; system_message?: SystemMessage; context_length?: ContextLength; + max_tokens?: MaxTokens; stop_tokens?: StopTokens; temperature?: Temperature; top_p?: TopP; diff --git a/extensions/vscode/schema/SerializedContinueConfig.d.ts b/extensions/vscode/schema/SerializedContinueConfig.d.ts new file mode 100644 index 000000000..bafd2ab0d --- /dev/null +++ b/extensions/vscode/schema/SerializedContinueConfig.d.ts @@ -0,0 +1,323 @@ +/* eslint-disable */ +/** + * This file was automatically generated by json-schema-to-typescript. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run json-schema-to-typescript to regenerate this file. + */ + +export type SerializedContinueConfig = SerializedContinueConfig1; +export type Step = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep"; +/** + * Steps that will be automatically run at the beginning of a new session + */ +export type StepsOnStartup = StepWithParams[]; +/** + * Steps that are not allowed to be run, and will be skipped if attempted + */ +export type DisallowedSteps = string[]; +/** + * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. + */ +export type AllowAnonymousTelemetry = boolean; +/** + * The title you wish to give your model. + */ +export type Title = string; +/** + * The provider of the model. This is used to determine the type of model, and how to interact with it. + */ +export type Provider = + | "openai" + | "openai-free-trial" + | "openai-aiohttp" + | "anthropic" + | "together" + | "ollama" + | "huggingface-tgi" + | "huggingface-inference-api" + | "llama.cpp" + | "replicate" + | "text-gen-webui" + | "google-palm"; +/** + * The name of the model. Used to autodetect prompt template. + */ +export type Model = string; +/** + * OpenAI, Anthropic, Together, or other API key + */ +export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; +/** + * The maximum context length of the LLM in tokens, as counted by count_tokens. + */ +export type ContextLength = number; +/** + * The chat template used to format messages. This is auto-detected for most models, but can be overridden here. + */ +export type Template = "llama2" | "alpaca" | "zephyr" | "phind" | "anthropic" | "chatml"; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions = BaseCompletionOptions; +/** + * The temperature of the completion. + */ +export type Temperature = number; +/** + * The top_p of the completion. + */ +export type TopP = number; +/** + * The top_k of the completion. + */ +export type TopK = number; +/** + * The presence penalty Aof the completion. + */ +export type PresencePenalty = number; +/** + * The frequency penalty of the completion. + */ +export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; +/** + * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. + */ +export type Timeout = number; +/** + * Whether to verify SSL certificates for requests. + */ +export type VerifySsl = boolean; +/** + * Path to a custom CA bundle to use when making the HTTP request + */ +export type CaBundlePath = string; +/** + * Proxy URL to use when making the HTTP request + */ +export type Proxy = string; +export type Models = ModelDescription[]; +/** + * Roles for models. Each entry should be the title of a model in the models array. + */ +export type ModelRoles = ModelRoles1; +/** + * The default model. If other model roles are not set, they will fall back to default. + */ +export type Default = string; +/** + * The model to use for chat. If not set, will fall back to default. + */ +export type Chat = string; +/** + * The model to use for editing. If not set, will fall back to default. + */ +export type Edit = string; +/** + * The model to use for summarization. If not set, will fall back to default. + */ +export type Summarize = string; +/** + * Default options for completion. These will be overriden by any options set for a specific model. + */ +export type CompletionOptions1 = BaseCompletionOptions; +export type Name = string; +export type Description = string; +/** + * An array of slash commands that let you map custom Steps to a shortcut. + */ +export type SlashCommands = SlashCommand[]; +export type Name1 = string; +export type Prompt = string; +export type Description1 = string; +/** + * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. + */ +export type CustomCommands = CustomCommand[]; +/** + * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. + */ +export type ContextProviders = StepWithParams[]; +/** + * An optional token to identify the user. + */ +export type UserToken = string; +/** + * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. + */ +export type DataServerUrl = string; +/** + * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. + */ +export type DisableSummaries = boolean; +/** + * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. + */ +export type DisableIndexing = boolean; +/** + * Settings for the retrieval system. Read more about the retrieval system in the documentation. + */ +export type RetrievalSettings = RetrievalSettings1; +/** + * Number of results to initially retrieve from vector database + */ +export type NRetrieve = number; +/** + * Final number of results to use after re-ranking + */ +export type NFinal = number; +/** + * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results + */ +export type UseReranking = boolean; +/** + * Number of results to group together when re-ranking. Each group will be processed in parallel. + */ +export type RerankGroupSize = number; +/** + * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. + */ +export type IgnoreFiles = string[]; +/** + * OpenAI API key + */ +export type OpenaiApiKey = string; +/** + * OpenAI API base URL + */ +export type ApiBase1 = string; +/** + * OpenAI API type + */ +export type ApiType = string; +/** + * OpenAI API version + */ +export type ApiVersion = string; +/** + * OpenAI organization ID + */ +export type OrganizationId = string; + +export interface SerializedContinueConfig1 { + steps_on_startup?: StepsOnStartup; + disallowed_steps?: DisallowedSteps; + allow_anonymous_telemetry?: AllowAnonymousTelemetry; + models?: Models; + model_roles?: ModelRoles; + completion_options?: CompletionOptions1; + slash_commands?: SlashCommands; + custom_commands?: CustomCommands; + context_providers?: ContextProviders; + user_token?: UserToken; + data_server_url?: DataServerUrl; + disable_summaries?: DisableSummaries; + disable_indexing?: DisableIndexing; + retrieval_settings?: RetrievalSettings; + [k: string]: unknown; +} +export interface StepWithParams { + step: Step; + params: Params; + [k: string]: unknown; +} +export interface Params { + [k: string]: unknown; +} +export interface ModelDescription { + title: Title; + provider: Provider; + model: Model; + api_key?: ApiKey; + api_base?: ApiBase; + context_length?: ContextLength; + template?: Template; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + [k: string]: unknown; +} +export interface BaseCompletionOptions { + temperature?: Temperature; + top_p?: TopP; + top_k?: TopK; + presence_penalty?: PresencePenalty; + frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { + timeout?: Timeout; + verify_ssl?: VerifySsl; + ca_bundle_path?: CaBundlePath; + proxy?: Proxy; + headers?: Headers; + [k: string]: unknown; +} +/** + * Headers to use when making the HTTP request + */ +export interface Headers { + [k: string]: string; +} +export interface ModelRoles1 { + default: Default; + chat?: Chat; + edit?: Edit; + summarize?: Summarize; + [k: string]: unknown; +} +export interface SlashCommand { + name: Name; + description: Description; + step: Step1; + params?: Params1; + [k: string]: unknown; +} +export interface Step1 { + [k: string]: unknown; +} +export interface Params1 { + [k: string]: unknown; +} +export interface CustomCommand { + name: Name1; + prompt: Prompt; + description: Description1; + [k: string]: unknown; +} +export interface RetrievalSettings1 { + n_retrieve?: NRetrieve; + n_final?: NFinal; + use_reranking?: UseReranking; + rerank_group_size?: RerankGroupSize; + ignore_files?: IgnoreFiles; + openai_api_key?: OpenaiApiKey; + api_base?: ApiBase1; + api_type?: ApiType; + api_version?: ApiVersion; + organization_id?: OrganizationId; + [k: string]: unknown; +} diff --git a/gui/src/components/ComboBox.tsx b/gui/src/components/ComboBox.tsx index 3cba113df..fbeab27ca 100644 --- a/gui/src/components/ComboBox.tsx +++ b/gui/src/components/ComboBox.tsx @@ -1091,16 +1091,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => { {selectedContextItems.length} snippets selected )} - {/* {selectedContextItems.length > 0 && ( - { - client?.showContextVirtualFile(props.index); - }} - text="View Current Context" - > - - - )} */} ) : ( selectedContextItems.length > 0 && ( diff --git a/gui/src/hooks/AbstractContinueGUIClientProtocol.ts b/gui/src/hooks/AbstractContinueGUIClientProtocol.ts index afba38839..b0dd12331 100644 --- a/gui/src/hooks/AbstractContinueGUIClientProtocol.ts +++ b/gui/src/hooks/AbstractContinueGUIClientProtocol.ts @@ -27,8 +27,6 @@ abstract class AbstractContinueGUIClientProtocol { abstract toggleAddingHighlightedCode(): void; - abstract showContextVirtualFile(): void; - abstract selectContextItem(id: string, query: string): void; abstract getContextItem(id: string, query: string): Promise; diff --git a/gui/src/hooks/ContinueGUIClientProtocol.ts b/gui/src/hooks/ContinueGUIClientProtocol.ts index 7540df446..22be86c92 100644 --- a/gui/src/hooks/ContinueGUIClientProtocol.ts +++ b/gui/src/hooks/ContinueGUIClientProtocol.ts @@ -181,10 +181,6 @@ class ContinueGUIClientProtocol extends AbstractContinueGUIClientProtocol { this.messenger?.send("toggle_adding_highlighted_code", {}); } - showContextVirtualFile(index?: number): void { - this.messenger?.send("show_context_virtual_file", { index }); - } - selectContextItem(id: string, query: string): void { this.messenger?.send("select_context_item", { id, query }); } diff --git a/gui/src/schema/ContinueConfig.d.ts b/gui/src/schema/ContinueConfig.d.ts deleted file mode 100644 index bd52f1440..000000000 --- a/gui/src/schema/ContinueConfig.d.ts +++ /dev/null @@ -1,406 +0,0 @@ -/* eslint-disable */ -/** - * This file was automatically generated by json-schema-to-typescript. - * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, - * and run json-schema-to-typescript to regenerate this file. - */ - -export type ContinueConfig = ContinueConfig1; -export type Name = string; -export type Hide = boolean; -export type Description = string; -export type ClassName = string; -export type SystemMessage = string; -export type Role = "assistant" | "user" | "system" | "function"; -export type Content = string; -export type Name1 = string; -export type Summary = string; -export type Name2 = string; -export type Arguments = string; -export type ChatContext = ChatMessage[]; -export type ManageOwnChatContext = boolean; -/** - * Steps that will be automatically run at the beginning of a new session - */ -export type StepsOnStartup = Step[]; -/** - * Steps that are not allowed to be run, and will be skipped if attempted - */ -export type DisallowedSteps = string[]; -/** - * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. - */ -export type AllowAnonymousTelemetry = boolean; -/** - * Configuration for the models used by Continue. Read more about how to configure models in the documentation. - */ -export type Models = Models1; -/** - * A title that will identify this model in the model selection dropdown - */ -export type Title = string; -/** - * The unique ID of the user. - */ -export type UniqueId = string; -/** - * The name of the model to be used (e.g. gpt-4, codellama) - */ -export type Model = string; -/** - * A system message that will always be followed by the LLM - */ -export type SystemMessage1 = string; -/** - * The maximum context length of the LLM in tokens, as counted by count_tokens. - */ -export type ContextLength = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; -/** - * The temperature of the completion. - */ -export type Temperature = number; -/** - * The top_p of the completion. - */ -export type TopP = number; -/** - * The top_k of the completion. - */ -export type TopK = number; -/** - * The presence penalty Aof the completion. - */ -export type PresencePenalty = number; -/** - * The frequency penalty of the completion. - */ -export type FrequencyPenalty = number; -/** - * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. - */ -export type Timeout = number; -/** - * Whether to verify SSL certificates for requests. - */ -export type VerifySsl = boolean; -/** - * Path to a custom CA bundle to use when making the HTTP request - */ -export type CaBundlePath = string; -/** - * Proxy URL to use when making the HTTP request - */ -export type Proxy = string; -/** - * The API key for the LLM provider. - */ -export type ApiKey = string; -export type Saved = LLM[]; -export type Temperature1 = number; -export type SystemMessage2 = string; -/** - * The temperature parameter for sampling from the LLM. Higher temperatures will result in more random output, while lower temperatures will result in more predictable output. This value ranges from 0 to 1. - */ -export type Temperature2 = number; -export type Name3 = string; -export type Prompt = string; -export type Description1 = string; -/** - * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. - */ -export type CustomCommands = CustomCommand[]; -export type Name4 = string; -export type Description2 = string; -/** - * An array of slash commands that let you map custom Steps to a shortcut. - */ -export type SlashCommands = SlashCommand[]; -/** - * The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R) - */ -export type OnTraceback = Step; -/** - * A system message that will always be followed by the LLM - */ -export type SystemMessage3 = string; -/** - * A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time. - */ -export type PolicyOverride = Policy; -/** - * The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider. - */ -export type Title1 = string; -/** - * The display title of the ContextProvider shown in the dropdown menu - */ -export type DisplayTitle = string; -/** - * A description of the ContextProvider displayed in the dropdown menu - */ -export type Description3 = string; -/** - * Indicates whether the ContextProvider is dynamic - */ -export type Dynamic = boolean; -/** - * Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query. - */ -export type RequiresQuery = boolean; -export type Name5 = string; -export type Description4 = string; -export type ProviderTitle = string; -export type ItemId = string; -export type Content1 = string; -export type Editing = boolean; -export type Editable = boolean; -/** - * List of selected items in the ContextProvider - */ -export type SelectedItems = ContextItem[]; -/** - * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. - */ -export type ContextProviders = ContextProvider[]; -/** - * An optional token to identify the user. - */ -export type UserToken = string; -/** - * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. - */ -export type DataServerUrl = string; -/** - * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. - */ -export type DisableSummaries = boolean; -/** - * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. - */ -export type DisableIndexing = boolean; -/** - * Settings for the retrieval system. Read more about the retrieval system in the documentation. - */ -export type RetrievalSettings = RetrievalSettings1; -/** - * Number of results to initially retrieve from vector database - */ -export type NRetrieve = number; -/** - * Final number of results to use after re-ranking - */ -export type NFinal = number; -/** - * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results - */ -export type UseReranking = boolean; -/** - * Number of results to group together when re-ranking. Each group will be processed in parallel. - */ -export type RerankGroupSize = number; -/** - * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. - */ -export type IgnoreFiles = string[]; -/** - * OpenAI API key - */ -export type OpenaiApiKey = string; -/** - * OpenAI API base URL - */ -export type ApiBase = string; -/** - * OpenAI API type - */ -export type ApiType = string; -/** - * OpenAI API version - */ -export type ApiVersion = string; -/** - * OpenAI organization ID - */ -export type OrganizationId = string; - -/** - * Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\.continue\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session. - */ -export interface ContinueConfig1 { - steps_on_startup?: StepsOnStartup; - disallowed_steps?: DisallowedSteps; - allow_anonymous_telemetry?: AllowAnonymousTelemetry; - models?: Models; - temperature?: Temperature2; - custom_commands?: CustomCommands; - slash_commands?: SlashCommands; - on_traceback?: OnTraceback; - system_message?: SystemMessage3; - policy_override?: PolicyOverride; - context_providers?: ContextProviders; - user_token?: UserToken; - data_server_url?: DataServerUrl; - disable_summaries?: DisableSummaries; - disable_indexing?: DisableIndexing; - retrieval_settings?: RetrievalSettings; - [k: string]: unknown; -} -export interface Step { - name?: Name; - hide?: Hide; - description?: Description; - class_name?: ClassName; - system_message?: SystemMessage; - chat_context?: ChatContext; - manage_own_chat_context?: ManageOwnChatContext; - [k: string]: unknown; -} -export interface ChatMessage { - role: Role; - content?: Content; - name?: Name1; - summary: Summary; - function_call?: FunctionCall; - [k: string]: unknown; -} -export interface FunctionCall { - name: Name2; - arguments: Arguments; - [k: string]: unknown; -} -/** - * Main class that holds the current model configuration - */ -export interface Models1 { - default: LLM; - summarize?: LLM; - edit?: LLM; - chat?: LLM; - saved?: Saved; - temperature?: Temperature1; - system_message?: SystemMessage2; - [k: string]: unknown; -} -export interface LLM { - title?: Title; - unique_id?: UniqueId; - model: Model; - system_message?: SystemMessage1; - context_length?: ContextLength; - stop_tokens?: StopTokens; - temperature?: Temperature; - top_p?: TopP; - top_k?: TopK; - presence_penalty?: PresencePenalty; - frequency_penalty?: FrequencyPenalty; - timeout?: Timeout; - verify_ssl?: VerifySsl; - ca_bundle_path?: CaBundlePath; - proxy?: Proxy; - headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; - [k: string]: unknown; -} -/** - * Headers to use when making the HTTP request - */ -export interface Headers { - [k: string]: string; -} -/** - * A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information. - */ -export interface PromptTemplates { - [k: string]: unknown; -} -export interface CustomCommand { - name: Name3; - prompt: Prompt; - description: Description1; - [k: string]: unknown; -} -export interface SlashCommand { - name: Name4; - description: Description2; - step: Step1; - params?: Params; - [k: string]: unknown; -} -export interface Step1 { - [k: string]: unknown; -} -export interface Params { - [k: string]: unknown; -} -/** - * A rule that determines which step to take next - */ -export interface Policy { - [k: string]: unknown; -} -/** - * The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'. - * When you type '@', the context provider will be asked to populate a list of options. - * These options will be updated on each keystroke. - * When you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object). - */ -export interface ContextProvider { - title: Title1; - ide?: Ide; - display_title: DisplayTitle; - description: Description3; - dynamic: Dynamic; - requires_query?: RequiresQuery; - selected_items?: SelectedItems; - [k: string]: unknown; -} -export interface Ide { - [k: string]: unknown; -} -/** - * A ContextItem is a single item that is stored in the ContextManager. - */ -export interface ContextItem { - description: ContextItemDescription; - content: Content1; - editing?: Editing; - editable?: Editable; - [k: string]: unknown; -} -/** - * A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'. - * - * The id can be used to retrieve the ContextItem from the ContextManager. - */ -export interface ContextItemDescription { - name: Name5; - description: Description4; - id: ContextItemId; - [k: string]: unknown; -} -/** - * A ContextItemId is a unique identifier for a ContextItem. - */ -export interface ContextItemId { - provider_title: ProviderTitle; - item_id: ItemId; - [k: string]: unknown; -} -export interface RetrievalSettings1 { - n_retrieve?: NRetrieve; - n_final?: NFinal; - use_reranking?: UseReranking; - rerank_group_size?: RerankGroupSize; - ignore_files?: IgnoreFiles; - openai_api_key?: OpenaiApiKey; - api_base?: ApiBase; - api_type?: ApiType; - api_version?: ApiVersion; - organization_id?: OrganizationId; - [k: string]: unknown; -} diff --git a/gui/src/schema/LLM.d.ts b/gui/src/schema/LLM.d.ts index f17f969a1..663ceb1d2 100644 --- a/gui/src/schema/LLM.d.ts +++ b/gui/src/schema/LLM.d.ts @@ -26,6 +26,10 @@ export type SystemMessage = string; * The maximum context length of the LLM in tokens, as counted by count_tokens. */ export type ContextLength = number; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; /** * Tokens that will stop the completion. */ @@ -77,6 +81,7 @@ export interface LLM1 { model: Model; system_message?: SystemMessage; context_length?: ContextLength; + max_tokens?: MaxTokens; stop_tokens?: StopTokens; temperature?: Temperature; top_p?: TopP; diff --git a/gui/src/schema/Models.d.ts b/gui/src/schema/Models.d.ts index 7c1c814e6..52547c4a2 100644 --- a/gui/src/schema/Models.d.ts +++ b/gui/src/schema/Models.d.ts @@ -26,6 +26,10 @@ export type SystemMessage = string; * The maximum context length of the LLM in tokens, as counted by count_tokens. */ export type ContextLength = number; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; /** * Tokens that will stop the completion. */ @@ -93,6 +97,7 @@ export interface LLM { model: Model; system_message?: SystemMessage; context_length?: ContextLength; + max_tokens?: MaxTokens; stop_tokens?: StopTokens; temperature?: Temperature; top_p?: TopP; diff --git a/gui/src/schema/SerializedContinueConfig.d.ts b/gui/src/schema/SerializedContinueConfig.d.ts new file mode 100644 index 000000000..bafd2ab0d --- /dev/null +++ b/gui/src/schema/SerializedContinueConfig.d.ts @@ -0,0 +1,323 @@ +/* eslint-disable */ +/** + * This file was automatically generated by json-schema-to-typescript. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run json-schema-to-typescript to regenerate this file. + */ + +export type SerializedContinueConfig = SerializedContinueConfig1; +export type Step = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep"; +/** + * Steps that will be automatically run at the beginning of a new session + */ +export type StepsOnStartup = StepWithParams[]; +/** + * Steps that are not allowed to be run, and will be skipped if attempted + */ +export type DisallowedSteps = string[]; +/** + * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. + */ +export type AllowAnonymousTelemetry = boolean; +/** + * The title you wish to give your model. + */ +export type Title = string; +/** + * The provider of the model. This is used to determine the type of model, and how to interact with it. + */ +export type Provider = + | "openai" + | "openai-free-trial" + | "openai-aiohttp" + | "anthropic" + | "together" + | "ollama" + | "huggingface-tgi" + | "huggingface-inference-api" + | "llama.cpp" + | "replicate" + | "text-gen-webui" + | "google-palm"; +/** + * The name of the model. Used to autodetect prompt template. + */ +export type Model = string; +/** + * OpenAI, Anthropic, Together, or other API key + */ +export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; +/** + * The maximum context length of the LLM in tokens, as counted by count_tokens. + */ +export type ContextLength = number; +/** + * The chat template used to format messages. This is auto-detected for most models, but can be overridden here. + */ +export type Template = "llama2" | "alpaca" | "zephyr" | "phind" | "anthropic" | "chatml"; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions = BaseCompletionOptions; +/** + * The temperature of the completion. + */ +export type Temperature = number; +/** + * The top_p of the completion. + */ +export type TopP = number; +/** + * The top_k of the completion. + */ +export type TopK = number; +/** + * The presence penalty Aof the completion. + */ +export type PresencePenalty = number; +/** + * The frequency penalty of the completion. + */ +export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; +/** + * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. + */ +export type Timeout = number; +/** + * Whether to verify SSL certificates for requests. + */ +export type VerifySsl = boolean; +/** + * Path to a custom CA bundle to use when making the HTTP request + */ +export type CaBundlePath = string; +/** + * Proxy URL to use when making the HTTP request + */ +export type Proxy = string; +export type Models = ModelDescription[]; +/** + * Roles for models. Each entry should be the title of a model in the models array. + */ +export type ModelRoles = ModelRoles1; +/** + * The default model. If other model roles are not set, they will fall back to default. + */ +export type Default = string; +/** + * The model to use for chat. If not set, will fall back to default. + */ +export type Chat = string; +/** + * The model to use for editing. If not set, will fall back to default. + */ +export type Edit = string; +/** + * The model to use for summarization. If not set, will fall back to default. + */ +export type Summarize = string; +/** + * Default options for completion. These will be overriden by any options set for a specific model. + */ +export type CompletionOptions1 = BaseCompletionOptions; +export type Name = string; +export type Description = string; +/** + * An array of slash commands that let you map custom Steps to a shortcut. + */ +export type SlashCommands = SlashCommand[]; +export type Name1 = string; +export type Prompt = string; +export type Description1 = string; +/** + * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. + */ +export type CustomCommands = CustomCommand[]; +/** + * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. + */ +export type ContextProviders = StepWithParams[]; +/** + * An optional token to identify the user. + */ +export type UserToken = string; +/** + * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. + */ +export type DataServerUrl = string; +/** + * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. + */ +export type DisableSummaries = boolean; +/** + * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. + */ +export type DisableIndexing = boolean; +/** + * Settings for the retrieval system. Read more about the retrieval system in the documentation. + */ +export type RetrievalSettings = RetrievalSettings1; +/** + * Number of results to initially retrieve from vector database + */ +export type NRetrieve = number; +/** + * Final number of results to use after re-ranking + */ +export type NFinal = number; +/** + * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results + */ +export type UseReranking = boolean; +/** + * Number of results to group together when re-ranking. Each group will be processed in parallel. + */ +export type RerankGroupSize = number; +/** + * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. + */ +export type IgnoreFiles = string[]; +/** + * OpenAI API key + */ +export type OpenaiApiKey = string; +/** + * OpenAI API base URL + */ +export type ApiBase1 = string; +/** + * OpenAI API type + */ +export type ApiType = string; +/** + * OpenAI API version + */ +export type ApiVersion = string; +/** + * OpenAI organization ID + */ +export type OrganizationId = string; + +export interface SerializedContinueConfig1 { + steps_on_startup?: StepsOnStartup; + disallowed_steps?: DisallowedSteps; + allow_anonymous_telemetry?: AllowAnonymousTelemetry; + models?: Models; + model_roles?: ModelRoles; + completion_options?: CompletionOptions1; + slash_commands?: SlashCommands; + custom_commands?: CustomCommands; + context_providers?: ContextProviders; + user_token?: UserToken; + data_server_url?: DataServerUrl; + disable_summaries?: DisableSummaries; + disable_indexing?: DisableIndexing; + retrieval_settings?: RetrievalSettings; + [k: string]: unknown; +} +export interface StepWithParams { + step: Step; + params: Params; + [k: string]: unknown; +} +export interface Params { + [k: string]: unknown; +} +export interface ModelDescription { + title: Title; + provider: Provider; + model: Model; + api_key?: ApiKey; + api_base?: ApiBase; + context_length?: ContextLength; + template?: Template; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + [k: string]: unknown; +} +export interface BaseCompletionOptions { + temperature?: Temperature; + top_p?: TopP; + top_k?: TopK; + presence_penalty?: PresencePenalty; + frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { + timeout?: Timeout; + verify_ssl?: VerifySsl; + ca_bundle_path?: CaBundlePath; + proxy?: Proxy; + headers?: Headers; + [k: string]: unknown; +} +/** + * Headers to use when making the HTTP request + */ +export interface Headers { + [k: string]: string; +} +export interface ModelRoles1 { + default: Default; + chat?: Chat; + edit?: Edit; + summarize?: Summarize; + [k: string]: unknown; +} +export interface SlashCommand { + name: Name; + description: Description; + step: Step1; + params?: Params1; + [k: string]: unknown; +} +export interface Step1 { + [k: string]: unknown; +} +export interface Params1 { + [k: string]: unknown; +} +export interface CustomCommand { + name: Name1; + prompt: Prompt; + description: Description1; + [k: string]: unknown; +} +export interface RetrievalSettings1 { + n_retrieve?: NRetrieve; + n_final?: NFinal; + use_reranking?: UseReranking; + rerank_group_size?: RerankGroupSize; + ignore_files?: IgnoreFiles; + openai_api_key?: OpenaiApiKey; + api_base?: ApiBase1; + api_type?: ApiType; + api_version?: ApiVersion; + organization_id?: OrganizationId; + [k: string]: unknown; +} diff --git a/server/continuedev/__init__.py b/server/continuedev/__init__.py index 2fa7e7f47..1941ab2ce 100644 --- a/server/continuedev/__init__.py +++ b/server/continuedev/__init__.py @@ -1,7 +1,7 @@ import asyncio from typing import Union -from .core.config.serialized_config import ContinueConfig +from .core.config.config import ContinueConfig from .core.main import Step # from .headless import start_headless_session diff --git a/server/continuedev/core/config/config.py b/server/continuedev/core/config/config.py index a5def0ac1..9b08972e9 100644 --- a/server/continuedev/core/config/config.py +++ b/server/continuedev/core/config/config.py @@ -1,14 +1,9 @@ from typing import Dict, List, Optional, Type +from pydantic import BaseModel, Field, validator + from ...libs.llm.base import BaseCompletionOptions - -from .serialized_config import ( - CustomCommand, - RetrievalSettings, - SerializedContinueConfig, - SlashCommand, -) - +from ...libs.llm.openai_free_trial import OpenAIFreeTrial from ...libs.util.edit_config import ( create_bool_node, create_obj_node, @@ -16,14 +11,17 @@ from ...libs.util.edit_config import ( edit_config_property, ) from ...libs.util.paths import convertConfigImports, getConfigFilePath - -from pydantic import BaseModel, Field, validator - -from ...libs.llm.openai_free_trial import OpenAIFreeTrial +from ...libs.util.telemetry import posthog_logger from ..context import ContextProvider from ..main import ContextProviderDescription, Policy, SlashCommandDescription, Step from ..models import Models -from ...libs.util.telemetry import posthog_logger +from .context import CONTEXT_PROVIDER_NAME_TO_CLASS +from .serialized_config import ( + CustomCommand, + RetrievalSettings, + SerializedContinueConfig, + SlashCommand, +) class ContinueConfig(BaseModel): @@ -32,30 +30,30 @@ class ContinueConfig(BaseModel): """ steps_on_startup: List[Step] = Field( - [], + default=[], description="Steps that will be automatically run at the beginning of a new session", ) disallowed_steps: Optional[List[str]] = Field( - [], + default=[], description="Steps that are not allowed to be run, and will be skipped if attempted", ) allow_anonymous_telemetry: Optional[bool] = Field( - True, + default=True, description="If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", ) models: Models = Field( - Models( + default=Models( default=OpenAIFreeTrial(model="gpt-4"), summarize=OpenAIFreeTrial(model="gpt-3.5-turbo"), ), description="Configuration for the models used by Continue. Read more about how to configure models in the documentation.", ) completion_options: BaseCompletionOptions = Field( - BaseCompletionOptions(), + default=BaseCompletionOptions(), description="Options for the completion endpoint. Read more about the completion options in the documentation.", ) custom_commands: Optional[List[CustomCommand]] = Field( - [ + default=[ CustomCommand( name="test", description="This is an example custom command. Use /config to edit it and create more", @@ -65,38 +63,38 @@ class ContinueConfig(BaseModel): description="An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", ) slash_commands: Optional[List[SlashCommand]] = Field( - [], + default=[], description="An array of slash commands that let you map custom Steps to a shortcut.", ) on_traceback: Optional[Step] = Field( - None, + default=None, description="The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R)", ) policy_override: Optional[Policy] = Field( - None, + default=None, description="A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time.", ) context_providers: List[ContextProvider] = Field( - [], + default=[], description="A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", ) user_token: Optional[str] = Field( - None, description="An optional token to identify the user." + default=None, description="An optional token to identify the user." ) data_server_url: Optional[str] = Field( - "https://us-west1-autodebug.cloudfunctions.net", + default="https://us-west1-autodebug.cloudfunctions.net", description="The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", ) disable_summaries: Optional[bool] = Field( - False, + default=False, description="If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", ) disable_indexing: Optional[bool] = Field( - False, + default=False, description="If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", ) retrieval_settings: Optional[RetrievalSettings] = Field( - RetrievalSettings(), + default=RetrievalSettings(), description="Settings for the retrieval system. Read more about the retrieval system in the documentation.", ) @@ -106,6 +104,10 @@ class ContinueConfig(BaseModel): @staticmethod def from_serialized_config(config: SerializedContinueConfig) -> "ContinueConfig": + context_providers = [ + CONTEXT_PROVIDER_NAME_TO_CLASS[provider.name](**provider.params) + for provider in config.context_providers + ] return ContinueConfig( disallowed_steps=config.disallowed_steps, allow_anonymous_telemetry=config.allow_anonymous_telemetry, @@ -113,7 +115,7 @@ class ContinueConfig(BaseModel): completion_options=config.completion_options, custom_commands=config.custom_commands, slash_commands=config.slash_commands, - context_providers=config.context_providers, + context_providers=context_providers, user_token=config.user_token, data_server_url=config.data_server_url, disable_summaries=config.disable_summaries, diff --git a/server/continuedev/core/config/context.py b/server/continuedev/core/config/context.py new file mode 100644 index 000000000..9f76f4a50 --- /dev/null +++ b/server/continuedev/core/config/context.py @@ -0,0 +1,17 @@ +from ...plugins.context_providers.diff import DiffContextProvider +from ...plugins.context_providers.github import GitHubIssuesContextProvider +from ...plugins.context_providers.google import GoogleContextProvider +from ...plugins.context_providers.open_tabs import OpenTabsContextProvider +from ...plugins.context_providers.search import SearchContextProvider +from ...plugins.context_providers.terminal import TerminalContextProvider +from ...plugins.context_providers.url import URLContextProvider + +CONTEXT_PROVIDER_NAME_TO_CLASS = { + "diff": DiffContextProvider, + "github": GitHubIssuesContextProvider, + "terminal": TerminalContextProvider, + "open": OpenTabsContextProvider, + "google": GoogleContextProvider, + "search": SearchContextProvider, + "url": URLContextProvider, +} diff --git a/server/continuedev/core/config/serialized_config.py b/server/continuedev/core/config/serialized_config.py index ee31d5e47..e9c817dd9 100644 --- a/server/continuedev/core/config/serialized_config.py +++ b/server/continuedev/core/config/serialized_config.py @@ -1,13 +1,15 @@ -from typing import Any, Dict, List, Literal, Optional, Type -from .shared import ModelProvider, RequestOptions, StepName, TemplateType +from typing import Any, Dict, List, Optional, Type + +from anthropic import RequestOptions from pydantic import BaseModel, Field -from ...libs.llm.base import BaseCompletionOptions +from ...models.llm import BaseCompletionOptions from ..main import SlashCommandDescription, Step +from .shared import ModelProvider, StepName, TemplateType class StepWithParams(BaseModel): - step: StepName + name: StepName params: Dict[str, Any] @@ -46,102 +48,105 @@ class CustomCommand(BaseModel): class RetrievalSettings(BaseModel): n_retrieve: Optional[int] = Field( - 50, description="Number of results to initially retrieve from vector database" + default=50, + description="Number of results to initially retrieve from vector database", ) n_final: Optional[int] = Field( - 10, description="Final number of results to use after re-ranking" + default=10, description="Final number of results to use after re-ranking" ) use_reranking: bool = Field( - True, + default=True, description="Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", ) rerank_group_size: int = Field( - 5, + default=5, description="Number of results to group together when re-ranking. Each group will be processed in parallel.", ) ignore_files: List[str] = Field( - [], + default=[], description="Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", ) - openai_api_key: Optional[str] = Field(None, description="OpenAI API key") - api_base: Optional[str] = Field(None, description="OpenAI API base URL") - api_type: Optional[str] = Field(None, description="OpenAI API type") - api_version: Optional[str] = Field(None, description="OpenAI API version") - organization_id: Optional[str] = Field(None, description="OpenAI organization ID") + openai_api_key: Optional[str] = Field(default=None, description="OpenAI API key") + api_base: Optional[str] = Field(default=None, description="OpenAI API base URL") + api_type: Optional[str] = Field(default=None, description="OpenAI API type") + api_version: Optional[str] = Field(default=None, description="OpenAI API version") + organization_id: Optional[str] = Field( + default=None, description="OpenAI organization ID" + ) class ModelDescription(BaseModel): title: str = Field( - ..., + default=..., description="The title you wish to give your model.", ) provider: ModelProvider = Field( - ..., + default=..., description="The provider of the model. This is used to determine the type of model, and how to interact with it.", ) model: str = Field( - ..., + default=..., description="The name of the model. Used to autodetect prompt template.", ) api_key: Optional[str] = Field( - None, description="OpenAI, Anthropic, Together, or other API key" + default=None, description="OpenAI, Anthropic, Together, or other API key" ) api_base: Optional[str] = Field(None, description="The base URL of the LLM API.") context_length: int = Field( - 2048, + default=2048, description="The maximum context length of the LLM in tokens, as counted by count_tokens.", ) template: Optional[TemplateType] = Field( - None, + default=None, description="The chat template used to format messages. This is auto-detected for most models, but can be overridden here.", ) completion_options: BaseCompletionOptions = Field( - BaseCompletionOptions(), + default=BaseCompletionOptions(), description="Options for the completion endpoint. Read more about the completion options in the documentation.", ) system_message: Optional[str] = Field( - None, + default=None, description="A system message that will always be followed by the LLM", ) request_options: RequestOptions = Field( - RequestOptions(), + default=RequestOptions(), description="Options for the HTTP request to the LLM.", ) class ModelRoles(BaseModel): default: str = Field( - ..., + default=..., description="The default model. If other model roles are not set, they will fall back to default.", ) chat: Optional[str] = Field( - None, + default=None, description="The model to use for chat. If not set, will fall back to default.", ) edit: Optional[str] = Field( - None, + default=None, description="The model to use for editing. If not set, will fall back to default.", ) summarize: Optional[str] = Field( - None, + default=None, description="The model to use for summarization. If not set, will fall back to default.", ) class SerializedContinueConfig(BaseModel): disallowed_steps: Optional[List[str]] = Field( - [], + default=[], description="Steps that are not allowed to be run, and will be skipped if attempted", ) allow_anonymous_telemetry: Optional[bool] = Field( - True, + default=True, description="If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", ) models: List[ModelDescription] = Field( - [ + default=[ { "title": "GPT-4 (trial)", "provider": "openai-free-trial", @@ -151,19 +156,19 @@ class SerializedContinueConfig(BaseModel): ] ) model_roles: ModelRoles = Field( - ModelRoles(default="GPT-4 (trial)"), + default=ModelRoles(default="GPT-4 (trial)"), description="Roles for models. Each entry should be the title of a model in the models array.", ) completion_options: BaseCompletionOptions = Field( - BaseCompletionOptions(), + default=BaseCompletionOptions(), description="Default options for completion. These will be overriden by any options set for a specific model.", ) slash_commands: Optional[List[SlashCommand]] = Field( - [], + default=[], description="An array of slash commands that let you map custom Steps to a shortcut.", ) custom_commands: Optional[List[CustomCommand]] = Field( - [ + default=[ CustomCommand( name="test", description="This is an example custom command. Use /config to edit it and create more", @@ -173,25 +178,25 @@ class SerializedContinueConfig(BaseModel): description="An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", ) context_providers: List[StepWithParams] = Field( - [], + default=[], description="A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", ) user_token: Optional[str] = Field( - None, description="An optional token to identify the user." + default=None, description="An optional token to identify the user." ) data_server_url: Optional[str] = Field( - "https://us-west1-autodebug.cloudfunctions.net", + default="https://us-west1-autodebug.cloudfunctions.net", description="The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", ) disable_summaries: Optional[bool] = Field( - False, + default=False, description="If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", ) disable_indexing: Optional[bool] = Field( - False, + default=False, description="If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", ) retrieval_settings: Optional[RetrievalSettings] = Field( - RetrievalSettings(), + default=RetrievalSettings(), description="Settings for the retrieval system. Read more about the retrieval system in the documentation.", ) diff --git a/server/continuedev/core/config/shared.py b/server/continuedev/core/config/shared.py index 675fa46aa..c5d4888db 100644 --- a/server/continuedev/core/config/shared.py +++ b/server/continuedev/core/config/shared.py @@ -1,21 +1,18 @@ -from typing import Dict, Literal, Optional -from pydantic import BaseModel, Field +from typing import Any, Dict, Literal, Optional from ...libs.llm.prompts.chat import ( - llama2_template_messages, - template_alpaca_messages, - phind_template_messages, - zephyr_template_messages, - chatml_template_messages, anthropic_template_messages, + chatml_template_messages, + llama2_template_messages, + phind_template_messages, + template_alpaca_messages, + zephyr_template_messages, ) - from ...libs.llm.prompts.edit import ( - codellama_edit_prompt, alpaca_edit_prompt, + codellama_edit_prompt, simplest_edit_prompt, -) # TODO: Prompts for the rest of the template types - +) StepName = Literal[ "AnswerQuestionChroma", @@ -54,15 +51,17 @@ def autodetect_template_type(model: str) -> Optional[TemplateType]: def autodetect_template_function(model: str): - template_type = autodetect_template_type(model) - return { - "llama2": llama2_template_messages, - "alpaca": template_alpaca_messages, - "phind": phind_template_messages, - "zephyr": zephyr_template_messages, - "anthropic": anthropic_template_messages, - "chatml": chatml_template_messages, - }[template_type] + if template_type := autodetect_template_type(model): + mapping: Dict[TemplateType, Any] = { + "llama2": llama2_template_messages, + "alpaca": template_alpaca_messages, + "phind": phind_template_messages, + "zephyr": zephyr_template_messages, + "anthropic": anthropic_template_messages, + "chatml": chatml_template_messages, + } + return mapping[template_type] + return None def autodetect_prompt_templates(model: str): @@ -113,25 +112,3 @@ MODEL_PROVIDER_TO_MODEL_CLASS = { "text-gen-webui": "TextGenWebUI", "google-palm": "GooglePaLMAPI", } - - -class RequestOptions(BaseModel): - timeout: Optional[int] = Field( - 300, - description="Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", - ) - verify_ssl: Optional[bool] = Field( - None, description="Whether to verify SSL certificates for requests." - ) - ca_bundle_path: str = Field( - None, - description="Path to a custom CA bundle to use when making the HTTP request", - ) - proxy: Optional[str] = Field( - None, - description="Proxy URL to use when making the HTTP request", - ) - headers: Optional[Dict[str, str]] = Field( - None, - description="Headers to use when making the HTTP request", - ) diff --git a/server/continuedev/core/context.py b/server/continuedev/core/context.py index 9cc7e9cf9..b93b5ac76 100644 --- a/server/continuedev/core/context.py +++ b/server/continuedev/core/context.py @@ -3,25 +3,24 @@ import time from abc import abstractmethod from typing import Any, Awaitable, Callable, List, Optional -from ..libs.util.paths import migration -from ..server.protocols.ide_protocol import AbstractIdeProtocolServer - from meilisearch_python_async import Client from pydantic import BaseModel, Field from ..libs.util.create_async_task import create_async_task from ..libs.util.devdata import dev_data_logger from ..libs.util.logging import logger +from ..libs.util.paths import migration from ..libs.util.telemetry import posthog_logger from ..server.global_config import global_config from ..server.meilisearch_server import ( check_meilisearch_running, get_meilisearch_url, poll_meilisearch_running, + remove_meilisearch_disallowed_chars, restart_meilisearch, start_meilisearch, - remove_meilisearch_disallowed_chars, ) +from ..server.protocols.ide_protocol import AbstractIdeProtocolServer from .main import ( ChatMessage, ContextItem, @@ -139,7 +138,7 @@ class ContextProvider(BaseModel): summary=item.description.description, ) - async def get_item(self, id: ContextItemId, query: str) -> ContextItem: + async def get_item(self, id: ContextItemId, query: str) -> Optional[ContextItem]: """ Returns the ContextItem with the given id. @@ -463,13 +462,13 @@ class ContextManager: """ Opens a virtual file or otherwise previews the contents of the context provider in the IDE. """ - id: ContextItemId = ContextItemId.from_string(id) - if id.provider_title not in self.provider_titles: + item_id: ContextItemId = ContextItemId.from_string(id) + if item_id.provider_title not in self.provider_titles: raise ValueError( - f"Context provider with title {id.provider_title} not found" + f"Context provider with title {item_id.provider_title} not found" ) - await self.context_providers[id.provider_title].preview_contents(id) + await self.context_providers[item_id.provider_title].preview_contents(item_id) """ diff --git a/server/continuedev/core/models.py b/server/continuedev/core/models.py index 7e887ec59..78daf9322 100644 --- a/server/continuedev/core/models.py +++ b/server/continuedev/core/models.py @@ -1,11 +1,15 @@ -from typing import Callable, Dict, List, Optional import uuid -from .config.serialized_config import ModelDescription, SerializedContinueConfig +from typing import Callable, Dict, List, Optional, Type, cast from pydantic import BaseModel, validator +from ..core.config.shared import ( + MODEL_PROVIDER_TO_MODEL_CLASS, + autodetect_prompt_templates, + autodetect_template_function, +) from ..libs.llm.anthropic import AnthropicLLM -from ..libs.llm.base import LLM +from ..libs.llm.base import LLM, BaseCompletionOptions from ..libs.llm.ggml import GGML from ..libs.llm.google_palm_api import GooglePaLMAPI from ..libs.llm.hf_inference_api import HuggingFaceInferenceAPI @@ -15,13 +19,9 @@ from ..libs.llm.ollama import Ollama from ..libs.llm.openai import OpenAI from ..libs.llm.openai_free_trial import OpenAIFreeTrial from ..libs.llm.replicate import ReplicateLLM -from ..libs.llm.together import TogetherLLM from ..libs.llm.text_gen_webui import TextGenWebUI -from ..core.config.shared import ( - MODEL_PROVIDER_TO_MODEL_CLASS, - autodetect_prompt_templates, - autodetect_template_function, -) +from ..libs.llm.together import TogetherLLM +from .config.serialized_config import ModelDescription, SerializedContinueConfig class ContinueSDK(BaseModel): @@ -35,7 +35,7 @@ ALL_MODEL_ROLES = [ "chat", ] -MODEL_CLASSES: Dict[str, LLM] = { +MODEL_CLASSES: Dict[str, Type[LLM]] = { cls.__name__: cls for cls in [ OpenAI, @@ -96,7 +96,7 @@ class Models(BaseModel): @staticmethod def from_serialized_config(config: SerializedContinueConfig) -> "Models": - def model_with_title(title: str, fallback: ModelDescription): + def model_with_title(title: Optional[str], fallback: ModelDescription): return next(filter(lambda x: x.title == title, config.models), fallback) default = model_with_title(config.model_roles.default, config.models[0]) @@ -111,7 +111,7 @@ class Models(BaseModel): model_class.system_message = model.system_message return LLM( api_key=model.api_key, - completion_options=completion_options, + completion_options=cast(BaseCompletionOptions, completion_options), request_options=model.request_options, system_message=model.system_message, api_base=model.api_base, # TODO diff --git a/server/continuedev/libs/llm/anthropic.py b/server/continuedev/libs/llm/anthropic.py index 40b322d3f..280b20d61 100644 --- a/server/continuedev/libs/llm/anthropic.py +++ b/server/continuedev/libs/llm/anthropic.py @@ -1,4 +1,4 @@ -from typing import Any, Callable, Coroutine +from typing import Any, Callable, Coroutine, Optional from anthropic import AI_PROMPT, HUMAN_PROMPT, AsyncAnthropic @@ -25,21 +25,16 @@ class AnthropicLLM(LLM): """ - api_key: str + api_key: Optional[str] "Anthropic API key" model: str = "claude-2" - _async_client: AsyncAnthropic = None - - template_messages: Callable = anthropic_template_messages - class Config: arbitrary_types_allowed = True async def start(self, *args, **kwargs): await super().start(*args, **kwargs) - self._async_client = AsyncAnthropic(api_key=self.api_key) if self.model == "claude-2": self.context_length = 100_000 @@ -61,14 +56,16 @@ class AnthropicLLM(LLM): args = self.collect_args(options) prompt = f"{HUMAN_PROMPT} {prompt} {AI_PROMPT}" - async for chunk in await self._async_client.completions.create( - prompt=prompt, stream=True, **args - ): + async for chunk in await AsyncAnthropic( + api_key=self.api_key + ).completions.create(prompt=prompt, stream=True, **args): yield chunk.completion async def _complete(self, prompt: str, options) -> Coroutine[Any, Any, str]: args = self.collect_args(options) prompt = f"{HUMAN_PROMPT} {prompt} {AI_PROMPT}" return ( - await self._async_client.completions.create(prompt=prompt, **args) + await AsyncAnthropic(api_key=self.api_key).completions.create( + prompt=prompt, **args + ) ).completion diff --git a/server/continuedev/libs/llm/base.py b/server/continuedev/libs/llm/base.py index ab33c62c4..d69822466 100644 --- a/server/continuedev/libs/llm/base.py +++ b/server/continuedev/libs/llm/base.py @@ -1,128 +1,87 @@ import os import ssl from time import time -from typing import Any, Callable, Coroutine, Dict, Generator, List, Optional, Union +from typing import Any, AsyncGenerator, Callable, Coroutine, Dict, List, Optional, Union import aiohttp import certifi -from ...core.config.shared import RequestOptions -from ..util.templating import render_templated_string -from pydantic import Field, validator +from pydantic import Field from ...core.main import ChatMessage +from ...models.llm import ( + BaseCompletionOptions, + CompletionOptions, + RequestOptions, +) from ...models.main import ContinueBaseModel from ..util.count_tokens import ( - DEFAULT_ARGS, - DEFAULT_MAX_TOKENS, CONTEXT_LENGTH_FOR_MODEL, + DEFAULT_ARGS, compile_chat_messages, count_tokens, format_chat_messages, prune_raw_prompt_from_top, ) from ..util.devdata import dev_data_logger -from ..util.telemetry import posthog_logger from ..util.logging import logger - - -class BaseCompletionOptions(ContinueBaseModel): - @validator( - "*", - pre=True, - always=True, - ) - def ignore_none_and_set_default(cls, value, field): - return value if value is not None else field.default - - temperature: Optional[float] = Field( - None, description="The temperature of the completion." - ) - top_p: Optional[float] = Field(None, description="The top_p of the completion.") - top_k: Optional[int] = Field(None, description="The top_k of the completion.") - presence_penalty: Optional[float] = Field( - None, description="The presence penalty Aof the completion." - ) - frequency_penalty: Optional[float] = Field( - None, description="The frequency penalty of the completion." - ) - stop: Optional[List[str]] = Field( - None, description="The stop tokens of the completion." - ) - max_tokens: int = Field( - DEFAULT_MAX_TOKENS, description="The maximum number of tokens to generate." - ) - - -class CompletionOptions(BaseCompletionOptions): - """Options for the completion.""" - - @validator( - "*", - pre=True, - always=True, - ) - def ignore_none_and_set_default(cls, value, field): - return value if value is not None else field.default - - model: Optional[str] = Field(None, description="The model name") - functions: Optional[List[Any]] = Field( - None, description="The functions/tools to make available to the model." - ) - - -class PromptTemplate(CompletionOptions): - prompt: str = Field(description="The prompt to be used for the completion.") - raw: bool = Field(False, description="Whether to use the raw prompt or not.") +from ..util.telemetry import posthog_logger +from ..util.templating import render_templated_string class LLM(ContinueBaseModel): title: Optional[str] = Field( - None, + default=None, description="A title that will identify this model in the model selection dropdown", ) - unique_id: Optional[str] = Field(None, description="The unique ID of the user.") + unique_id: Optional[str] = Field( + default=None, description="The unique ID of the user." + ) model: str = Field( - ..., description="The name of the model to be used (e.g. gpt-4, codellama)" + default=..., + description="The name of the model to be used (e.g. gpt-4, codellama)", ) system_message: Optional[str] = Field( - None, description="A system message that will always be followed by the LLM" + default=None, + description="A system message that will always be followed by the LLM", ) context_length: int = Field( - 2048, + default=2048, description="The maximum context length of the LLM in tokens, as counted by count_tokens.", ) completion_options: BaseCompletionOptions = Field( - BaseCompletionOptions(), + default=BaseCompletionOptions(), description="Options for the completion endpoint. Read more about the completion options in the documentation.", ) request_options: RequestOptions = Field( - RequestOptions(), + default=RequestOptions(), description="Options for the HTTP request to the LLM.", ) prompt_templates: dict = Field( - {}, + default={}, description='A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information.', ) template_messages: Optional[Callable[[List[Dict[str, str]]], str]] = Field( - None, + default=None, description="A function that takes a list of messages and returns a prompt. This ensures that models like llama2, which are trained on specific chat formats, will always receive input in that format.", ) - write_log: Optional[Callable[[str], None]] = Field( - None, + write_log: Optional[Callable[[str], Coroutine]] = Field( + default=None, description="A function that is called upon every prompt and completion, by default to log to the file which can be viewed by clicking on the magnifying glass.", ) api_key: Optional[str] = Field( - None, description="The API key for the LLM provider." + default=None, description="The API key for the LLM provider." + ) + api_base: Optional[str] = Field( + default=None, description="The base URL of the LLM API." ) - api_base: Optional[str] = Field(None, description="The base URL of the LLM API.") class Config: arbitrary_types_allowed = True @@ -264,13 +223,13 @@ Settings: 0, { "role": "system", - "content": render_templated_string(self.get_system_message()), + "content": render_templated_string(self.get_system_message() or ""), }, ) return self.template_messages(msgs) - def log_tokens_generated(self, model: str, completion: int): + def log_tokens_generated(self, model: str, completion: str): tokens = self.count_tokens(completion) dev_data_logger.capture( "tokens_generated", @@ -285,17 +244,17 @@ Settings: self, prompt: str, raw: bool = False, - model: str = None, - temperature: float = None, - top_p: float = None, - top_k: int = None, - presence_penalty: float = None, - frequency_penalty: float = None, + model: Optional[str] = None, + temperature: Optional[float] = None, + top_p: Optional[float] = None, + top_k: Optional[int] = None, + presence_penalty: Optional[float] = None, + frequency_penalty: Optional[float] = None, stop: Optional[List[str]] = None, max_tokens: Optional[int] = None, functions: Optional[List[Any]] = None, log: bool = True, - ) -> Generator[Union[Any, List, Dict], None, None]: + ) -> AsyncGenerator[Union[Any, List, Dict], None]: """Yield completion response, either streamed or not.""" options = CompletionOptions( model=model or self.model, @@ -335,12 +294,12 @@ Settings: self, prompt: str, raw: bool = False, - model: str = None, - temperature: float = None, - top_p: float = None, - top_k: int = None, - presence_penalty: float = None, - frequency_penalty: float = None, + model: Optional[str] = None, + temperature: Optional[float] = None, + top_p: Optional[float] = None, + top_k: Optional[int] = None, + presence_penalty: Optional[float] = None, + frequency_penalty: Optional[float] = None, stop: Optional[List[str]] = None, max_tokens: Optional[int] = None, functions: Optional[List[Any]] = None, @@ -383,17 +342,17 @@ Settings: async def stream_chat( self, messages: List[ChatMessage], - model: str = None, - temperature: float = None, - top_p: float = None, - top_k: int = None, - presence_penalty: float = None, - frequency_penalty: float = None, + model: Optional[str] = None, + temperature: Optional[float] = None, + top_p: Optional[float] = None, + top_k: Optional[int] = None, + presence_penalty: Optional[float] = None, + frequency_penalty: Optional[float] = None, stop: Optional[List[str]] = None, max_tokens: Optional[int] = None, functions: Optional[List[Any]] = None, log: bool = True, - ) -> Generator[Union[Any, List, Dict], None, None]: + ) -> AsyncGenerator[Union[Any, List, Dict], None]: """Yield completion response, either streamed or not.""" options = CompletionOptions( model=model or self.model, @@ -469,22 +428,21 @@ Settings: def _stream_complete( self, prompt, options: CompletionOptions - ) -> Generator[str, None, None]: + ) -> AsyncGenerator[str, None]: """Stream the completion through generator.""" raise NotImplementedError - async def _complete( - self, prompt: str, options: CompletionOptions - ) -> Coroutine[Any, Any, str]: + async def _complete(self, prompt: str, options: CompletionOptions) -> str: """Return the completion of the text with the given temperature.""" completion = "" async for chunk in self._stream_complete(prompt=prompt, options=options): completion += chunk + return completion async def _stream_chat( self, messages: List[ChatMessage], options: CompletionOptions - ) -> Generator[Union[Any, List, Dict], None, None]: + ) -> AsyncGenerator[Dict[str, str], None]: """Stream the chat through generator.""" if self.template_messages is None: raise NotImplementedError( diff --git a/server/continuedev/libs/llm/prompts/edit.py b/server/continuedev/libs/llm/prompts/edit.py index 43816bed0..4c7fb1f3a 100644 --- a/server/continuedev/libs/llm/prompts/edit.py +++ b/server/continuedev/libs/llm/prompts/edit.py @@ -1,6 +1,6 @@ from textwrap import dedent -from ...llm.base import PromptTemplate +from ....models.llm import PromptTemplate simplified_edit_prompt = dedent( """\ diff --git a/server/continuedev/libs/util/types.py b/server/continuedev/libs/util/types.py new file mode 100644 index 000000000..162d7c11f --- /dev/null +++ b/server/continuedev/libs/util/types.py @@ -0,0 +1,4 @@ +from typing import Any, Awaitable, Callable + + +AsyncFunc = Callable[..., Awaitable[Any]] diff --git a/server/continuedev/models/generate_json_schema.py b/server/continuedev/models/generate_json_schema.py index fef9f2a5f..14b28c833 100644 --- a/server/continuedev/models/generate_json_schema.py +++ b/server/continuedev/models/generate_json_schema.py @@ -2,22 +2,23 @@ import os from pydantic import schema_json_of +from ..core.config.config import ContinueConfig from ..core.config.serialized_config import SerializedContinueConfig from ..core.context import ContextItem, ContextItemId from ..core.main import ( + ContextProviderDescription, + ContinueError, SessionInfo, SessionState, SessionUpdate, - ContinueError, SlashCommandDescription, - ContextProviderDescription, ) from ..core.models import Models from ..libs.llm.base import LLM +from ..server.sessions import PersistedSessionInfo from .filesystem import FileEdit, RangeInFile, RangeInFileWithContents from .filesystem_edit import FileEditWithFullContents from .main import Position, Range, Traceback, TracebackFrame -from ..server.sessions import PersistedSessionInfo MODELS_TO_GENERATE = ( [Position, Range, Traceback, TracebackFrame] @@ -32,6 +33,7 @@ MODELS_TO_GENERATE = ( ContextProviderDescription, ] + [SerializedContinueConfig] + + [ContinueConfig] + [ContextItem, ContextItemId] + [Models] + [LLM] diff --git a/server/continuedev/models/llm.py b/server/continuedev/models/llm.py new file mode 100644 index 000000000..66b319764 --- /dev/null +++ b/server/continuedev/models/llm.py @@ -0,0 +1,87 @@ +from typing import Any, Dict, List, Optional + +from pydantic import BaseModel, Field, validator + +from ..libs.util.count_tokens import DEFAULT_MAX_TOKENS +from .main import ContinueBaseModel + + +class RequestOptions(BaseModel): + timeout: Optional[int] = Field( + default=300, + description="Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + ) + verify_ssl: Optional[bool] = Field( + default=None, description="Whether to verify SSL certificates for requests." + ) + ca_bundle_path: str = Field( + default=None, + description="Path to a custom CA bundle to use when making the HTTP request", + ) + proxy: Optional[str] = Field( + default=None, + description="Proxy URL to use when making the HTTP request", + ) + headers: Optional[Dict[str, str]] = Field( + default=None, + description="Headers to use when making the HTTP request", + ) + + +class BaseCompletionOptions(ContinueBaseModel): + @validator( + "*", + pre=True, + always=True, + ) + def ignore_none_and_set_default(cls, value, field): + return value if value is not None else field.default + + temperature: Optional[float] = Field( + default=None, description="The temperature of the completion." + ) + top_p: Optional[float] = Field( + default=None, description="The top_p of the completion." + ) + top_k: Optional[int] = Field( + default=None, description="The top_k of the completion." + ) + presence_penalty: Optional[float] = Field( + default=None, description="The presence penalty Aof the completion." + ) + frequency_penalty: Optional[float] = Field( + default=None, description="The frequency penalty of the completion." + ) + stop: Optional[List[str]] = Field( + default=None, description="The stop tokens of the completion." + ) + max_tokens: int = Field( + default=DEFAULT_MAX_TOKENS, + description="The maximum number of tokens to generate.", + ) + + +class CompletionOptions(BaseCompletionOptions): + """Options for the completion.""" + + @validator( + "*", + pre=True, + always=True, + ) + def ignore_none_and_set_default(cls, value, field): + return value if value is not None else field.default + + model: str = Field(default=None, description="The model name") + functions: Optional[List[Any]] = Field( + default=None, description="The functions/tools to make available to the model." + ) + + +class PromptTemplate(CompletionOptions): + prompt: str = Field( + default=..., description="The prompt to be used for the completion." + ) + raw: bool = Field( + default=False, description="Whether to use the raw prompt or not." + ) diff --git a/server/continuedev/server/protocols/gui.py b/server/continuedev/server/protocols/gui.py index e4b50f2e3..fb9dd7dbd 100644 --- a/server/continuedev/server/protocols/gui.py +++ b/server/continuedev/server/protocols/gui.py @@ -1,24 +1,20 @@ -from typing import Any, Callable, Dict, List, Optional, TypeVar - -from ...core.config.serialized_config import ContinueConfig -from ...core.autopilot import Autopilot -import socketio import uuid +from typing import Any, Awaitable, Callable, Dict, List, Optional, TypeVar +import socketio from pydantic import BaseModel -from ...models.websockets import WebsocketsMessage +from ...core.autopilot import Autopilot +from ...core.config.config import ContinueConfig from ...core.main import ContextItem, SessionState, SessionUpdate, Step, StepDescription from ...core.models import ALL_MODEL_ROLES, MODEL_CLASSES, MODEL_MODULE_NAMES -from ...core.steps import DisplayErrorStep from ...libs.llm.prompts.chat import ( llama2_template_messages, + phind_template_messages, sqlcoder_template_messages, template_alpaca_messages, - phind_template_messages, ) -from ...libs.llm.prompts.edit import codellama_edit_prompt, alpaca_edit_prompt -from ...libs.util.create_async_task import create_async_task +from ...libs.llm.prompts.edit import alpaca_edit_prompt, codellama_edit_prompt from ...libs.util.edit_config import ( add_config_import, create_obj_node, @@ -26,9 +22,10 @@ from ...libs.util.edit_config import ( edit_config_property, ) from ...libs.util.telemetry import posthog_logger +from ...libs.util.types import AsyncFunc +from ...models.websockets import WebsocketsMessage from ..websockets_messenger import SocketIOMessenger - T = TypeVar("T", bound=BaseModel) # You should probably abstract away the websocket stuff into a separate class @@ -39,9 +36,9 @@ class GUIProtocolServer: messenger: SocketIOMessenger get_autopilot: Callable[[SessionState], Autopilot] - get_context_item: Callable[[str, str], ContextItem] + get_context_item: Callable[[str, str], Awaitable[ContextItem]] get_config: Callable[[], ContinueConfig] - reload_config: Callable[[], None] + reload_config: AsyncFunc def __init__( self, @@ -49,9 +46,9 @@ class GUIProtocolServer: sio: socketio.AsyncServer, sid: str, get_autopilot: Callable[[SessionState], Autopilot], - get_context_item: Callable[[str, str], ContextItem], + get_context_item: Callable[[str, str], Awaitable[ContextItem]], get_config: Callable[[], ContinueConfig], - reload_config: Callable[[], None], + reload_config: AsyncFunc, ): self.window_id = window_id self.messenger = SocketIOMessenger(sio, sid) @@ -60,10 +57,6 @@ class GUIProtocolServer: self.get_config = get_config self.reload_config = reload_config - def on_error(self, e: Exception): - # TODO - return self.session.autopilot.sdk.run_step(DisplayErrorStep.from_exception(e)) - async def handle_json(self, msg: WebsocketsMessage): data = msg.data if msg.message_type == "run_from_state": @@ -79,10 +72,6 @@ class GUIProtocolServer: elif msg.message_type == "get_config": return self.get_config().dict() - elif msg.message_type == "show_context_virtual_file": - self.show_context_virtual_file(data.get("index", None)) - elif msg.message_type == "load_session": - self.load_session(data.get("session_id", None)) elif msg.message_type == "set_system_message": sys_message = data["system_message"] ContinueConfig.set_system_message(sys_message) @@ -101,76 +90,9 @@ class GUIProtocolServer: ) elif msg.message_type == "set_model_for_role_from_index": await self.set_model_for_role_from_index(data["role"], data["index"]) - elif msg.message_type == "save_context_group": - self.save_context_group( - data["title"], [ContextItem(**item) for item in data["context_items"]] - ) - elif msg.message_type == "select_context_group": - self.select_context_group(data["id"]) - elif msg.message_type == "delete_context_group": - self.delete_context_group(data["id"]) - elif msg.message_type == "preview_context_item": - self.preview_context_item(data["id"]) elif msg.message_type == "delete_model_at_index": await self.delete_model_at_index(data["index"]) - def show_context_virtual_file(self, index: Optional[int] = None): - async def async_stuff(): - if index is None: - context_items = ( - await self.session.autopilot.context_manager.get_selected_items() - ) - elif index < len(self.session.autopilot.sdk.history.timeline): - context_items = self.session.autopilot.sdk.history.timeline[ - index - ].context_used - - ctx = "\n\n-----------------------------------\n\n".join( - ["These are the context items that will be passed to the LLM"] - + list(map(lambda x: x.content, context_items)) - ) - await self.session.autopilot.ide.showVirtualFile( - "Continue - Selected Context", ctx - ) - - create_async_task( - async_stuff(), - self.on_error, - ) - - def select_context_item(self, id: str, query: str): - """Called when user selects an item from the dropdown""" - create_async_task( - self.session.autopilot.select_context_item(id, query), self.on_error - ) - - def select_context_item_at_index(self, id: str, query: str, index: int): - """Called when user selects an item from the dropdown for prev UserInputStep""" - create_async_task( - self.session.autopilot.select_context_item_at_index(id, query, index), - self.on_error, - ) - - def preview_context_item(self, id: str): - """Called when user clicks on an item from the dropdown""" - create_async_task( - self.session.autopilot.context_manager.preview_context_item(id), - self.on_error, - ) - - # def load_session(self, session_id: Optional[str] = None): - # async def load_and_tell_to_reconnect(): - # new_session_id = await session_manager.load_session( - # self.session.session_id, session_id - # ) - # await self._send_json( - # "reconnect_at_session", {"session_id": new_session_id} - # ) - - # create_async_task(load_and_tell_to_reconnect(), self.on_error) - - # posthog_logger.capture_event("load_session", {"session_id": session_id}) - async def set_model_for_role_from_index(self, role: str, index: int): models = self.get_config().models temp = models.default @@ -276,22 +198,6 @@ class GUIProtocolServer: # TODO pass - def save_context_group(self, title: str, context_items: List[ContextItem]): - create_async_task( - self.session.autopilot.save_context_group(title, context_items), - self.on_error, - ) - - def select_context_group(self, id: str): - create_async_task( - self.session.autopilot.select_context_group(id), self.on_error - ) - - def delete_context_group(self, id: str): - create_async_task( - self.session.autopilot.delete_context_group(id), self.on_error - ) - # region: Send data to GUI _running_autopilots: Dict[str, Autopilot] = {} @@ -303,7 +209,9 @@ class GUIProtocolServer: "step run", { "step_name": step_to_log.name, - "params": step_to_log.params if step is None else step.dict(), + "params": step.dict() + if step is not None + else state.history[-1].params, "context": list( map( lambda item: item.dict(), From d0cff2682a4c4b434cc67c01257a182191640372 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 14 Nov 2023 12:37:51 -0800 Subject: [PATCH 04/15] =?UTF-8?q?=F0=9F=9A=A7=20WIP=20on=20models=20config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vscode/SerializedContinueConfig.json | 83 +- extensions/vscode/schema/ContinueConfig.d.ts | 438 +++++++++ extensions/vscode/schema/LLM.d.ts | 41 +- extensions/vscode/schema/Models.d.ts | 41 +- .../schema/SerializedContinueConfig.d.ts | 60 +- gui/src/pages/settings.tsx | 10 +- gui/src/schema/ContinueConfig.d.ts | 438 +++++++++ gui/src/schema/LLM.d.ts | 41 +- gui/src/schema/Models.d.ts | 41 +- gui/src/schema/SerializedContinueConfig.d.ts | 60 +- schema/json/ContinueConfig.json | 831 ++++++++++++++++++ schema/json/LLM.json | 183 ++-- schema/json/Models.json | 183 ++-- schema/json/SerializedContinueConfig.json | 88 +- server/continuedev/__main__.py | 17 +- server/continuedev/core/autopilot.py | 19 +- server/continuedev/core/config/config.py | 23 +- server/continuedev/core/config/context.py | 12 + .../core/config/serialized_config.py | 27 +- server/continuedev/core/config/shared.py | 4 + server/continuedev/core/models.py | 12 +- server/continuedev/core/sdk.py | 8 +- server/continuedev/core/steps.py | 22 +- server/continuedev/headless/__init__.py | 11 +- server/continuedev/libs/index/build_index.py | 7 +- server/continuedev/libs/llm/ggml.py | 9 +- .../continuedev/libs/llm/hf_inference_api.py | 4 +- server/continuedev/libs/llm/hf_tgi.py | 14 +- server/continuedev/libs/llm/llamacpp.py | 12 +- server/continuedev/libs/llm/ollama.py | 11 +- server/continuedev/libs/llm/openai.py | 6 +- server/continuedev/libs/llm/text_gen_webui.py | 7 +- server/continuedev/libs/llm/together.py | 11 +- server/continuedev/libs/util/paths.py | 8 +- server/continuedev/plugins/policies/commit.py | 2 +- .../continuedev/plugins/policies/default.py | 19 +- .../continuedev/plugins/policies/headless.py | 2 +- server/continuedev/server/main.py | 20 +- server/continuedev/server/window_manager.py | 36 +- server/tests/step_test.py | 2 +- server/tests/util/config.py | 2 +- 41 files changed, 2414 insertions(+), 451 deletions(-) create mode 100644 extensions/vscode/schema/ContinueConfig.d.ts create mode 100644 gui/src/schema/ContinueConfig.d.ts create mode 100644 schema/json/ContinueConfig.json diff --git a/extensions/vscode/SerializedContinueConfig.json b/extensions/vscode/SerializedContinueConfig.json index 059755036..6afe2052b 100644 --- a/extensions/vscode/SerializedContinueConfig.json +++ b/extensions/vscode/SerializedContinueConfig.json @@ -2,33 +2,6 @@ "title": "SerializedContinueConfig", "$ref": "#/definitions/continuedev__core__config__serialized_config__SerializedContinueConfig", "definitions": { - "StepWithParams": { - "title": "StepWithParams", - "type": "object", - "properties": { - "step": { - "title": "Step", - "enum": [ - "AnswerQuestionChroma", - "GenerateShellCommandStep", - "EditHighlightedCodeStep", - "ShareSessionStep", - "CommentCodeStep", - "ClearHistoryStep", - "StackOverflowStep" - ], - "type": "string" - }, - "params": { - "title": "Params", - "type": "object" - } - }, - "required": [ - "step", - "params" - ] - }, "BaseCompletionOptions": { "title": "BaseCompletionOptions", "type": "object", @@ -189,6 +162,11 @@ } ] }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, "request_options": { "title": "Request Options", "description": "Options for the HTTP request to the LLM.", @@ -254,7 +232,18 @@ "type": "string" }, "step": { - "title": "Step" + "title": "Step", + "enum": [ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep", + "OpenConfigStep" + ], + "type": "string" }, "params": { "title": "Params", @@ -291,6 +280,33 @@ "description" ] }, + "ContextProviderWithParams": { + "title": "ContextProviderWithParams", + "type": "object", + "properties": { + "name": { + "title": "Name", + "enum": [ + "diff", + "github", + "terminal", + "open", + "google", + "search", + "url" + ], + "type": "string" + }, + "params": { + "title": "Params", + "default": {}, + "type": "object" + } + }, + "required": [ + "name" + ] + }, "RetrievalSettings": { "title": "RetrievalSettings", "type": "object", @@ -359,15 +375,6 @@ "title": "SerializedContinueConfig", "type": "object", "properties": { - "steps_on_startup": { - "title": "Steps On Startup", - "description": "Steps that will be automatically run at the beginning of a new session", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/StepWithParams" - } - }, "disallowed_steps": { "title": "Disallowed Steps", "description": "Steps that are not allowed to be run, and will be skipped if attempted", @@ -461,7 +468,7 @@ "default": [], "type": "array", "items": { - "$ref": "#/definitions/StepWithParams" + "$ref": "#/definitions/ContextProviderWithParams" } }, "user_token": { diff --git a/extensions/vscode/schema/ContinueConfig.d.ts b/extensions/vscode/schema/ContinueConfig.d.ts new file mode 100644 index 000000000..846cab197 --- /dev/null +++ b/extensions/vscode/schema/ContinueConfig.d.ts @@ -0,0 +1,438 @@ +/* eslint-disable */ +/** + * This file was automatically generated by json-schema-to-typescript. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run json-schema-to-typescript to regenerate this file. + */ + +export type ContinueConfig = ContinueConfig1; +export type Name = string; +export type Hide = boolean; +export type Description = string; +export type ClassName = string; +export type SystemMessage = string; +export type Role = "assistant" | "user" | "system" | "function"; +export type Content = string; +export type Name1 = string; +export type Summary = string; +export type Name2 = string; +export type Arguments = string; +export type ChatContext = ChatMessage[]; +export type ManageOwnChatContext = boolean; +/** + * Steps that will be automatically run at the beginning of a new session + */ +export type StepsOnStartup = Step[]; +/** + * Steps that are not allowed to be run, and will be skipped if attempted + */ +export type DisallowedSteps = string[]; +/** + * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. + */ +export type AllowAnonymousTelemetry = boolean; +/** + * Configuration for the models used by Continue. Read more about how to configure models in the documentation. + */ +export type Models = Models1; +/** + * A title that will identify this model in the model selection dropdown + */ +export type Title = string; +/** + * The unique ID of the user. + */ +export type UniqueId = string; +/** + * The name of the model to be used (e.g. gpt-4, codellama) + */ +export type Model = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage1 = string; +/** + * The maximum context length of the LLM in tokens, as counted by count_tokens. + */ +export type ContextLength = number; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions = BaseCompletionOptions; +/** + * The temperature of the completion. + */ +export type Temperature = number; +/** + * The top_p of the completion. + */ +export type TopP = number; +/** + * The top_k of the completion. + */ +export type TopK = number; +/** + * The presence penalty Aof the completion. + */ +export type PresencePenalty = number; +/** + * The frequency penalty of the completion. + */ +export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; +/** + * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. + */ +export type Timeout = number; +/** + * Whether to verify SSL certificates for requests. + */ +export type VerifySsl = boolean; +/** + * Path to a custom CA bundle to use when making the HTTP request + */ +export type CaBundlePath = string; +/** + * Proxy URL to use when making the HTTP request + */ +export type Proxy = string; +/** + * The API key for the LLM provider. + */ +export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; +export type Saved = LLM[]; +export type Temperature1 = number; +export type SystemMessage2 = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage3 = string; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions1 = BaseCompletionOptions; +export type Name3 = string; +export type Prompt = string; +export type Description1 = string; +/** + * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. + */ +export type CustomCommands = CustomCommand[]; +export type Name4 = string; +export type Description2 = string; +export type Step1 = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep" + | "OpenConfigStep"; +/** + * An array of slash commands that let you map custom Steps to a shortcut. + */ +export type SlashCommands = SlashCommand[]; +/** + * The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R) + */ +export type OnTraceback = Step; +/** + * A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time. + */ +export type PolicyOverride = Policy; +/** + * The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider. + */ +export type Title1 = string; +/** + * The display title of the ContextProvider shown in the dropdown menu + */ +export type DisplayTitle = string; +/** + * A description of the ContextProvider displayed in the dropdown menu + */ +export type Description3 = string; +/** + * Indicates whether the ContextProvider is dynamic + */ +export type Dynamic = boolean; +/** + * Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query. + */ +export type RequiresQuery = boolean; +export type Name5 = string; +export type Description4 = string; +export type ProviderTitle = string; +export type ItemId = string; +export type Content1 = string; +export type Editing = boolean; +export type Editable = boolean; +/** + * List of selected items in the ContextProvider + */ +export type SelectedItems = ContextItem[]; +/** + * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. + */ +export type ContextProviders = ContextProvider[]; +/** + * An optional token to identify the user. + */ +export type UserToken = string; +/** + * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. + */ +export type DataServerUrl = string; +/** + * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. + */ +export type DisableSummaries = boolean; +/** + * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. + */ +export type DisableIndexing = boolean; +/** + * Settings for the retrieval system. Read more about the retrieval system in the documentation. + */ +export type RetrievalSettings = RetrievalSettings1; +/** + * Number of results to initially retrieve from vector database + */ +export type NRetrieve = number; +/** + * Final number of results to use after re-ranking + */ +export type NFinal = number; +/** + * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results + */ +export type UseReranking = boolean; +/** + * Number of results to group together when re-ranking. Each group will be processed in parallel. + */ +export type RerankGroupSize = number; +/** + * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. + */ +export type IgnoreFiles = string[]; +/** + * OpenAI API key + */ +export type OpenaiApiKey = string; +/** + * OpenAI API base URL + */ +export type ApiBase1 = string; +/** + * OpenAI API type + */ +export type ApiType = string; +/** + * OpenAI API version + */ +export type ApiVersion = string; +/** + * OpenAI organization ID + */ +export type OrganizationId = string; + +/** + * Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\.continue\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session. + */ +export interface ContinueConfig1 { + steps_on_startup?: StepsOnStartup; + disallowed_steps?: DisallowedSteps; + allow_anonymous_telemetry?: AllowAnonymousTelemetry; + models?: Models; + system_message?: SystemMessage3; + completion_options?: CompletionOptions1; + custom_commands?: CustomCommands; + slash_commands?: SlashCommands; + on_traceback?: OnTraceback; + policy_override?: PolicyOverride; + context_providers?: ContextProviders; + user_token?: UserToken; + data_server_url?: DataServerUrl; + disable_summaries?: DisableSummaries; + disable_indexing?: DisableIndexing; + retrieval_settings?: RetrievalSettings; + [k: string]: unknown; +} +export interface Step { + name?: Name; + hide?: Hide; + description?: Description; + class_name?: ClassName; + system_message?: SystemMessage; + chat_context?: ChatContext; + manage_own_chat_context?: ManageOwnChatContext; + [k: string]: unknown; +} +export interface ChatMessage { + role: Role; + content?: Content; + name?: Name1; + summary: Summary; + function_call?: FunctionCall; + [k: string]: unknown; +} +export interface FunctionCall { + name: Name2; + arguments: Arguments; + [k: string]: unknown; +} +/** + * Main class that holds the current model configuration + */ +export interface Models1 { + default: LLM; + summarize?: LLM; + edit?: LLM; + chat?: LLM; + saved?: Saved; + temperature?: Temperature1; + system_message?: SystemMessage2; + [k: string]: unknown; +} +export interface LLM { + title?: Title; + unique_id?: UniqueId; + model: Model; + system_message?: SystemMessage1; + context_length?: ContextLength; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { + temperature?: Temperature; + top_p?: TopP; + top_k?: TopK; + presence_penalty?: PresencePenalty; + frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { + timeout?: Timeout; + verify_ssl?: VerifySsl; + ca_bundle_path?: CaBundlePath; + proxy?: Proxy; + headers?: Headers; + [k: string]: unknown; +} +/** + * Headers to use when making the HTTP request + */ +export interface Headers { + [k: string]: string; +} +/** + * A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information. + */ +export interface PromptTemplates { + [k: string]: unknown; +} +export interface CustomCommand { + name: Name3; + prompt: Prompt; + description: Description1; + [k: string]: unknown; +} +export interface SlashCommand { + name: Name4; + description: Description2; + step: Step1; + params?: Params; + [k: string]: unknown; +} +export interface Params { + [k: string]: unknown; +} +/** + * A rule that determines which step to take next + */ +export interface Policy { + [k: string]: unknown; +} +/** + * The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'. + * When you type '@', the context provider will be asked to populate a list of options. + * These options will be updated on each keystroke. + * When you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object). + */ +export interface ContextProvider { + title: Title1; + ide?: Ide; + display_title: DisplayTitle; + description: Description3; + dynamic: Dynamic; + requires_query?: RequiresQuery; + selected_items?: SelectedItems; + [k: string]: unknown; +} +export interface Ide { + [k: string]: unknown; +} +/** + * A ContextItem is a single item that is stored in the ContextManager. + */ +export interface ContextItem { + description: ContextItemDescription; + content: Content1; + editing?: Editing; + editable?: Editable; + [k: string]: unknown; +} +/** + * A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'. + * + * The id can be used to retrieve the ContextItem from the ContextManager. + */ +export interface ContextItemDescription { + name: Name5; + description: Description4; + id: ContextItemId; + [k: string]: unknown; +} +/** + * A ContextItemId is a unique identifier for a ContextItem. + */ +export interface ContextItemId { + provider_title: ProviderTitle; + item_id: ItemId; + [k: string]: unknown; +} +export interface RetrievalSettings1 { + n_retrieve?: NRetrieve; + n_final?: NFinal; + use_reranking?: UseReranking; + rerank_group_size?: RerankGroupSize; + ignore_files?: IgnoreFiles; + openai_api_key?: OpenaiApiKey; + api_base?: ApiBase1; + api_type?: ApiType; + api_version?: ApiVersion; + organization_id?: OrganizationId; + [k: string]: unknown; +} diff --git a/extensions/vscode/schema/LLM.d.ts b/extensions/vscode/schema/LLM.d.ts index 663ceb1d2..47321e751 100644 --- a/extensions/vscode/schema/LLM.d.ts +++ b/extensions/vscode/schema/LLM.d.ts @@ -27,13 +27,9 @@ export type SystemMessage = string; */ export type ContextLength = number; /** - * The maximum number of tokens to generate. + * Options for the completion endpoint. Read more about the completion options in the documentation. */ -export type MaxTokens = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; +export type CompletionOptions = BaseCompletionOptions; /** * The temperature of the completion. */ @@ -54,6 +50,18 @@ export type PresencePenalty = number; * The frequency penalty of the completion. */ export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; /** * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. */ @@ -74,6 +82,10 @@ export type Proxy = string; * The API key for the LLM provider. */ export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; export interface LLM1 { title?: Title; @@ -81,20 +93,29 @@ export interface LLM1 { model: Model; system_message?: SystemMessage; context_length?: ContextLength; - max_tokens?: MaxTokens; - stop_tokens?: StopTokens; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { temperature?: Temperature; top_p?: TopP; top_k?: TopK; presence_penalty?: PresencePenalty; frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { timeout?: Timeout; verify_ssl?: VerifySsl; ca_bundle_path?: CaBundlePath; proxy?: Proxy; headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; [k: string]: unknown; } /** diff --git a/extensions/vscode/schema/Models.d.ts b/extensions/vscode/schema/Models.d.ts index 52547c4a2..683995905 100644 --- a/extensions/vscode/schema/Models.d.ts +++ b/extensions/vscode/schema/Models.d.ts @@ -27,13 +27,9 @@ export type SystemMessage = string; */ export type ContextLength = number; /** - * The maximum number of tokens to generate. + * Options for the completion endpoint. Read more about the completion options in the documentation. */ -export type MaxTokens = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; +export type CompletionOptions = BaseCompletionOptions; /** * The temperature of the completion. */ @@ -54,6 +50,18 @@ export type PresencePenalty = number; * The frequency penalty of the completion. */ export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; /** * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. */ @@ -74,6 +82,10 @@ export type Proxy = string; * The API key for the LLM provider. */ export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; export type Saved = LLM[]; export type Temperature1 = number; export type SystemMessage1 = string; @@ -97,20 +109,29 @@ export interface LLM { model: Model; system_message?: SystemMessage; context_length?: ContextLength; - max_tokens?: MaxTokens; - stop_tokens?: StopTokens; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { temperature?: Temperature; top_p?: TopP; top_k?: TopK; presence_penalty?: PresencePenalty; frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { timeout?: Timeout; verify_ssl?: VerifySsl; ca_bundle_path?: CaBundlePath; proxy?: Proxy; headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; [k: string]: unknown; } /** diff --git a/extensions/vscode/schema/SerializedContinueConfig.d.ts b/extensions/vscode/schema/SerializedContinueConfig.d.ts index bafd2ab0d..156498a7b 100644 --- a/extensions/vscode/schema/SerializedContinueConfig.d.ts +++ b/extensions/vscode/schema/SerializedContinueConfig.d.ts @@ -6,18 +6,6 @@ */ export type SerializedContinueConfig = SerializedContinueConfig1; -export type Step = - | "AnswerQuestionChroma" - | "GenerateShellCommandStep" - | "EditHighlightedCodeStep" - | "ShareSessionStep" - | "CommentCodeStep" - | "ClearHistoryStep" - | "StackOverflowStep"; -/** - * Steps that will be automatically run at the beginning of a new session - */ -export type StepsOnStartup = StepWithParams[]; /** * Steps that are not allowed to be run, and will be skipped if attempted */ @@ -98,6 +86,10 @@ export type Stop = string[]; * The maximum number of tokens to generate. */ export type MaxTokens = number; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage = string; /** * Options for the HTTP request to the LLM. */ @@ -139,12 +131,25 @@ export type Edit = string; * The model to use for summarization. If not set, will fall back to default. */ export type Summarize = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage1 = string; /** * Default options for completion. These will be overriden by any options set for a specific model. */ export type CompletionOptions1 = BaseCompletionOptions; export type Name = string; export type Description = string; +export type Step = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep" + | "OpenConfigStep"; /** * An array of slash commands that let you map custom Steps to a shortcut. */ @@ -156,10 +161,11 @@ export type Description1 = string; * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. */ export type CustomCommands = CustomCommand[]; +export type Name2 = "diff" | "github" | "terminal" | "open" | "google" | "search" | "url"; /** * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. */ -export type ContextProviders = StepWithParams[]; +export type ContextProviders = ContextProviderWithParams[]; /** * An optional token to identify the user. */ @@ -222,11 +228,11 @@ export type ApiVersion = string; export type OrganizationId = string; export interface SerializedContinueConfig1 { - steps_on_startup?: StepsOnStartup; disallowed_steps?: DisallowedSteps; allow_anonymous_telemetry?: AllowAnonymousTelemetry; models?: Models; model_roles?: ModelRoles; + system_message?: SystemMessage1; completion_options?: CompletionOptions1; slash_commands?: SlashCommands; custom_commands?: CustomCommands; @@ -238,14 +244,6 @@ export interface SerializedContinueConfig1 { retrieval_settings?: RetrievalSettings; [k: string]: unknown; } -export interface StepWithParams { - step: Step; - params: Params; - [k: string]: unknown; -} -export interface Params { - [k: string]: unknown; -} export interface ModelDescription { title: Title; provider: Provider; @@ -255,6 +253,7 @@ export interface ModelDescription { context_length?: ContextLength; template?: Template; completion_options?: CompletionOptions; + system_message?: SystemMessage; request_options?: RequestOptions; [k: string]: unknown; } @@ -292,14 +291,11 @@ export interface ModelRoles1 { export interface SlashCommand { name: Name; description: Description; - step: Step1; - params?: Params1; + step: Step; + params?: Params; [k: string]: unknown; } -export interface Step1 { - [k: string]: unknown; -} -export interface Params1 { +export interface Params { [k: string]: unknown; } export interface CustomCommand { @@ -308,6 +304,14 @@ export interface CustomCommand { description: Description1; [k: string]: unknown; } +export interface ContextProviderWithParams { + name: Name2; + params?: Params1; + [k: string]: unknown; +} +export interface Params1 { + [k: string]: unknown; +} export interface RetrievalSettings1 { n_retrieve?: NRetrieve; n_final?: NFinal; diff --git a/gui/src/pages/settings.tsx b/gui/src/pages/settings.tsx index e0677b3ff..31e81382d 100644 --- a/gui/src/pages/settings.tsx +++ b/gui/src/pages/settings.tsx @@ -92,8 +92,10 @@ function Settings() { const submitChanges = () => { if (!client) return; - const systemMessage = formMethods.watch("system_message"); - const temperature = formMethods.watch("temperature"); + const systemMessage = formMethods.watch("system_message") as + | string + | undefined; + const temperature = formMethods.watch("temperature") as number | undefined; // const models = formMethods.watch("models"); client.setSystemMessage(systemMessage || ""); @@ -176,8 +178,8 @@ function Settings() {

- {formMethods.watch("temperature") || - config.temperature || + {(formMethods.watch("temperature") as number | undefined) || + config.completion_options.temperature || "-"}

diff --git a/gui/src/schema/ContinueConfig.d.ts b/gui/src/schema/ContinueConfig.d.ts new file mode 100644 index 000000000..846cab197 --- /dev/null +++ b/gui/src/schema/ContinueConfig.d.ts @@ -0,0 +1,438 @@ +/* eslint-disable */ +/** + * This file was automatically generated by json-schema-to-typescript. + * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, + * and run json-schema-to-typescript to regenerate this file. + */ + +export type ContinueConfig = ContinueConfig1; +export type Name = string; +export type Hide = boolean; +export type Description = string; +export type ClassName = string; +export type SystemMessage = string; +export type Role = "assistant" | "user" | "system" | "function"; +export type Content = string; +export type Name1 = string; +export type Summary = string; +export type Name2 = string; +export type Arguments = string; +export type ChatContext = ChatMessage[]; +export type ManageOwnChatContext = boolean; +/** + * Steps that will be automatically run at the beginning of a new session + */ +export type StepsOnStartup = Step[]; +/** + * Steps that are not allowed to be run, and will be skipped if attempted + */ +export type DisallowedSteps = string[]; +/** + * If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data. + */ +export type AllowAnonymousTelemetry = boolean; +/** + * Configuration for the models used by Continue. Read more about how to configure models in the documentation. + */ +export type Models = Models1; +/** + * A title that will identify this model in the model selection dropdown + */ +export type Title = string; +/** + * The unique ID of the user. + */ +export type UniqueId = string; +/** + * The name of the model to be used (e.g. gpt-4, codellama) + */ +export type Model = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage1 = string; +/** + * The maximum context length of the LLM in tokens, as counted by count_tokens. + */ +export type ContextLength = number; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions = BaseCompletionOptions; +/** + * The temperature of the completion. + */ +export type Temperature = number; +/** + * The top_p of the completion. + */ +export type TopP = number; +/** + * The top_k of the completion. + */ +export type TopK = number; +/** + * The presence penalty Aof the completion. + */ +export type PresencePenalty = number; +/** + * The frequency penalty of the completion. + */ +export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; +/** + * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. + */ +export type Timeout = number; +/** + * Whether to verify SSL certificates for requests. + */ +export type VerifySsl = boolean; +/** + * Path to a custom CA bundle to use when making the HTTP request + */ +export type CaBundlePath = string; +/** + * Proxy URL to use when making the HTTP request + */ +export type Proxy = string; +/** + * The API key for the LLM provider. + */ +export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; +export type Saved = LLM[]; +export type Temperature1 = number; +export type SystemMessage2 = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage3 = string; +/** + * Options for the completion endpoint. Read more about the completion options in the documentation. + */ +export type CompletionOptions1 = BaseCompletionOptions; +export type Name3 = string; +export type Prompt = string; +export type Description1 = string; +/** + * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. + */ +export type CustomCommands = CustomCommand[]; +export type Name4 = string; +export type Description2 = string; +export type Step1 = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep" + | "OpenConfigStep"; +/** + * An array of slash commands that let you map custom Steps to a shortcut. + */ +export type SlashCommands = SlashCommand[]; +/** + * The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R) + */ +export type OnTraceback = Step; +/** + * A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time. + */ +export type PolicyOverride = Policy; +/** + * The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider. + */ +export type Title1 = string; +/** + * The display title of the ContextProvider shown in the dropdown menu + */ +export type DisplayTitle = string; +/** + * A description of the ContextProvider displayed in the dropdown menu + */ +export type Description3 = string; +/** + * Indicates whether the ContextProvider is dynamic + */ +export type Dynamic = boolean; +/** + * Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query. + */ +export type RequiresQuery = boolean; +export type Name5 = string; +export type Description4 = string; +export type ProviderTitle = string; +export type ItemId = string; +export type Content1 = string; +export type Editing = boolean; +export type Editable = boolean; +/** + * List of selected items in the ContextProvider + */ +export type SelectedItems = ContextItem[]; +/** + * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. + */ +export type ContextProviders = ContextProvider[]; +/** + * An optional token to identify the user. + */ +export type UserToken = string; +/** + * The URL of the server where development data is sent. No data is sent unless a valid user token is provided. + */ +export type DataServerUrl = string; +/** + * If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute. + */ +export type DisableSummaries = boolean; +/** + * If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes. + */ +export type DisableIndexing = boolean; +/** + * Settings for the retrieval system. Read more about the retrieval system in the documentation. + */ +export type RetrievalSettings = RetrievalSettings1; +/** + * Number of results to initially retrieve from vector database + */ +export type NRetrieve = number; +/** + * Final number of results to use after re-ranking + */ +export type NFinal = number; +/** + * Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results + */ +export type UseReranking = boolean; +/** + * Number of results to group together when re-ranking. Each group will be processed in parallel. + */ +export type RerankGroupSize = number; +/** + * Files to ignore when indexing the codebase. You can use glob patterns, such as ** /*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase. + */ +export type IgnoreFiles = string[]; +/** + * OpenAI API key + */ +export type OpenaiApiKey = string; +/** + * OpenAI API base URL + */ +export type ApiBase1 = string; +/** + * OpenAI API type + */ +export type ApiType = string; +/** + * OpenAI API version + */ +export type ApiVersion = string; +/** + * OpenAI organization ID + */ +export type OrganizationId = string; + +/** + * Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\.continue\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session. + */ +export interface ContinueConfig1 { + steps_on_startup?: StepsOnStartup; + disallowed_steps?: DisallowedSteps; + allow_anonymous_telemetry?: AllowAnonymousTelemetry; + models?: Models; + system_message?: SystemMessage3; + completion_options?: CompletionOptions1; + custom_commands?: CustomCommands; + slash_commands?: SlashCommands; + on_traceback?: OnTraceback; + policy_override?: PolicyOverride; + context_providers?: ContextProviders; + user_token?: UserToken; + data_server_url?: DataServerUrl; + disable_summaries?: DisableSummaries; + disable_indexing?: DisableIndexing; + retrieval_settings?: RetrievalSettings; + [k: string]: unknown; +} +export interface Step { + name?: Name; + hide?: Hide; + description?: Description; + class_name?: ClassName; + system_message?: SystemMessage; + chat_context?: ChatContext; + manage_own_chat_context?: ManageOwnChatContext; + [k: string]: unknown; +} +export interface ChatMessage { + role: Role; + content?: Content; + name?: Name1; + summary: Summary; + function_call?: FunctionCall; + [k: string]: unknown; +} +export interface FunctionCall { + name: Name2; + arguments: Arguments; + [k: string]: unknown; +} +/** + * Main class that holds the current model configuration + */ +export interface Models1 { + default: LLM; + summarize?: LLM; + edit?: LLM; + chat?: LLM; + saved?: Saved; + temperature?: Temperature1; + system_message?: SystemMessage2; + [k: string]: unknown; +} +export interface LLM { + title?: Title; + unique_id?: UniqueId; + model: Model; + system_message?: SystemMessage1; + context_length?: ContextLength; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { + temperature?: Temperature; + top_p?: TopP; + top_k?: TopK; + presence_penalty?: PresencePenalty; + frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { + timeout?: Timeout; + verify_ssl?: VerifySsl; + ca_bundle_path?: CaBundlePath; + proxy?: Proxy; + headers?: Headers; + [k: string]: unknown; +} +/** + * Headers to use when making the HTTP request + */ +export interface Headers { + [k: string]: string; +} +/** + * A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the "edit" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information. + */ +export interface PromptTemplates { + [k: string]: unknown; +} +export interface CustomCommand { + name: Name3; + prompt: Prompt; + description: Description1; + [k: string]: unknown; +} +export interface SlashCommand { + name: Name4; + description: Description2; + step: Step1; + params?: Params; + [k: string]: unknown; +} +export interface Params { + [k: string]: unknown; +} +/** + * A rule that determines which step to take next + */ +export interface Policy { + [k: string]: unknown; +} +/** + * The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'. + * When you type '@', the context provider will be asked to populate a list of options. + * These options will be updated on each keystroke. + * When you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object). + */ +export interface ContextProvider { + title: Title1; + ide?: Ide; + display_title: DisplayTitle; + description: Description3; + dynamic: Dynamic; + requires_query?: RequiresQuery; + selected_items?: SelectedItems; + [k: string]: unknown; +} +export interface Ide { + [k: string]: unknown; +} +/** + * A ContextItem is a single item that is stored in the ContextManager. + */ +export interface ContextItem { + description: ContextItemDescription; + content: Content1; + editing?: Editing; + editable?: Editable; + [k: string]: unknown; +} +/** + * A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'. + * + * The id can be used to retrieve the ContextItem from the ContextManager. + */ +export interface ContextItemDescription { + name: Name5; + description: Description4; + id: ContextItemId; + [k: string]: unknown; +} +/** + * A ContextItemId is a unique identifier for a ContextItem. + */ +export interface ContextItemId { + provider_title: ProviderTitle; + item_id: ItemId; + [k: string]: unknown; +} +export interface RetrievalSettings1 { + n_retrieve?: NRetrieve; + n_final?: NFinal; + use_reranking?: UseReranking; + rerank_group_size?: RerankGroupSize; + ignore_files?: IgnoreFiles; + openai_api_key?: OpenaiApiKey; + api_base?: ApiBase1; + api_type?: ApiType; + api_version?: ApiVersion; + organization_id?: OrganizationId; + [k: string]: unknown; +} diff --git a/gui/src/schema/LLM.d.ts b/gui/src/schema/LLM.d.ts index 663ceb1d2..47321e751 100644 --- a/gui/src/schema/LLM.d.ts +++ b/gui/src/schema/LLM.d.ts @@ -27,13 +27,9 @@ export type SystemMessage = string; */ export type ContextLength = number; /** - * The maximum number of tokens to generate. + * Options for the completion endpoint. Read more about the completion options in the documentation. */ -export type MaxTokens = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; +export type CompletionOptions = BaseCompletionOptions; /** * The temperature of the completion. */ @@ -54,6 +50,18 @@ export type PresencePenalty = number; * The frequency penalty of the completion. */ export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; /** * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. */ @@ -74,6 +82,10 @@ export type Proxy = string; * The API key for the LLM provider. */ export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; export interface LLM1 { title?: Title; @@ -81,20 +93,29 @@ export interface LLM1 { model: Model; system_message?: SystemMessage; context_length?: ContextLength; - max_tokens?: MaxTokens; - stop_tokens?: StopTokens; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { temperature?: Temperature; top_p?: TopP; top_k?: TopK; presence_penalty?: PresencePenalty; frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { timeout?: Timeout; verify_ssl?: VerifySsl; ca_bundle_path?: CaBundlePath; proxy?: Proxy; headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; [k: string]: unknown; } /** diff --git a/gui/src/schema/Models.d.ts b/gui/src/schema/Models.d.ts index 52547c4a2..683995905 100644 --- a/gui/src/schema/Models.d.ts +++ b/gui/src/schema/Models.d.ts @@ -27,13 +27,9 @@ export type SystemMessage = string; */ export type ContextLength = number; /** - * The maximum number of tokens to generate. + * Options for the completion endpoint. Read more about the completion options in the documentation. */ -export type MaxTokens = number; -/** - * Tokens that will stop the completion. - */ -export type StopTokens = string[]; +export type CompletionOptions = BaseCompletionOptions; /** * The temperature of the completion. */ @@ -54,6 +50,18 @@ export type PresencePenalty = number; * The frequency penalty of the completion. */ export type FrequencyPenalty = number; +/** + * The stop tokens of the completion. + */ +export type Stop = string[]; +/** + * The maximum number of tokens to generate. + */ +export type MaxTokens = number; +/** + * Options for the HTTP request to the LLM. + */ +export type RequestOptions = RequestOptions1; /** * Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts. */ @@ -74,6 +82,10 @@ export type Proxy = string; * The API key for the LLM provider. */ export type ApiKey = string; +/** + * The base URL of the LLM API. + */ +export type ApiBase = string; export type Saved = LLM[]; export type Temperature1 = number; export type SystemMessage1 = string; @@ -97,20 +109,29 @@ export interface LLM { model: Model; system_message?: SystemMessage; context_length?: ContextLength; - max_tokens?: MaxTokens; - stop_tokens?: StopTokens; + completion_options?: CompletionOptions; + request_options?: RequestOptions; + prompt_templates?: PromptTemplates; + api_key?: ApiKey; + api_base?: ApiBase; + [k: string]: unknown; +} +export interface BaseCompletionOptions { temperature?: Temperature; top_p?: TopP; top_k?: TopK; presence_penalty?: PresencePenalty; frequency_penalty?: FrequencyPenalty; + stop?: Stop; + max_tokens?: MaxTokens; + [k: string]: unknown; +} +export interface RequestOptions1 { timeout?: Timeout; verify_ssl?: VerifySsl; ca_bundle_path?: CaBundlePath; proxy?: Proxy; headers?: Headers; - prompt_templates?: PromptTemplates; - api_key?: ApiKey; [k: string]: unknown; } /** diff --git a/gui/src/schema/SerializedContinueConfig.d.ts b/gui/src/schema/SerializedContinueConfig.d.ts index bafd2ab0d..156498a7b 100644 --- a/gui/src/schema/SerializedContinueConfig.d.ts +++ b/gui/src/schema/SerializedContinueConfig.d.ts @@ -6,18 +6,6 @@ */ export type SerializedContinueConfig = SerializedContinueConfig1; -export type Step = - | "AnswerQuestionChroma" - | "GenerateShellCommandStep" - | "EditHighlightedCodeStep" - | "ShareSessionStep" - | "CommentCodeStep" - | "ClearHistoryStep" - | "StackOverflowStep"; -/** - * Steps that will be automatically run at the beginning of a new session - */ -export type StepsOnStartup = StepWithParams[]; /** * Steps that are not allowed to be run, and will be skipped if attempted */ @@ -98,6 +86,10 @@ export type Stop = string[]; * The maximum number of tokens to generate. */ export type MaxTokens = number; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage = string; /** * Options for the HTTP request to the LLM. */ @@ -139,12 +131,25 @@ export type Edit = string; * The model to use for summarization. If not set, will fall back to default. */ export type Summarize = string; +/** + * A system message that will always be followed by the LLM + */ +export type SystemMessage1 = string; /** * Default options for completion. These will be overriden by any options set for a specific model. */ export type CompletionOptions1 = BaseCompletionOptions; export type Name = string; export type Description = string; +export type Step = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep" + | "OpenConfigStep"; /** * An array of slash commands that let you map custom Steps to a shortcut. */ @@ -156,10 +161,11 @@ export type Description1 = string; * An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt. */ export type CustomCommands = CustomCommand[]; +export type Name2 = "diff" | "github" | "terminal" | "open" | "google" | "search" | "url"; /** * A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation. */ -export type ContextProviders = StepWithParams[]; +export type ContextProviders = ContextProviderWithParams[]; /** * An optional token to identify the user. */ @@ -222,11 +228,11 @@ export type ApiVersion = string; export type OrganizationId = string; export interface SerializedContinueConfig1 { - steps_on_startup?: StepsOnStartup; disallowed_steps?: DisallowedSteps; allow_anonymous_telemetry?: AllowAnonymousTelemetry; models?: Models; model_roles?: ModelRoles; + system_message?: SystemMessage1; completion_options?: CompletionOptions1; slash_commands?: SlashCommands; custom_commands?: CustomCommands; @@ -238,14 +244,6 @@ export interface SerializedContinueConfig1 { retrieval_settings?: RetrievalSettings; [k: string]: unknown; } -export interface StepWithParams { - step: Step; - params: Params; - [k: string]: unknown; -} -export interface Params { - [k: string]: unknown; -} export interface ModelDescription { title: Title; provider: Provider; @@ -255,6 +253,7 @@ export interface ModelDescription { context_length?: ContextLength; template?: Template; completion_options?: CompletionOptions; + system_message?: SystemMessage; request_options?: RequestOptions; [k: string]: unknown; } @@ -292,14 +291,11 @@ export interface ModelRoles1 { export interface SlashCommand { name: Name; description: Description; - step: Step1; - params?: Params1; + step: Step; + params?: Params; [k: string]: unknown; } -export interface Step1 { - [k: string]: unknown; -} -export interface Params1 { +export interface Params { [k: string]: unknown; } export interface CustomCommand { @@ -308,6 +304,14 @@ export interface CustomCommand { description: Description1; [k: string]: unknown; } +export interface ContextProviderWithParams { + name: Name2; + params?: Params1; + [k: string]: unknown; +} +export interface Params1 { + [k: string]: unknown; +} export interface RetrievalSettings1 { n_retrieve?: NRetrieve; n_final?: NFinal; diff --git a/schema/json/ContinueConfig.json b/schema/json/ContinueConfig.json new file mode 100644 index 000000000..f214602d7 --- /dev/null +++ b/schema/json/ContinueConfig.json @@ -0,0 +1,831 @@ +{ + "title": "ContinueConfig", + "$ref": "#/definitions/continuedev__core__config__config__ContinueConfig", + "definitions": { + "FunctionCall": { + "title": "FunctionCall", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "arguments": { + "title": "Arguments", + "type": "string" + } + }, + "required": [ + "name", + "arguments" + ] + }, + "ChatMessage": { + "title": "ChatMessage", + "type": "object", + "properties": { + "role": { + "title": "Role", + "enum": [ + "assistant", + "user", + "system", + "function" + ], + "type": "string" + }, + "content": { + "title": "Content", + "type": "string" + }, + "name": { + "title": "Name", + "type": "string" + }, + "summary": { + "title": "Summary", + "type": "string" + }, + "function_call": { + "$ref": "#/definitions/FunctionCall" + } + }, + "required": [ + "role", + "summary" + ] + }, + "Step": { + "title": "Step", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "hide": { + "title": "Hide", + "default": false, + "type": "boolean" + }, + "description": { + "title": "Description", + "default": "", + "type": "string" + }, + "class_name": { + "title": "Class Name", + "default": "Step", + "type": "string" + }, + "system_message": { + "title": "System Message", + "type": "string" + }, + "chat_context": { + "title": "Chat Context", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/ChatMessage" + } + }, + "manage_own_chat_context": { + "title": "Manage Own Chat Context", + "default": false, + "type": "boolean" + } + } + }, + "BaseCompletionOptions": { + "title": "BaseCompletionOptions", + "type": "object", + "properties": { + "temperature": { + "title": "Temperature", + "description": "The temperature of the completion.", + "type": "number" + }, + "top_p": { + "title": "Top P", + "description": "The top_p of the completion.", + "type": "number" + }, + "top_k": { + "title": "Top K", + "description": "The top_k of the completion.", + "type": "integer" + }, + "presence_penalty": { + "title": "Presence Penalty", + "description": "The presence penalty Aof the completion.", + "type": "number" + }, + "frequency_penalty": { + "title": "Frequency Penalty", + "description": "The frequency penalty of the completion.", + "type": "number" + }, + "stop": { + "title": "Stop", + "description": "The stop tokens of the completion.", + "type": "array", + "items": { + "type": "string" + } + }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + } + } + }, + "RequestOptions": { + "title": "RequestOptions", + "type": "object", + "properties": { + "timeout": { + "title": "Timeout", + "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + "default": 300, + "type": "integer" + }, + "verify_ssl": { + "title": "Verify Ssl", + "description": "Whether to verify SSL certificates for requests.", + "type": "boolean" + }, + "ca_bundle_path": { + "title": "Ca Bundle Path", + "description": "Path to a custom CA bundle to use when making the HTTP request", + "type": "string" + }, + "proxy": { + "title": "Proxy", + "description": "Proxy URL to use when making the HTTP request", + "type": "string" + }, + "headers": { + "title": "Headers", + "description": "Headers to use when making the HTTP request", + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, + "LLM": { + "title": "LLM", + "type": "object", + "properties": { + "title": { + "title": "Title", + "description": "A title that will identify this model in the model selection dropdown", + "type": "string" + }, + "unique_id": { + "title": "Unique Id", + "description": "The unique ID of the user.", + "type": "string" + }, + "model": { + "title": "Model", + "description": "The name of the model to be used (e.g. gpt-4, codellama)", + "type": "string" + }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, + "context_length": { + "title": "Context Length", + "description": "The maximum context length of the LLM in tokens, as counted by count_tokens.", + "default": 2048, + "type": "integer" + }, + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "request_options": { + "title": "Request Options", + "description": "Options for the HTTP request to the LLM.", + "default": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "allOf": [ + { + "$ref": "#/definitions/RequestOptions" + } + ] + }, + "prompt_templates": { + "title": "Prompt Templates", + "description": "A dictionary of prompt templates that can be used to customize the behavior of the LLM in certain situations. For example, set the \"edit\" key in order to change the prompt that is used for the /edit slash command. Each value in the dictionary is a string templated in mustache syntax, and filled in at runtime with the variables specific to the situation. See the documentation for more information.", + "default": {}, + "type": "object" + }, + "api_key": { + "title": "Api Key", + "description": "The API key for the LLM provider.", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "The base URL of the LLM API.", + "type": "string" + } + }, + "required": [ + "model" + ] + }, + "Models": { + "title": "Models", + "description": "Main class that holds the current model configuration", + "type": "object", + "properties": { + "default": { + "$ref": "#/definitions/LLM" + }, + "summarize": { + "$ref": "#/definitions/LLM" + }, + "edit": { + "$ref": "#/definitions/LLM" + }, + "chat": { + "$ref": "#/definitions/LLM" + }, + "saved": { + "title": "Saved", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/LLM" + } + }, + "temperature": { + "title": "Temperature", + "type": "number" + }, + "system_message": { + "title": "System Message", + "type": "string" + } + }, + "required": [ + "default" + ] + }, + "CustomCommand": { + "title": "CustomCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "prompt": { + "title": "Prompt", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + } + }, + "required": [ + "name", + "prompt", + "description" + ] + }, + "SlashCommand": { + "title": "SlashCommand", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "step": { + "title": "Step", + "enum": [ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep", + "OpenConfigStep" + ], + "type": "string" + }, + "params": { + "title": "Params", + "default": {}, + "type": "object" + } + }, + "required": [ + "name", + "description", + "step" + ] + }, + "Policy": { + "title": "Policy", + "description": "A rule that determines which step to take next", + "type": "object", + "properties": {} + }, + "ContextItemId": { + "title": "ContextItemId", + "description": "A ContextItemId is a unique identifier for a ContextItem.", + "type": "object", + "properties": { + "provider_title": { + "title": "Provider Title", + "type": "string" + }, + "item_id": { + "title": "Item Id", + "type": "string" + } + }, + "required": [ + "provider_title", + "item_id" + ] + }, + "ContextItemDescription": { + "title": "ContextItemDescription", + "description": "A ContextItemDescription is a description of a ContextItem that is displayed to the user when they type '@'.\n\nThe id can be used to retrieve the ContextItem from the ContextManager.", + "type": "object", + "properties": { + "name": { + "title": "Name", + "type": "string" + }, + "description": { + "title": "Description", + "type": "string" + }, + "id": { + "$ref": "#/definitions/ContextItemId" + } + }, + "required": [ + "name", + "description", + "id" + ] + }, + "ContextItem": { + "title": "ContextItem", + "description": "A ContextItem is a single item that is stored in the ContextManager.", + "type": "object", + "properties": { + "description": { + "$ref": "#/definitions/ContextItemDescription" + }, + "content": { + "title": "Content", + "type": "string" + }, + "editing": { + "title": "Editing", + "default": false, + "type": "boolean" + }, + "editable": { + "title": "Editable", + "default": false, + "type": "boolean" + } + }, + "required": [ + "description", + "content" + ] + }, + "ContextProvider": { + "title": "ContextProvider", + "description": "The ContextProvider class is a plugin that lets you provide new information to the LLM by typing '@'.\nWhen you type '@', the context provider will be asked to populate a list of options.\nThese options will be updated on each keystroke.\nWhen you hit enter on an option, the context provider will add that item to the autopilot's list of context (which is all stored in the ContextManager object).", + "type": "object", + "properties": { + "title": { + "title": "Title", + "description": "The title of the ContextProvider. This is what must be typed in the input to trigger the ContextProvider.", + "type": "string" + }, + "ide": { + "title": "Ide" + }, + "display_title": { + "title": "Display Title", + "description": "The display title of the ContextProvider shown in the dropdown menu", + "type": "string" + }, + "description": { + "title": "Description", + "description": "A description of the ContextProvider displayed in the dropdown menu", + "type": "string" + }, + "dynamic": { + "title": "Dynamic", + "description": "Indicates whether the ContextProvider is dynamic", + "type": "boolean" + }, + "requires_query": { + "title": "Requires Query", + "description": "Indicates whether the ContextProvider requires a query. For example, the SearchContextProvider requires you to type '@search '. This will change the behavior of the UI so that it can indicate the expectation for a query.", + "default": false, + "type": "boolean" + }, + "selected_items": { + "title": "Selected Items", + "description": "List of selected items in the ContextProvider", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/ContextItem" + } + } + }, + "required": [ + "title", + "display_title", + "description", + "dynamic" + ] + }, + "RetrievalSettings": { + "title": "RetrievalSettings", + "type": "object", + "properties": { + "n_retrieve": { + "title": "N Retrieve", + "description": "Number of results to initially retrieve from vector database", + "default": 50, + "type": "integer" + }, + "n_final": { + "title": "N Final", + "description": "Final number of results to use after re-ranking", + "default": 10, + "type": "integer" + }, + "use_reranking": { + "title": "Use Reranking", + "description": "Whether to use re-ranking, which will allow initial selection of n_retrieve results, then will use an LLM to select the top n_final results", + "default": true, + "type": "boolean" + }, + "rerank_group_size": { + "title": "Rerank Group Size", + "description": "Number of results to group together when re-ranking. Each group will be processed in parallel.", + "default": 5, + "type": "integer" + }, + "ignore_files": { + "title": "Ignore Files", + "description": "Files to ignore when indexing the codebase. You can use glob patterns, such as **/*.py. This is useful for directories that contain generated code, or other directories that are not relevant to the codebase.", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "openai_api_key": { + "title": "Openai Api Key", + "description": "OpenAI API key", + "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "OpenAI API base URL", + "type": "string" + }, + "api_type": { + "title": "Api Type", + "description": "OpenAI API type", + "type": "string" + }, + "api_version": { + "title": "Api Version", + "description": "OpenAI API version", + "type": "string" + }, + "organization_id": { + "title": "Organization Id", + "description": "OpenAI organization ID", + "type": "string" + } + } + }, + "continuedev__core__config__config__ContinueConfig": { + "title": "ContinueConfig", + "description": "Continue can be deeply customized by editing the `ContinueConfig` object in `~/.continue/config.py` (`%userprofile%\\.continue\\config.py` for Windows) on your machine. This class is instantiated from the config file for every new session.", + "type": "object", + "properties": { + "steps_on_startup": { + "title": "Steps On Startup", + "description": "Steps that will be automatically run at the beginning of a new session", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/Step" + } + }, + "disallowed_steps": { + "title": "Disallowed Steps", + "description": "Steps that are not allowed to be run, and will be skipped if attempted", + "default": [], + "type": "array", + "items": { + "type": "string" + } + }, + "allow_anonymous_telemetry": { + "title": "Allow Anonymous Telemetry", + "description": "If this field is set to True, we will collect anonymous telemetry as described in the documentation page on telemetry. If set to False, we will not collect any data.", + "default": true, + "type": "boolean" + }, + "models": { + "title": "Models", + "description": "Configuration for the models used by Continue. Read more about how to configure models in the documentation.", + "default": { + "default": { + "title": null, + "model": "gpt-4", + "system_message": null, + "context_length": 8192, + "completion_options": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "request_options": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "prompt_templates": {}, + "template_messages": null, + "api_key": null, + "api_base": null, + "llm": null, + "class_name": "OpenAIFreeTrial" + }, + "summarize": { + "title": null, + "model": "gpt-3.5-turbo", + "system_message": null, + "context_length": 4096, + "completion_options": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "request_options": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "prompt_templates": {}, + "template_messages": null, + "api_key": null, + "api_base": null, + "llm": null, + "class_name": "OpenAIFreeTrial" + }, + "edit": { + "title": null, + "model": "gpt-4", + "system_message": null, + "context_length": 8192, + "completion_options": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "request_options": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "prompt_templates": {}, + "template_messages": null, + "api_key": null, + "api_base": null, + "llm": null, + "class_name": "OpenAIFreeTrial" + }, + "chat": { + "title": null, + "model": "gpt-4", + "system_message": null, + "context_length": 8192, + "completion_options": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "request_options": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "prompt_templates": {}, + "template_messages": null, + "api_key": null, + "api_base": null, + "llm": null, + "class_name": "OpenAIFreeTrial" + }, + "saved": [], + "temperature": null, + "system_message": null + }, + "allOf": [ + { + "$ref": "#/definitions/Models" + } + ] + }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] + }, + "custom_commands": { + "title": "Custom Commands", + "description": "An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", + "default": [ + { + "name": "test", + "prompt": "Write a comprehensive set of unit tests for the selected code. It should setup, run tests that check for correctness including important edge cases, and teardown. Ensure that the tests are complete and sophisticated. Give the tests just as chat output, don't edit any file.", + "description": "This is an example custom command. Use /config to edit it and create more" + } + ], + "type": "array", + "items": { + "$ref": "#/definitions/CustomCommand" + } + }, + "slash_commands": { + "title": "Slash Commands", + "description": "An array of slash commands that let you map custom Steps to a shortcut.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/SlashCommand" + } + }, + "on_traceback": { + "title": "On Traceback", + "description": "The step that will be run when a traceback is detected (when you use the shortcut cmd+shift+R)", + "allOf": [ + { + "$ref": "#/definitions/Step" + } + ] + }, + "policy_override": { + "title": "Policy Override", + "description": "A Policy object that can be used to override the default behavior of Continue, for example in order to build custom agents that take multiple steps at a time.", + "allOf": [ + { + "$ref": "#/definitions/Policy" + } + ] + }, + "context_providers": { + "title": "Context Providers", + "description": "A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/ContextProvider" + } + }, + "user_token": { + "title": "User Token", + "description": "An optional token to identify the user.", + "type": "string" + }, + "data_server_url": { + "title": "Data Server Url", + "description": "The URL of the server where development data is sent. No data is sent unless a valid user token is provided.", + "default": "https://us-west1-autodebug.cloudfunctions.net", + "type": "string" + }, + "disable_summaries": { + "title": "Disable Summaries", + "description": "If set to `True`, Continue will not generate summaries for each Step. This can be useful if you want to save on compute.", + "default": false, + "type": "boolean" + }, + "disable_indexing": { + "title": "Disable Indexing", + "description": "If set to `True`, Continue will not index the codebase. This is mainly used for debugging purposes.", + "default": false, + "type": "boolean" + }, + "retrieval_settings": { + "title": "Retrieval Settings", + "description": "Settings for the retrieval system. Read more about the retrieval system in the documentation.", + "default": { + "n_retrieve": 50, + "n_final": 10, + "use_reranking": true, + "rerank_group_size": 5, + "ignore_files": [], + "openai_api_key": null, + "api_base": null, + "api_type": null, + "api_version": null, + "organization_id": null + }, + "allOf": [ + { + "$ref": "#/definitions/RetrievalSettings" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/schema/json/LLM.json b/schema/json/LLM.json index be340014d..34bcaaf04 100644 --- a/schema/json/LLM.json +++ b/schema/json/LLM.json @@ -2,6 +2,86 @@ "title": "LLM", "$ref": "#/definitions/continuedev__libs__llm__base__LLM", "definitions": { + "BaseCompletionOptions": { + "title": "BaseCompletionOptions", + "type": "object", + "properties": { + "temperature": { + "title": "Temperature", + "description": "The temperature of the completion.", + "type": "number" + }, + "top_p": { + "title": "Top P", + "description": "The top_p of the completion.", + "type": "number" + }, + "top_k": { + "title": "Top K", + "description": "The top_k of the completion.", + "type": "integer" + }, + "presence_penalty": { + "title": "Presence Penalty", + "description": "The presence penalty Aof the completion.", + "type": "number" + }, + "frequency_penalty": { + "title": "Frequency Penalty", + "description": "The frequency penalty of the completion.", + "type": "number" + }, + "stop": { + "title": "Stop", + "description": "The stop tokens of the completion.", + "type": "array", + "items": { + "type": "string" + } + }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + } + } + }, + "RequestOptions": { + "title": "RequestOptions", + "type": "object", + "properties": { + "timeout": { + "title": "Timeout", + "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + "default": 300, + "type": "integer" + }, + "verify_ssl": { + "title": "Verify Ssl", + "description": "Whether to verify SSL certificates for requests.", + "type": "boolean" + }, + "ca_bundle_path": { + "title": "Ca Bundle Path", + "description": "Path to a custom CA bundle to use when making the HTTP request", + "type": "string" + }, + "proxy": { + "title": "Proxy", + "description": "Proxy URL to use when making the HTTP request", + "type": "string" + }, + "headers": { + "title": "Headers", + "description": "Headers to use when making the HTTP request", + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "continuedev__libs__llm__base__LLM": { "title": "LLM", "type": "object", @@ -32,73 +112,39 @@ "default": 2048, "type": "integer" }, - "max_tokens": { - "title": "Max Tokens", - "description": "The maximum number of tokens to generate.", - "default": 600, - "type": "integer" + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] }, - "stop_tokens": { - "title": "Stop Tokens", - "description": "Tokens that will stop the completion.", - "type": "array", - "items": { - "type": "string" - } - }, - "temperature": { - "title": "Temperature", - "description": "The temperature of the completion.", - "type": "number" - }, - "top_p": { - "title": "Top P", - "description": "The top_p of the completion.", - "type": "number" - }, - "top_k": { - "title": "Top K", - "description": "The top_k of the completion.", - "type": "integer" - }, - "presence_penalty": { - "title": "Presence Penalty", - "description": "The presence penalty Aof the completion.", - "type": "number" - }, - "frequency_penalty": { - "title": "Frequency Penalty", - "description": "The frequency penalty of the completion.", - "type": "number" - }, - "timeout": { - "title": "Timeout", - "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", - "default": 300, - "type": "integer" - }, - "verify_ssl": { - "title": "Verify Ssl", - "description": "Whether to verify SSL certificates for requests.", - "type": "boolean" - }, - "ca_bundle_path": { - "title": "Ca Bundle Path", - "description": "Path to a custom CA bundle to use when making the HTTP request", - "type": "string" - }, - "proxy": { - "title": "Proxy", - "description": "Proxy URL to use when making the HTTP request", - "type": "string" - }, - "headers": { - "title": "Headers", - "description": "Headers to use when making the HTTP request", - "type": "object", - "additionalProperties": { - "type": "string" - } + "request_options": { + "title": "Request Options", + "description": "Options for the HTTP request to the LLM.", + "default": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "allOf": [ + { + "$ref": "#/definitions/RequestOptions" + } + ] }, "prompt_templates": { "title": "Prompt Templates", @@ -110,6 +156,11 @@ "title": "Api Key", "description": "The API key for the LLM provider.", "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "The base URL of the LLM API.", + "type": "string" } }, "required": [ diff --git a/schema/json/Models.json b/schema/json/Models.json index 26812b3df..0485bdefc 100644 --- a/schema/json/Models.json +++ b/schema/json/Models.json @@ -2,6 +2,86 @@ "title": "Models", "$ref": "#/definitions/continuedev__core__models__Models", "definitions": { + "BaseCompletionOptions": { + "title": "BaseCompletionOptions", + "type": "object", + "properties": { + "temperature": { + "title": "Temperature", + "description": "The temperature of the completion.", + "type": "number" + }, + "top_p": { + "title": "Top P", + "description": "The top_p of the completion.", + "type": "number" + }, + "top_k": { + "title": "Top K", + "description": "The top_k of the completion.", + "type": "integer" + }, + "presence_penalty": { + "title": "Presence Penalty", + "description": "The presence penalty Aof the completion.", + "type": "number" + }, + "frequency_penalty": { + "title": "Frequency Penalty", + "description": "The frequency penalty of the completion.", + "type": "number" + }, + "stop": { + "title": "Stop", + "description": "The stop tokens of the completion.", + "type": "array", + "items": { + "type": "string" + } + }, + "max_tokens": { + "title": "Max Tokens", + "description": "The maximum number of tokens to generate.", + "default": 600, + "type": "integer" + } + } + }, + "RequestOptions": { + "title": "RequestOptions", + "type": "object", + "properties": { + "timeout": { + "title": "Timeout", + "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", + "default": 300, + "type": "integer" + }, + "verify_ssl": { + "title": "Verify Ssl", + "description": "Whether to verify SSL certificates for requests.", + "type": "boolean" + }, + "ca_bundle_path": { + "title": "Ca Bundle Path", + "description": "Path to a custom CA bundle to use when making the HTTP request", + "type": "string" + }, + "proxy": { + "title": "Proxy", + "description": "Proxy URL to use when making the HTTP request", + "type": "string" + }, + "headers": { + "title": "Headers", + "description": "Headers to use when making the HTTP request", + "type": "object", + "additionalProperties": { + "type": "string" + } + } + } + }, "LLM": { "title": "LLM", "type": "object", @@ -32,73 +112,39 @@ "default": 2048, "type": "integer" }, - "max_tokens": { - "title": "Max Tokens", - "description": "The maximum number of tokens to generate.", - "default": 600, - "type": "integer" + "completion_options": { + "title": "Completion Options", + "description": "Options for the completion endpoint. Read more about the completion options in the documentation.", + "default": { + "temperature": null, + "top_p": null, + "top_k": null, + "presence_penalty": null, + "frequency_penalty": null, + "stop": null, + "max_tokens": 600 + }, + "allOf": [ + { + "$ref": "#/definitions/BaseCompletionOptions" + } + ] }, - "stop_tokens": { - "title": "Stop Tokens", - "description": "Tokens that will stop the completion.", - "type": "array", - "items": { - "type": "string" - } - }, - "temperature": { - "title": "Temperature", - "description": "The temperature of the completion.", - "type": "number" - }, - "top_p": { - "title": "Top P", - "description": "The top_p of the completion.", - "type": "number" - }, - "top_k": { - "title": "Top K", - "description": "The top_k of the completion.", - "type": "integer" - }, - "presence_penalty": { - "title": "Presence Penalty", - "description": "The presence penalty Aof the completion.", - "type": "number" - }, - "frequency_penalty": { - "title": "Frequency Penalty", - "description": "The frequency penalty of the completion.", - "type": "number" - }, - "timeout": { - "title": "Timeout", - "description": "Set the timeout for each request to the LLM. If you are running a local LLM that takes a while to respond, you might want to set this to avoid timeouts.", - "default": 300, - "type": "integer" - }, - "verify_ssl": { - "title": "Verify Ssl", - "description": "Whether to verify SSL certificates for requests.", - "type": "boolean" - }, - "ca_bundle_path": { - "title": "Ca Bundle Path", - "description": "Path to a custom CA bundle to use when making the HTTP request", - "type": "string" - }, - "proxy": { - "title": "Proxy", - "description": "Proxy URL to use when making the HTTP request", - "type": "string" - }, - "headers": { - "title": "Headers", - "description": "Headers to use when making the HTTP request", - "type": "object", - "additionalProperties": { - "type": "string" - } + "request_options": { + "title": "Request Options", + "description": "Options for the HTTP request to the LLM.", + "default": { + "timeout": 300, + "verify_ssl": null, + "ca_bundle_path": null, + "proxy": null, + "headers": null + }, + "allOf": [ + { + "$ref": "#/definitions/RequestOptions" + } + ] }, "prompt_templates": { "title": "Prompt Templates", @@ -110,6 +156,11 @@ "title": "Api Key", "description": "The API key for the LLM provider.", "type": "string" + }, + "api_base": { + "title": "Api Base", + "description": "The base URL of the LLM API.", + "type": "string" } }, "required": [ diff --git a/schema/json/SerializedContinueConfig.json b/schema/json/SerializedContinueConfig.json index 059755036..e8470b1a9 100644 --- a/schema/json/SerializedContinueConfig.json +++ b/schema/json/SerializedContinueConfig.json @@ -2,33 +2,6 @@ "title": "SerializedContinueConfig", "$ref": "#/definitions/continuedev__core__config__serialized_config__SerializedContinueConfig", "definitions": { - "StepWithParams": { - "title": "StepWithParams", - "type": "object", - "properties": { - "step": { - "title": "Step", - "enum": [ - "AnswerQuestionChroma", - "GenerateShellCommandStep", - "EditHighlightedCodeStep", - "ShareSessionStep", - "CommentCodeStep", - "ClearHistoryStep", - "StackOverflowStep" - ], - "type": "string" - }, - "params": { - "title": "Params", - "type": "object" - } - }, - "required": [ - "step", - "params" - ] - }, "BaseCompletionOptions": { "title": "BaseCompletionOptions", "type": "object", @@ -189,6 +162,11 @@ } ] }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, "request_options": { "title": "Request Options", "description": "Options for the HTTP request to the LLM.", @@ -254,7 +232,18 @@ "type": "string" }, "step": { - "title": "Step" + "title": "Step", + "enum": [ + "AnswerQuestionChroma", + "GenerateShellCommandStep", + "EditHighlightedCodeStep", + "ShareSessionStep", + "CommentCodeStep", + "ClearHistoryStep", + "StackOverflowStep", + "OpenConfigStep" + ], + "type": "string" }, "params": { "title": "Params", @@ -291,6 +280,33 @@ "description" ] }, + "ContextProviderWithParams": { + "title": "ContextProviderWithParams", + "type": "object", + "properties": { + "name": { + "title": "Name", + "enum": [ + "diff", + "github", + "terminal", + "open", + "google", + "search", + "url" + ], + "type": "string" + }, + "params": { + "title": "Params", + "default": {}, + "type": "object" + } + }, + "required": [ + "name" + ] + }, "RetrievalSettings": { "title": "RetrievalSettings", "type": "object", @@ -359,15 +375,6 @@ "title": "SerializedContinueConfig", "type": "object", "properties": { - "steps_on_startup": { - "title": "Steps On Startup", - "description": "Steps that will be automatically run at the beginning of a new session", - "default": [], - "type": "array", - "items": { - "$ref": "#/definitions/StepWithParams" - } - }, "disallowed_steps": { "title": "Disallowed Steps", "description": "Steps that are not allowed to be run, and will be skipped if attempted", @@ -413,6 +420,11 @@ } ] }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, "completion_options": { "title": "Completion Options", "description": "Default options for completion. These will be overriden by any options set for a specific model.", @@ -461,7 +473,7 @@ "default": [], "type": "array", "items": { - "$ref": "#/definitions/StepWithParams" + "$ref": "#/definitions/ContextProviderWithParams" } }, "user_token": { diff --git a/server/continuedev/__main__.py b/server/continuedev/__main__.py index 7d5714de3..17c471cc9 100644 --- a/server/continuedev/__main__.py +++ b/server/continuedev/__main__.py @@ -1,23 +1,22 @@ import asyncio import os from typing import Optional -from tqdm import tqdm -from .core.config.serialized_config import ContinueConfig -from .headless.headless_ide import LocalIdeProtocol -from .libs.index.build_index import build_index -from .libs.util.ext_to_lang import ext_to_lang -from .libs.index.chunkers.chunk import Chunk +import typer from dotenv import load_dotenv from rich.console import Console from rich.markdown import Markdown - -import typer +from tqdm import tqdm from . import run -from .server.main import run_server +from .core.config.config import ContinueConfig from .headless import get_headless_autopilot +from .headless.headless_ide import LocalIdeProtocol +from .libs.index.build_index import build_index +from .libs.index.chunkers.chunk import Chunk from .libs.index.pipelines.main import main_retrieval_pipeline +from .libs.util.ext_to_lang import ext_to_lang +from .server.main import run_server load_dotenv() app = typer.Typer(invoke_without_command=True) diff --git a/server/continuedev/core/autopilot.py b/server/continuedev/core/autopilot.py index 8bc15fb57..1e6657117 100644 --- a/server/continuedev/core/autopilot.py +++ b/server/continuedev/core/autopilot.py @@ -1,3 +1,4 @@ +import inspect import json import os import traceback @@ -6,26 +7,24 @@ from typing import Dict, List, Optional from aiohttp import ClientPayloadError from openai import error as openai_errors -import inspect -from ..libs.util.strings import remove_quotes_and_escapes from ..libs.llm.prompts.chat import template_alpaca_messages -from .context import ContextManager from ..libs.util.devdata import dev_data_logger from ..libs.util.logging import logger from ..libs.util.paths import getSavedContextGroupsPath +from ..libs.util.strings import remove_quotes_and_escapes from ..libs.util.telemetry import posthog_logger from ..libs.util.traceback.traceback_parsers import ( get_javascript_traceback, get_python_traceback, ) from ..models.filesystem import RangeInFileWithContents -from ..server.protocols.gui_protocol import AbstractGUIProtocolServer -from ..server.protocols.ide_protocol import AbstractIdeProtocolServer from ..plugins.policies.default import DefaultPolicy from ..plugins.steps.on_traceback import DefaultOnTracebackStep - -from .config.serialized_config import ContinueConfig +from ..server.protocols.gui_protocol import AbstractGUIProtocolServer +from ..server.protocols.ide_protocol import AbstractIdeProtocolServer +from .config.config import ContinueConfig +from .context import ContextManager from .main import ( AutopilotGenerator, AutopilotGeneratorOutput, @@ -33,14 +32,14 @@ from .main import ( ContextItem, ContinueCustomException, ContinueError, + DeltaStep, Policy, SessionState, + SessionUpdate, SetStep, Step, - UpdateStep, - SessionUpdate, StepDescription, - DeltaStep, + UpdateStep, ) from .observation import Observation from .sdk import ContinueSDK diff --git a/server/continuedev/core/config/config.py b/server/continuedev/core/config/config.py index 9b08972e9..a84d04401 100644 --- a/server/continuedev/core/config/config.py +++ b/server/continuedev/core/config/config.py @@ -1,6 +1,7 @@ -from typing import Dict, List, Optional, Type +import json +from typing import List, Optional -from pydantic import BaseModel, Field, validator +from pydantic import BaseModel, Field from ...libs.llm.base import BaseCompletionOptions from ...libs.llm.openai_free_trial import OpenAIFreeTrial @@ -18,6 +19,7 @@ from ..models import Models from .context import CONTEXT_PROVIDER_NAME_TO_CLASS from .serialized_config import ( CustomCommand, + ModelDescription, RetrievalSettings, SerializedContinueConfig, SlashCommand, @@ -48,6 +50,10 @@ class ContinueConfig(BaseModel): ), description="Configuration for the models used by Continue. Read more about how to configure models in the documentation.", ) + system_message: Optional[str] = Field( + default=None, + description="A system message that will always be followed by the LLM", + ) completion_options: BaseCompletionOptions = Field( default=BaseCompletionOptions(), description="Options for the completion endpoint. Read more about the completion options in the documentation.", @@ -98,10 +104,6 @@ class ContinueConfig(BaseModel): description="Settings for the retrieval system. Read more about the retrieval system in the documentation.", ) - @validator("temperature", pre=True) - def temperature_validator(cls, v): - return max(0.0, min(1.0, v)) - @staticmethod def from_serialized_config(config: SerializedContinueConfig) -> "ContinueConfig": context_providers = [ @@ -112,6 +114,7 @@ class ContinueConfig(BaseModel): disallowed_steps=config.disallowed_steps, allow_anonymous_telemetry=config.allow_anonymous_telemetry, models=Models.from_serialized_config(config), + system_message=config.system_message, completion_options=config.completion_options, custom_commands=config.custom_commands, slash_commands=config.slash_commands, @@ -125,6 +128,12 @@ class ContinueConfig(BaseModel): @staticmethod def from_filepath(filepath: str, retry: bool = True) -> "ContinueConfig": + if filepath.endswith(".json"): + serialized_config = json.load(open(filepath)) + return ContinueConfig.from_serialized_config( + SerializedContinueConfig(**serialized_config) + ) + # Use importlib to load the config file config.py at the given path try: import importlib.util @@ -144,7 +153,7 @@ class ContinueConfig(BaseModel): @staticmethod def load_default() -> "ContinueConfig": - path = getConfigFilePath() + path = getConfigFilePath(json=True) return ContinueConfig.from_filepath(path) def get_slash_command_descriptions(self) -> List[SlashCommandDescription]: diff --git a/server/continuedev/core/config/context.py b/server/continuedev/core/config/context.py index 9f76f4a50..df169ac23 100644 --- a/server/continuedev/core/config/context.py +++ b/server/continuedev/core/config/context.py @@ -1,3 +1,5 @@ +from typing import Literal + from ...plugins.context_providers.diff import DiffContextProvider from ...plugins.context_providers.github import GitHubIssuesContextProvider from ...plugins.context_providers.google import GoogleContextProvider @@ -6,6 +8,16 @@ from ...plugins.context_providers.search import SearchContextProvider from ...plugins.context_providers.terminal import TerminalContextProvider from ...plugins.context_providers.url import URLContextProvider +ContextProviderName = Literal[ + "diff", + "github", + "terminal", + "open", + "google", + "search", + "url", +] + CONTEXT_PROVIDER_NAME_TO_CLASS = { "diff": DiffContextProvider, "github": GitHubIssuesContextProvider, diff --git a/server/continuedev/core/config/serialized_config.py b/server/continuedev/core/config/serialized_config.py index e9c817dd9..70c58d97b 100644 --- a/server/continuedev/core/config/serialized_config.py +++ b/server/continuedev/core/config/serialized_config.py @@ -1,32 +1,29 @@ from typing import Any, Dict, List, Optional, Type -from anthropic import RequestOptions from pydantic import BaseModel, Field -from ...models.llm import BaseCompletionOptions +from ...models.llm import BaseCompletionOptions, RequestOptions from ..main import SlashCommandDescription, Step +from .context import ContextProviderName from .shared import ModelProvider, StepName, TemplateType class StepWithParams(BaseModel): name: StepName - params: Dict[str, Any] + params: Dict[str, Any] = {} + + +class ContextProviderWithParams(BaseModel): + name: ContextProviderName + params: Dict[str, Any] = {} class SlashCommand(BaseModel): name: str description: str - step: Type[Step] + step: StepName params: Optional[Dict] = {} - def dict(self, *args, **kwargs): - return { - "name": self.name, - "description": self.description, - "params": self.params, - "step": self.step.__name__, - } - def slash_command_description(self) -> SlashCommandDescription: return SlashCommandDescription( name=self.name, @@ -159,6 +156,10 @@ class SerializedContinueConfig(BaseModel): default=ModelRoles(default="GPT-4 (trial)"), description="Roles for models. Each entry should be the title of a model in the models array.", ) + system_message: Optional[str] = Field( + default=None, + description="A system message that will always be followed by the LLM", + ) completion_options: BaseCompletionOptions = Field( default=BaseCompletionOptions(), description="Default options for completion. These will be overriden by any options set for a specific model.", @@ -177,7 +178,7 @@ class SerializedContinueConfig(BaseModel): ], description="An array of custom commands that allow you to reuse prompts. Each has name, description, and prompt properties. When you enter / in the text input, it will act as a shortcut to the prompt.", ) - context_providers: List[StepWithParams] = Field( + context_providers: List[ContextProviderWithParams] = Field( default=[], description="A list of ContextProvider objects that can be used to provide context to the LLM by typing '@'. Read more about ContextProviders in the documentation.", ) diff --git a/server/continuedev/core/config/shared.py b/server/continuedev/core/config/shared.py index c5d4888db..b4d6fba8c 100644 --- a/server/continuedev/core/config/shared.py +++ b/server/continuedev/core/config/shared.py @@ -22,8 +22,12 @@ StepName = Literal[ "CommentCodeStep", "ClearHistoryStep", "StackOverflowStep", + "OpenConfigStep", + "GenerateShellCommandStep", ] +ContextProviderName = Literal["diff", "github"] + TemplateType = Literal["llama2", "alpaca", "zephyr", "phind", "anthropic", "chatml"] diff --git a/server/continuedev/core/models.py b/server/continuedev/core/models.py index 78daf9322..0f8be5705 100644 --- a/server/continuedev/core/models.py +++ b/server/continuedev/core/models.py @@ -109,12 +109,13 @@ class Models(BaseModel): completion_options = config.completion_options.dict() completion_options.update(model.completion_options.dict(exclude_none=True)) model_class.system_message = model.system_message - return LLM( + return model_class( + title=model.title, api_key=model.api_key, completion_options=cast(BaseCompletionOptions, completion_options), request_options=model.request_options, system_message=model.system_message, - api_base=model.api_base, # TODO + api_base=model.api_base, model=model.model, template_messages=autodetect_template_function(model.model), prompt_templates=autodetect_prompt_templates(model.model), @@ -145,7 +146,12 @@ class Models(BaseModel): for model in self.all_models: model.set_main_config_params(system_msg, temperature) - async def start(self, unique_id: str, system_message: str, temperature: float): + async def start( + self, + unique_id: str, + system_message: Optional[str], + temperature: Optional[float], + ): """Start each of the LLMs, or fall back to default""" for role in ALL_MODEL_ROLES: model: LLM = getattr(self, role) diff --git a/server/continuedev/core/sdk.py b/server/continuedev/core/sdk.py index 62261eafc..62b14ca01 100644 --- a/server/continuedev/core/sdk.py +++ b/server/continuedev/core/sdk.py @@ -2,9 +2,6 @@ import asyncio import os from typing import Coroutine, List, Optional, Union -from ..plugins.context_providers.highlighted_code import HighlightedCodeContextProvider - - from ..models.filesystem import RangeInFile from ..models.filesystem_edit import ( AddDirectory, @@ -15,9 +12,10 @@ from ..models.filesystem_edit import ( FileSystemEdit, ) from ..models.main import Range -from ..server.protocols.ide_protocol import AbstractIdeProtocolServer +from ..plugins.context_providers.highlighted_code import HighlightedCodeContextProvider from ..server.protocols.gui_protocol import AbstractGUIProtocolServer -from .config.serialized_config import ContinueConfig +from ..server.protocols.ide_protocol import AbstractIdeProtocolServer +from .config.config import ContinueConfig from .lsp import ContinueLSPClient from .main import ( ChatMessage, diff --git a/server/continuedev/core/steps.py b/server/continuedev/core/steps.py index efb7e96bc..13dee44e2 100644 --- a/server/continuedev/core/steps.py +++ b/server/continuedev/core/steps.py @@ -1,11 +1,11 @@ # These steps are depended upon by ContinueSDK import difflib import subprocess -from textwrap import dedent import time +from textwrap import dedent from typing import Coroutine, List, Optional, Union -from ..libs.llm.base import LLM, PromptTemplate +from ..libs.llm.base import LLM from ..libs.llm.openai_free_trial import OpenAIFreeTrial from ..libs.util.count_tokens import DEFAULT_MAX_TOKENS from ..libs.util.devdata import dev_data_logger @@ -16,20 +16,8 @@ from ..libs.util.strings import ( from ..libs.util.telemetry import posthog_logger from ..libs.util.templating import render_prompt_template from ..models.filesystem import FileSystem, RangeInFile, RangeInFileWithContents -from ..models.filesystem_edit import ( - EditDiff, - FileEditWithFullContents, - FileSystemEdit, -) - -from .main import ( - ChatMessage, - ContinueCustomException, - DeltaStep, - SessionUpdate, - SetStep, - Step, -) +from ..models.filesystem_edit import EditDiff, FileEditWithFullContents, FileSystemEdit +from .main import ChatMessage, ContinueCustomException, SessionUpdate, SetStep, Step from .observation import TextObservation, UserInputObservation @@ -626,7 +614,7 @@ Please output the code to be inserted at the cursor in order to fulfill the user async def gen(): async for chunk in model_to_use.stream_chat( messages, - temperature=sdk.config.temperature, + temperature=sdk.config.completion_options.temperature, max_tokens=min(max_tokens, model_to_use.context_length // 2), ): if "content" in chunk: diff --git a/server/continuedev/headless/__init__.py b/server/continuedev/headless/__init__.py index b6df59f51..5479a81f9 100644 --- a/server/continuedev/headless/__init__.py +++ b/server/continuedev/headless/__init__.py @@ -1,12 +1,11 @@ from typing import List, Optional, Union -from ..server.protocols.cli_gui import CommandLineGUI - +from ..core.autopilot import Autopilot +from ..core.config.config import ContinueConfig from ..core.context import ContextManager, ContextProvider from ..core.main import SessionState -from ..core.autopilot import Autopilot +from ..server.protocols.cli_gui import CommandLineGUI from .headless_ide import LocalIdeProtocol -from ..core.config.serialized_config import ContinueConfig async def get_headless_autopilot( @@ -24,7 +23,9 @@ async def get_headless_autopilot( ide = LocalIdeProtocol(workspace_directory=directory) context_manager = ContextManager() # await context_manager.start(context_providers=context_providers, ide=ide) - await config.models.start("HEADLESS", config.system_message, config.temperature) + await config.models.start( + "HEADLESS", config.system_message, config.completion_options.temperature + ) return Autopilot( session_state=state, diff --git a/server/continuedev/libs/index/build_index.py b/server/continuedev/libs/index/build_index.py index 5d38939a3..c4b25444e 100644 --- a/server/continuedev/libs/index/build_index.py +++ b/server/continuedev/libs/index/build_index.py @@ -1,12 +1,13 @@ import asyncio from typing import AsyncGenerator -from ...core.config.serialized_config import ContinueConfig -from ...server.protocols.ide_protocol import AbstractIdeProtocolServer + +from ...core.config.config import ContinueConfig from ...libs.index.chunkers.chunk_directory import ( stream_chunk_directory, ) -from ...libs.index.indices.meilisearch_index import MeilisearchCodebaseIndex from ...libs.index.indices.chroma_index import MAX_CHUNK_SIZE, ChromaCodebaseIndex +from ...libs.index.indices.meilisearch_index import MeilisearchCodebaseIndex +from ...server.protocols.ide_protocol import AbstractIdeProtocolServer async def build_index( diff --git a/server/continuedev/libs/llm/ggml.py b/server/continuedev/libs/llm/ggml.py index 025096250..ce42a2a97 100644 --- a/server/continuedev/libs/llm/ggml.py +++ b/server/continuedev/libs/llm/ggml.py @@ -1,7 +1,7 @@ import json from typing import Any, Callable, Coroutine, Dict, List, Literal, Optional -from pydantic import Field +from pydantic import Field, validator from ...core.main import ChatMessage, ContinueCustomException from ..util.logging import logger @@ -31,10 +31,15 @@ class GGML(LLM): ``` """ - api_base: str = Field( + api_base: Optional[str] = Field( "http://localhost:8000", description="URL of the OpenAI-compatible server where the model is being served", ) + + @validator("api_base", pre=True, always=True) + def set_api_base(cls, api_base): + return api_base or "http://localhost:8000" + model: str = Field( "ggml", description="The name of the model to use (optional for the GGML class)" ) diff --git a/server/continuedev/libs/llm/hf_inference_api.py b/server/continuedev/libs/llm/hf_inference_api.py index 09b6a5068..96a733dde 100644 --- a/server/continuedev/libs/llm/hf_inference_api.py +++ b/server/continuedev/libs/llm/hf_inference_api.py @@ -1,4 +1,4 @@ -from typing import Callable, Dict, List, Union +from typing import Callable, Dict, List, Optional, Union from huggingface_hub import InferenceClient from pydantic import Field @@ -32,7 +32,7 @@ class HuggingFaceInferenceAPI(LLM): description="The name of the model to use (optional for the HuggingFaceInferenceAPI class)", ) api_key: str = Field(..., description="Your Hugging Face API token") - api_base: str = Field( + api_base: Optional[str] = Field( None, description="Your Hugging Face Inference API endpoint URL" ) diff --git a/server/continuedev/libs/llm/hf_tgi.py b/server/continuedev/libs/llm/hf_tgi.py index 27fd86237..a2f6ca3ce 100644 --- a/server/continuedev/libs/llm/hf_tgi.py +++ b/server/continuedev/libs/llm/hf_tgi.py @@ -1,10 +1,10 @@ import json -from typing import Any, Callable, List -from ..util.count_tokens import DEFAULT_MAX_TOKENS +from typing import Any, Callable, List, Optional -from pydantic import Field +from pydantic import Field, validator from ...core.main import ChatMessage +from ..util.count_tokens import DEFAULT_MAX_TOKENS from .base import LLM, CompletionOptions from .prompts.chat import llama2_template_messages from .prompts.edit import codellama_edit_prompt @@ -12,7 +12,13 @@ from .prompts.edit import codellama_edit_prompt class HuggingFaceTGI(LLM): model: str = "huggingface-tgi" - api_base: str = Field("http://localhost:8080", description="URL of your TGI server") + api_base: Optional[str] = Field( + "http://localhost:8080", description="URL of your TGI server" + ) + + @validator("api_base", pre=True, always=True) + def set_api_base(cls, api_base): + return api_base or "http://localhost:8080" class Config: arbitrary_types_allowed = True diff --git a/server/continuedev/libs/llm/llamacpp.py b/server/continuedev/libs/llm/llamacpp.py index 5fc7405b1..b1bd042dd 100644 --- a/server/continuedev/libs/llm/llamacpp.py +++ b/server/continuedev/libs/llm/llamacpp.py @@ -1,7 +1,7 @@ import json -from typing import Any, Callable, Dict +from typing import Any, Callable, Dict, Optional -from pydantic import Field +from pydantic import Field, validator from .base import LLM from .prompts.chat import llama2_template_messages @@ -33,7 +33,13 @@ class LlamaCpp(LLM): """ model: str = "llamacpp" - api_base: str = Field("http://localhost:8080", description="URL of the server") + api_base: Optional[str] = Field( + "http://localhost:8080", description="URL of the server" + ) + + @validator("api_base", pre=True, always=True) + def set_api_base(cls, api_base): + return api_base or "http://localhost:8080" llama_cpp_args: Dict[str, Any] = Field( {"stop": ["[INST]"]}, diff --git a/server/continuedev/libs/llm/ollama.py b/server/continuedev/libs/llm/ollama.py index a7d4d1038..76b2bec83 100644 --- a/server/continuedev/libs/llm/ollama.py +++ b/server/continuedev/libs/llm/ollama.py @@ -1,6 +1,7 @@ import json -from typing import Any, Callable, Dict -from pydantic import Field +from typing import Any, Callable, Dict, Optional + +from pydantic import Field, validator from ...core.main import ContinueCustomException from ..util.logging import logger @@ -24,10 +25,14 @@ class Ollama(LLM): """ model: str = "llama2" - api_base: str = Field( + api_base: Optional[str] = Field( "http://localhost:11434", description="URL of the Ollama server" ) + @validator("api_base", pre=True, always=True) + def set_api_base(cls, api_base): + return api_base or "http://localhost:11434" + class Config: arbitrary_types_allowed = True diff --git a/server/continuedev/libs/llm/openai.py b/server/continuedev/libs/llm/openai.py index 1fcf13af9..04896a854 100644 --- a/server/continuedev/libs/llm/openai.py +++ b/server/continuedev/libs/llm/openai.py @@ -2,15 +2,15 @@ import asyncio from typing import List, Literal, Optional import certifi -from ..util.count_tokens import CONTEXT_LENGTH_FOR_MODEL -from ..util.logging import logger -from .prompts.chat import template_alpaca_messages import openai from openai.error import RateLimitError from pydantic import Field, validator from ...core.main import ChatMessage +from ..util.count_tokens import CONTEXT_LENGTH_FOR_MODEL +from ..util.logging import logger from .base import LLM +from .prompts.chat import template_alpaca_messages CHAT_MODELS = { "gpt-3.5-turbo", diff --git a/server/continuedev/libs/llm/text_gen_webui.py b/server/continuedev/libs/llm/text_gen_webui.py index 6c1acf521..2ddb94d33 100644 --- a/server/continuedev/libs/llm/text_gen_webui.py +++ b/server/continuedev/libs/llm/text_gen_webui.py @@ -1,5 +1,6 @@ import json -from typing import Any, List +from typing import Any, List, Optional + import websockets from pydantic import Field @@ -26,10 +27,10 @@ class TextGenWebUI(LLM): """ model: str = "text-gen-webui" - api_base: str = Field( + api_base: Optional[str] = Field( "http://localhost:5000", description="URL of your TextGenWebUI server" ) - streaming_url: str = Field( + streaming_url: Optional[str] = Field( "http://localhost:5005", description="URL of your TextGenWebUI streaming server (separate from main server URL)", ) diff --git a/server/continuedev/libs/llm/together.py b/server/continuedev/libs/llm/together.py index 1c462cae7..d1ea7652d 100644 --- a/server/continuedev/libs/llm/together.py +++ b/server/continuedev/libs/llm/together.py @@ -1,6 +1,7 @@ import json -from typing import Callable -from pydantic import Field +from typing import Callable, Optional + +from pydantic import Field, validator from ...core.main import ContinueCustomException from ..util.logging import logger @@ -32,11 +33,15 @@ class TogetherLLM(LLM): api_key: str = Field(..., description="Together API key") model: str = "togethercomputer/RedPajama-INCITE-7B-Instruct" - api_base: str = Field( + api_base: Optional[str] = Field( "https://api.together.xyz", description="The base URL for your Together API instance", ) + @validator("api_base", pre=True, always=True) + def set_api_base(cls, api_base): + return api_base or "https://api.together.xyz" + async def _stream_complete(self, prompt, options): args = self.collect_args(options) diff --git a/server/continuedev/libs/util/paths.py b/server/continuedev/libs/util/paths.py index b1fe41a79..e470d650e 100644 --- a/server/continuedev/libs/util/paths.py +++ b/server/continuedev/libs/util/paths.py @@ -1,5 +1,6 @@ import os import re +from contextlib import asynccontextmanager from typing import Optional from ..constants.default_config import default_config @@ -8,7 +9,6 @@ from ..constants.main import ( CONTINUE_SERVER_FOLDER, CONTINUE_SESSIONS_FOLDER, ) -from contextlib import asynccontextmanager def find_data_file(filename): @@ -152,8 +152,10 @@ def migrateConfigFile(existing: str) -> Optional[str]: return None -def getConfigFilePath() -> str: - path = os.path.join(getGlobalFolderPath(), "config.py") +def getConfigFilePath(json: bool = False) -> str: + path = os.path.join( + getGlobalFolderPath(), "config.py" if not json else "config.json" + ) os.makedirs(os.path.dirname(path), exist_ok=True) if not os.path.exists(path): diff --git a/server/continuedev/plugins/policies/commit.py b/server/continuedev/plugins/policies/commit.py index 0ff002c09..cd5676c58 100644 --- a/server/continuedev/plugins/policies/commit.py +++ b/server/continuedev/plugins/policies/commit.py @@ -12,7 +12,7 @@ from textwrap import dedent from typing import Literal -from ...core.config.serialized_config import ContinueConfig +from ...core.config.config import ContinueConfig from ...core.main import Policy, SessionState, Step from ...core.observation import TextObservation from ...core.sdk import ContinueSDK diff --git a/server/continuedev/plugins/policies/default.py b/server/continuedev/plugins/policies/default.py index 9a881b1cf..52c1c6969 100644 --- a/server/continuedev/plugins/policies/default.py +++ b/server/continuedev/plugins/policies/default.py @@ -1,20 +1,19 @@ from typing import Type, Union -from ..steps.stack_overflow import StackOverflowStep -from ...models.main import Position, PositionInFile -from ..steps.refactor import RefactorReferencesStep -from ..steps.clear_history import ClearHistoryStep -from ..steps.comment_code import CommentCodeStep -from ..steps.share_session import ShareSessionStep -from ..steps.codebase import AnswerQuestionChroma -from ...core.config.serialized_config import ContinueConfig +from ...core.config.config import ContinueConfig from ...core.main import Policy, SessionState, Step +from ...models.main import Position, PositionInFile from ..steps.chat import SimpleChatStep +from ..steps.clear_history import ClearHistoryStep +from ..steps.cmd import GenerateShellCommandStep +from ..steps.codebase import AnswerQuestionChroma +from ..steps.comment_code import CommentCodeStep from ..steps.custom_command import CustomCommandStep from ..steps.main import EditHighlightedCodeStep +from ..steps.refactor import RefactorReferencesStep +from ..steps.share_session import ShareSessionStep +from ..steps.stack_overflow import StackOverflowStep from ..steps.steps_on_startup import StepsOnStartupStep -from ..steps.cmd import GenerateShellCommandStep - # When importing with importlib from config.py, the classes do not pass isinstance checks. # Mapping them here is a workaround. diff --git a/server/continuedev/plugins/policies/headless.py b/server/continuedev/plugins/policies/headless.py index 3dcc4a007..f33884c63 100644 --- a/server/continuedev/plugins/policies/headless.py +++ b/server/continuedev/plugins/policies/headless.py @@ -1,4 +1,4 @@ -from ...core.config.serialized_config import ContinueConfig +from ...core.config.config import ContinueConfig from ...core.main import Policy, SessionState, Step from ...core.observation import TextObservation from ...core.steps import ShellCommandsStep diff --git a/server/continuedev/server/main.py b/server/continuedev/server/main.py index 60de242bb..950c9d459 100644 --- a/server/continuedev/server/main.py +++ b/server/continuedev/server/main.py @@ -4,23 +4,23 @@ import atexit from contextlib import asynccontextmanager from typing import List, Optional -from pydantic import BaseModel - -from ..core.main import ContextProviderDescription, SlashCommandDescription -from ..core.config.serialized_config import ContinueConfig -from ..libs.util.devdata import dev_data_logger - import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from pydantic import BaseModel +from ..core.config.config import ContinueConfig +from ..core.main import ContextProviderDescription, SlashCommandDescription from ..libs.util.create_async_task import create_async_task +from ..libs.util.devdata import dev_data_logger from ..libs.util.logging import logger -from .gui import router as gui_router, sio_gui_app -from .ide import router as ide_router, sio_ide_app -from .sessions import router as sessions_router -from .meilisearch_server import start_meilisearch, stop_meilisearch from .global_config import global_config +from .gui import router as gui_router +from .gui import sio_gui_app +from .ide import router as ide_router +from .ide import sio_ide_app +from .meilisearch_server import start_meilisearch, stop_meilisearch +from .sessions import router as sessions_router @asynccontextmanager diff --git a/server/continuedev/server/window_manager.py b/server/continuedev/server/window_manager.py index be7554990..57998d84e 100644 --- a/server/continuedev/server/window_manager.py +++ b/server/continuedev/server/window_manager.py @@ -1,27 +1,21 @@ import traceback from typing import Dict, Optional -from ..libs.util.create_async_task import create_async_task - -from ..libs.index.build_index import build_index - -from ..plugins.steps.on_traceback import DefaultOnTracebackStep - -from ..core.context import ContextManager - -from ..plugins.context_providers.highlighted_code import HighlightedCodeContextProvider - -from ..plugins.context_providers.file import FileContextProvider - -from ..core.main import SessionState from ..core.autopilot import Autopilot -from ..libs.util.paths import getConfigFilePath, getDiffsFolderPath -from ..core.config.serialized_config import ContinueConfig -from .protocols.ide import IdeProtocolServer, WindowInfo -from .protocols.gui import GUIProtocolServer -from ..libs.util.logging import logger -from ..libs.util.telemetry import posthog_logger +from ..core.config.config import ContinueConfig +from ..core.context import ContextManager +from ..core.main import SessionState +from ..libs.index.build_index import build_index +from ..libs.util.create_async_task import create_async_task from ..libs.util.devdata import dev_data_logger +from ..libs.util.logging import logger +from ..libs.util.paths import getConfigFilePath, getDiffsFolderPath +from ..libs.util.telemetry import posthog_logger +from ..plugins.context_providers.file import FileContextProvider +from ..plugins.context_providers.highlighted_code import HighlightedCodeContextProvider +from ..plugins.steps.on_traceback import DefaultOnTracebackStep +from .protocols.gui import GUIProtocolServer +from .protocols.ide import IdeProtocolServer, WindowInfo class Window: @@ -75,7 +69,7 @@ class Window: await self.config.models.start( self.ide.window_info.unique_id, self.config.system_message, - self.config.temperature, + self.config.completion_options.temperature, ) async def display_config_error(self): @@ -115,7 +109,7 @@ class Window: await self.config.models.start( self.ide.window_info.unique_id, self.config.system_message, - self.config.temperature, + self.config.completion_options.temperature, ) # When the config is loaded, setup posthog logger diff --git a/server/tests/step_test.py b/server/tests/step_test.py index 62a53b5fc..a4697ce1f 100644 --- a/server/tests/step_test.py +++ b/server/tests/step_test.py @@ -1,5 +1,5 @@ import pytest -from continuedev.core.config.serialized_config import ContinueConfig +from continuedev.core.config.config import ContinueConfig from continuedev.core.steps import UserInputStep from continuedev.headless import start_headless_session from continuedev.models.filesystem import Range, RangeInFileWithContents diff --git a/server/tests/util/config.py b/server/tests/util/config.py index 7a62b5d22..e32d6b987 100644 --- a/server/tests/util/config.py +++ b/server/tests/util/config.py @@ -1,4 +1,4 @@ -from continuedev.core.config.serialized_config import ContinueConfig +from continuedev.core.config.config import ContinueConfig from continuedev.core.models import Models from continuedev.libs.llm.openai_free_trial import OpenAIFreeTrial From 90fab6317ffb4a67e1cfc86d80fbb9b2443a6c15 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Tue, 14 Nov 2023 15:24:37 -0800 Subject: [PATCH 05/15] =?UTF-8?q?=F0=9F=94=A7=20writing=20back=20to=20conf?= =?UTF-8?q?ig.json?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ContinueConfig.json => config_schema.json} | 130 ++++++++++-- extensions/vscode/package.json | 2 +- gui/src/components/dialogs/FTCDialog.tsx | 3 +- .../AbstractContinueGUIClientProtocol.ts | 7 +- gui/src/hooks/ContinueGUIClientProtocol.ts | 5 +- gui/src/pages/modelconfig.tsx | 4 +- schema/json/ModelDescription.json | 194 ++++++++++++++++++ server/continuedev/core/config/config.py | 32 +-- .../core/config/serialized_config.py | 77 ++++++- server/continuedev/core/models.py | 29 +-- .../models/generate_json_schema.py | 4 +- server/continuedev/server/protocols/gui.py | 134 ++---------- 12 files changed, 422 insertions(+), 199 deletions(-) rename extensions/vscode/{SerializedContinueConfig.json => config_schema.json} (86%) create mode 100644 schema/json/ModelDescription.json diff --git a/extensions/vscode/SerializedContinueConfig.json b/extensions/vscode/config_schema.json similarity index 86% rename from extensions/vscode/SerializedContinueConfig.json rename to extensions/vscode/config_schema.json index 6afe2052b..2eee6d576 100644 --- a/extensions/vscode/SerializedContinueConfig.json +++ b/extensions/vscode/config_schema.json @@ -184,10 +184,105 @@ ] } }, - "required": [ - "title", - "provider", - "model" + "required": ["title", "provider", "model"], + "allOf": [ + { + "if": { + "properties": { + "provider": { + "enum": [ + "openai", + "anthropic", + "google-palm", + "huggingface-inference-api", + "replicate", + "together" + ] + } + } + }, + "then": { + "required": ["api_key"] + } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["huggingface-tgi"] + } + } + }, + "then": { + "required": ["api_base"] + } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["openai", "openai-aiohttp"] + } + } + }, + "then": { + "properties": { + "engine": { + "type": "string" + }, + "api_type": { + "type": "string" + }, + "api_version": { + "type": "string" + } + } + } + }, + { + "if": { + "properties": { + "api_type": { + "const": "azure" + } + } + }, + "then": { + "required": ["engine", "api_version", "api_base"] + } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["openai"] + } + } + }, + "then": { + "properties": { + "use_legacy_completions_endpoint": { + "type": "boolean" + } + } + } + }, + { + "if": { + "properties": { + "provider": { + "enum": ["text-gen-webui"] + } + } + }, + "then": { + "properties": { + "streaming_url": { + "type": "string" + } + } + } + } ] }, "ModelRoles": { @@ -215,9 +310,7 @@ "type": "string" } }, - "required": [ - "default" - ] + "required": ["default"] }, "SlashCommand": { "title": "SlashCommand", @@ -251,11 +344,7 @@ "type": "object" } }, - "required": [ - "name", - "description", - "step" - ] + "required": ["name", "description", "step"] }, "CustomCommand": { "title": "CustomCommand", @@ -274,11 +363,7 @@ "type": "string" } }, - "required": [ - "name", - "prompt", - "description" - ] + "required": ["name", "prompt", "description"] }, "ContextProviderWithParams": { "title": "ContextProviderWithParams", @@ -303,9 +388,7 @@ "type": "object" } }, - "required": [ - "name" - ] + "required": ["name"] }, "RetrievalSettings": { "title": "RetrievalSettings", @@ -420,6 +503,11 @@ } ] }, + "system_message": { + "title": "System Message", + "description": "A system message that will always be followed by the LLM", + "type": "string" + }, "completion_options": { "title": "Completion Options", "description": "Default options for completion. These will be overriden by any options set for a specific model.", @@ -518,4 +606,4 @@ } } } -} \ No newline at end of file +} diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 549fb2d9e..976cfe809 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -278,7 +278,7 @@ "jsonValidation": [ { "fileMatch": "config.json", - "url": "./SerializedContinueConfig.json" + "url": "./config_schema.json" } ] }, diff --git a/gui/src/components/dialogs/FTCDialog.tsx b/gui/src/components/dialogs/FTCDialog.tsx index 5fa2d4e64..48699fefd 100644 --- a/gui/src/components/dialogs/FTCDialog.tsx +++ b/gui/src/components/dialogs/FTCDialog.tsx @@ -55,10 +55,11 @@ function FTCDialog() {