🚧 migration from config.py to config.json

This commit is contained in:
Nate Sesti 2023-11-14 20:44:26 -08:00
parent c6a1312bf6
commit 28c9d52e34
23 changed files with 652 additions and 555 deletions

View file

@ -4,19 +4,18 @@ This is the Continue configuration file.
See https://continue.dev/docs/customization to for documentation of the available options.
"""
from continuedev.core.models import Models
from continuedev.core.config.serialized_config import (
from continuedev.core.config import (
ContinueConfig,
CustomCommand,
SlashCommand,
ContinueConfig,
)
from continuedev.core.models import Models
from continuedev.libs.llm import OpenAIFreeTrial
from continuedev.plugins.context_providers import (
DiffContextProvider,
GitHubIssuesContextProvider,
TerminalContextProvider,
URLContextProvider,
GitHubIssuesContextProvider,
)
from continuedev.plugins.steps import (
ClearHistoryStep,

View file

@ -1,7 +1,7 @@
import asyncio
from typing import Union
from .core.config.config import ContinueConfig
from .core.config import ContinueConfig
from .core.main import Step
# from .headless import start_headless_session

View file

@ -9,7 +9,7 @@ from rich.markdown import Markdown
from tqdm import tqdm
from . import run
from .core.config.config import ContinueConfig
from .core.config import ContinueConfig
from .headless import get_headless_autopilot
from .headless.headless_ide import LocalIdeProtocol
from .libs.index.build_index import build_index

View file

@ -23,7 +23,7 @@ from ..plugins.policies.default import DefaultPolicy
from ..plugins.steps.on_traceback import DefaultOnTracebackStep
from ..server.protocols.gui_protocol import AbstractGUIProtocolServer
from ..server.protocols.ide_protocol import AbstractIdeProtocolServer
from .config.config import ContinueConfig
from .config import ContinueConfig
from .context import ContextManager
from .main import (
AutopilotGenerator,

View file

@ -0,0 +1,588 @@
import json
import os
from contextlib import contextmanager
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field, validator
from ..libs.llm.base import LLM
from ..libs.llm.openai_free_trial import OpenAIFreeTrial
from ..libs.util.paths import (
convertConfigImports,
getConfigFilePath,
getGlobalFolderPath,
)
from ..libs.util.telemetry import posthog_logger
from ..models.llm import BaseCompletionOptions, RequestOptions
from .config_utils.context import (
CLASS_TO_CONTEXT_PROVIDER_NAME,
CONTEXT_PROVIDER_NAME_TO_CLASS,
ContextProviderName,
)
from .config_utils.shared import (
MODEL_CLASS_TO_MODEL_PROVIDER,
MODEL_PROVIDER_TO_MODEL_CLASS,
ModelProvider,
StepName,
TemplateType,
autodetect_prompt_templates,
autodetect_template_function,
)
from .context import ContextProvider
from .main import ContextProviderDescription, Policy, SlashCommandDescription, Step
from .models import MODEL_CLASSES, Models
class StepWithParams(BaseModel):
name: StepName
params: Dict[str, Any] = {}
class ContextProviderWithParams(BaseModel):
name: ContextProviderName
params: Dict[str, Any] = {}
class SlashCommand(BaseModel):
name: str
description: str
step: StepName
params: Optional[Dict] = {}
# Allow step class for the migration
@validator("step", pre=True, always=True)
def step_is_string(cls, v):
if isinstance(v, str):
return v
elif isinstance(v, object):
return str(v).split(".")[-1].split("'")[0]
else:
raise ValueError("Step must be a string or a Step object")
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(
default=50,
description="Number of results to initially retrieve from vector database",
)
n_final: Optional[int] = Field(
default=10, description="Final number of results to use after re-ranking"
)
use_reranking: bool = Field(
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(
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(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):
class Config:
extra = "allow"
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(
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(
default=2048,
description="The maximum context length of the LLM in tokens, as counted by count_tokens.",
)
template: Optional[TemplateType] = Field(
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(
default=BaseCompletionOptions(),
description="Options for the completion endpoint. Read more about the completion options in the documentation.",
)
system_message: Optional[str] = Field(
default=None,
description="A system message that will always be followed by the LLM",
)
request_options: RequestOptions = Field(
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(
default=None,
description="The model to use for chat. If not set, will fall back to default.",
)
edit: Optional[str] = Field(
default=None,
description="The model to use for editing. If not set, will fall back to default.",
)
summarize: Optional[str] = Field(
default=None,
description="The model to use for summarization. If not set, will fall back to default.",
)
CONFIG_JSON_PATH = getConfigFilePath(json=True)
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(
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",
"model": "gpt-4",
"api_key": "",
}
]
)
model_roles: ModelRoles = Field(
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.",
)
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",
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 /<name> in the text input, it will act as a shortcut to the prompt.",
)
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.",
)
user_token: Optional[str] = Field(
default=None, description="An optional token to identify the user."
)
data_server_url: Optional[str] = Field(
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(
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(
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(
default=RetrievalSettings(),
description="Settings for the retrieval system. Read more about the retrieval system in the documentation.",
)
@staticmethod
@contextmanager
def edit_config():
config = SerializedContinueConfig.parse_file(CONFIG_JSON_PATH)
yield config
with open(CONFIG_JSON_PATH, "w") as f:
f.write(config.json(exclude_none=True, exclude_defaults=True, indent=2))
@staticmethod
def set_temperature(temperature: float):
with SerializedContinueConfig.edit_config() as config:
config.completion_options.temperature = temperature
posthog_logger.capture_event(
"set_temperature", {"temperature": temperature}
)
@staticmethod
def set_system_message(message: str):
with SerializedContinueConfig.edit_config() as config:
config.system_message = message
posthog_logger.capture_event("set_system_message", {"message": message})
@staticmethod
def set_model_for_role(title: str, role: str):
with SerializedContinueConfig.edit_config() as config:
if role == "*":
config.model_roles.default = title
config.model_roles.chat = title
config.model_roles.edit = title
config.model_roles.summarize = title
else:
config.model_roles.__setattr__(role, title)
@staticmethod
def add_model(model: ModelDescription):
with SerializedContinueConfig.edit_config() as config:
config.models.append(model)
@staticmethod
def set_telemetry_enabled(enabled: bool):
with SerializedContinueConfig.edit_config() as config:
config.allow_anonymous_telemetry = enabled
@staticmethod
def delete_model(title: str):
with SerializedContinueConfig.edit_config() as config:
config.models = [model for model in config.models if model.title != title]
if config.model_roles.default == title:
config.model_roles.default = config.models[0].title
if config.model_roles.chat == title:
config.model_roles.chat = None
if config.model_roles.edit == title:
config.model_roles.edit = None
if config.model_roles.summarize == title:
config.model_roles.summarize = None
def construct_models(self) -> Models:
def model_with_title(title: Optional[str], fallback: ModelDescription):
return next(filter(lambda x: x.title == title, self.models), fallback)
default = model_with_title(self.model_roles.default, self.models[0])
chat = model_with_title(self.model_roles.chat, default)
edit = model_with_title(self.model_roles.edit, default)
summarize = model_with_title(self.model_roles.summarize, default)
saved = [
model_with_title(model.title, default)
for model in self.models
if model.title
not in [default.title, chat.title, edit.title, summarize.title]
]
def create_llm(model: ModelDescription) -> LLM:
model_class = MODEL_CLASSES[MODEL_PROVIDER_TO_MODEL_CLASS[model.provider]]
completion_options = self.completion_options.dict()
completion_options.update(model.completion_options.dict(exclude_none=True))
# Allow extra fields to be passed through
kwargs = {**model.dict(exclude_none=True)}
kwargs["completion_options"] = completion_options
kwargs["template_messages"] = autodetect_template_function(model.model)
kwargs["prompt_templates"] = autodetect_prompt_templates(model.model)
return model_class(**kwargs)
return Models(
default=create_llm(default),
chat=create_llm(chat),
edit=create_llm(edit),
summarize=create_llm(summarize),
saved=[create_llm(model) for model in saved],
)
class ContinueConfig(BaseModel):
"""
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.
"""
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(
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(
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.",
)
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.",
)
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",
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 /<name> 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(
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(
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(
default=None, description="An optional token to identify the user."
)
data_server_url: Optional[str] = Field(
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(
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(
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(
default=RetrievalSettings(),
description="Settings for the retrieval system. Read more about the retrieval system in the documentation.",
)
@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,
models=config.construct_models(),
system_message=config.system_message,
completion_options=config.completion_options,
custom_commands=config.custom_commands,
slash_commands=config.slash_commands,
context_providers=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":
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
spec = importlib.util.spec_from_file_location("config", filepath)
config = importlib.util.module_from_spec(spec)
spec.loader.exec_module(config)
return config.config
except ModuleNotFoundError as e:
# Check if the module was "continuedev.src"
if retry and e.name == "continuedev.src":
convertConfigImports(shorten=True)
return ContinueConfig.from_filepath(filepath, retry=False)
else:
raise e
@staticmethod
def load_default() -> "ContinueConfig":
json_path = os.path.join(getGlobalFolderPath(), "config.json")
if not os.path.exists(json_path):
# MIGRATE FROM OLD CONFIG FORMAT TO JSON
py_path = getConfigFilePath()
config = ContinueConfig.from_filepath(py_path)
with open(json_path, "w") as f:
json.dump(config.to_serialized_continue_config().dict(), f)
return config
# And then the second time, load from the json file
config = ContinueConfig.from_filepath(json_path)
return config
def get_slash_command_descriptions(self) -> List[SlashCommandDescription]:
custom_commands = (
list(
map(
lambda x: x.slash_command_description(),
self.custom_commands,
)
)
or []
)
slash_commands = (
list(
map(
lambda x: x.slash_command_description(),
self.slash_commands,
)
)
or []
)
cmds = custom_commands + slash_commands
cmds.sort(key=lambda x: x.name == "edit", reverse=True)
return cmds
def get_context_provider_descriptions(self) -> List[ContextProviderDescription]:
"""
Returns a list of ContextProviderDescriptions
"""
return [
provider.get_description()
for provider in self.context_providers
if provider.title != "code" # Code isn't used with '@'
] + [
ContextProviderDescription(
title="file",
display_title="Files",
description="Reference files in the current workspace",
dynamic=False,
requires_query=False,
)
]
def to_serialized_continue_config(self) -> SerializedContinueConfig:
# For migration purposes
pre_models = self.models.saved + [
self.models.default,
self.models.chat,
self.models.edit,
self.models.summarize,
]
titles = set()
models: List[LLM] = []
for model in pre_models:
if model is None or model.title in titles:
# Remove duplicate models
continue # : )
titles.add(model.title)
models.append(model)
BACKUP_TITLE = "LLM"
serialized_models = [
ModelDescription(
title=model.title or BACKUP_TITLE,
provider=MODEL_CLASS_TO_MODEL_PROVIDER[model.__class__.__name__],
api_base=model.api_base,
model=model.model,
completion_options=model.completion_options,
api_key=model.api_key,
context_length=model.context_length,
system_message=model.system_message,
)
for model in models
if model is not None
]
model_roles = ModelRoles(
default=self.models.default.title or BACKUP_TITLE,
chat=(self.models.chat or self.models.default).title,
edit=(self.models.edit or self.models.default).title,
summarize=(self.models.summarize or self.models.default).title,
)
return SerializedContinueConfig(
disallowed_steps=self.disallowed_steps,
allow_anonymous_telemetry=self.allow_anonymous_telemetry,
models=serialized_models,
model_roles=model_roles,
system_message=self.system_message,
completion_options=self.completion_options,
custom_commands=self.custom_commands,
slash_commands=self.slash_commands,
context_providers=[
ContextProviderWithParams(
name=CLASS_TO_CONTEXT_PROVIDER_NAME[provider.title],
params=provider.dict(exclude_none=True, exclude_defaults=True),
)
for provider in self.context_providers
if provider.title in CLASS_TO_CONTEXT_PROVIDER_NAME
],
user_token=self.user_token,
data_server_url=self.data_server_url,
disable_summaries=self.disable_summaries,
disable_indexing=self.disable_indexing,
retrieval_settings=self.retrieval_settings,
)

View file

@ -1,199 +0,0 @@
import json
from typing import List, Optional
from pydantic import BaseModel, Field
from ...libs.llm.base import BaseCompletionOptions
from ...libs.llm.openai_free_trial import OpenAIFreeTrial
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.telemetry import posthog_logger
from ..context import ContextProvider
from ..main import ContextProviderDescription, Policy, SlashCommandDescription, Step
from ..models import Models
from .context import CONTEXT_PROVIDER_NAME_TO_CLASS
from .serialized_config import (
CustomCommand,
ModelDescription,
RetrievalSettings,
SerializedContinueConfig,
SlashCommand,
)
class ContinueConfig(BaseModel):
"""
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.
"""
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(
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(
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.",
)
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.",
)
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",
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 /<name> 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(
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(
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(
default=None, description="An optional token to identify the user."
)
data_server_url: Optional[str] = Field(
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(
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(
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(
default=RetrievalSettings(),
description="Settings for the retrieval system. Read more about the retrieval system in the documentation.",
)
@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,
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,
context_providers=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":
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
spec = importlib.util.spec_from_file_location("config", filepath)
config = importlib.util.module_from_spec(spec)
spec.loader.exec_module(config)
return config.config
except ModuleNotFoundError as e:
# Check if the module was "continuedev.src"
if retry and e.name == "continuedev.src":
convertConfigImports(shorten=True)
return ContinueConfig.from_filepath(filepath, retry=False)
else:
raise e
@staticmethod
def load_default() -> "ContinueConfig":
path = getConfigFilePath(json=True)
config = ContinueConfig.from_filepath(path)
return config
def get_slash_command_descriptions(self) -> List[SlashCommandDescription]:
custom_commands = (
list(
map(
lambda x: x.slash_command_description(),
self.custom_commands,
)
)
or []
)
slash_commands = (
list(
map(
lambda x: x.slash_command_description(),
self.slash_commands,
)
)
or []
)
cmds = custom_commands + slash_commands
cmds.sort(key=lambda x: x.name == "edit", reverse=True)
return cmds
def get_context_provider_descriptions(self) -> List[ContextProviderDescription]:
"""
Returns a list of ContextProviderDescriptions
"""
return [
provider.get_description()
for provider in self.context_providers
if provider.title != "code" # Code isn't used with '@'
] + [
ContextProviderDescription(
title="file",
display_title="Files",
description="Reference files in the current workspace",
dynamic=False,
requires_query=False,
)
]

View file

@ -1,270 +0,0 @@
from contextlib import contextmanager
from typing import Any, Dict, List, Optional
from pydantic import BaseModel, Field
from ...libs.util.paths import getConfigFilePath
from ...libs.util.telemetry import posthog_logger
from ...models.llm import BaseCompletionOptions, RequestOptions
from ..main import SlashCommandDescription
from .context import ContextProviderName
from .shared import ModelProvider, StepName, TemplateType
class StepWithParams(BaseModel):
name: StepName
params: Dict[str, Any] = {}
class ContextProviderWithParams(BaseModel):
name: ContextProviderName
params: Dict[str, Any] = {}
class SlashCommand(BaseModel):
name: str
description: str
step: StepName
params: Optional[Dict] = {}
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(
default=50,
description="Number of results to initially retrieve from vector database",
)
n_final: Optional[int] = Field(
default=10, description="Final number of results to use after re-ranking"
)
use_reranking: bool = Field(
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(
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(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):
class Config:
extra = "allow"
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(
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(
default=2048,
description="The maximum context length of the LLM in tokens, as counted by count_tokens.",
)
template: Optional[TemplateType] = Field(
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(
default=BaseCompletionOptions(),
description="Options for the completion endpoint. Read more about the completion options in the documentation.",
)
system_message: Optional[str] = Field(
default=None,
description="A system message that will always be followed by the LLM",
)
request_options: RequestOptions = Field(
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(
default=None,
description="The model to use for chat. If not set, will fall back to default.",
)
edit: Optional[str] = Field(
default=None,
description="The model to use for editing. If not set, will fall back to default.",
)
summarize: Optional[str] = Field(
default=None,
description="The model to use for summarization. If not set, will fall back to default.",
)
CONFIG_JSON_PATH = getConfigFilePath(json=True)
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(
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",
"model": "gpt-4",
"api_key": "",
}
]
)
model_roles: ModelRoles = Field(
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.",
)
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",
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 /<name> in the text input, it will act as a shortcut to the prompt.",
)
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.",
)
user_token: Optional[str] = Field(
default=None, description="An optional token to identify the user."
)
data_server_url: Optional[str] = Field(
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(
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(
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(
default=RetrievalSettings(),
description="Settings for the retrieval system. Read more about the retrieval system in the documentation.",
)
@staticmethod
@contextmanager
def edit_config():
config = SerializedContinueConfig.parse_file(CONFIG_JSON_PATH)
yield config
with open(CONFIG_JSON_PATH, "w") as f:
f.write(config.json(exclude_none=True, exclude_defaults=True, indent=2))
@staticmethod
def set_temperature(temperature: float):
with SerializedContinueConfig.edit_config() as config:
config.completion_options.temperature = temperature
posthog_logger.capture_event(
"set_temperature", {"temperature": temperature}
)
@staticmethod
def set_system_message(message: str):
with SerializedContinueConfig.edit_config() as config:
config.system_message = message
posthog_logger.capture_event("set_system_message", {"message": message})
@staticmethod
def set_model_for_role(title: str, role: str):
with SerializedContinueConfig.edit_config() as config:
if role == "*":
config.model_roles.default = title
config.model_roles.chat = title
config.model_roles.edit = title
config.model_roles.summarize = title
else:
config.model_roles.__setattr__(role, title)
@staticmethod
def add_model(model: ModelDescription):
with SerializedContinueConfig.edit_config() as config:
config.models.append(model)
@staticmethod
def set_telemetry_enabled(enabled: bool):
with SerializedContinueConfig.edit_config() as config:
config.allow_anonymous_telemetry = enabled
@staticmethod
def delete_model(title: str):
with SerializedContinueConfig.edit_config() as config:
config.models = [model for model in config.models if model.title != title]
if config.model_roles.default == title:
config.model_roles.default = config.models[0].title
if config.model_roles.chat == title:
config.model_roles.chat = None
if config.model_roles.edit == title:
config.model_roles.edit = None
if config.model_roles.summarize == title:
config.model_roles.summarize = None

View file

@ -1,4 +1,4 @@
from typing import Literal
from typing import Dict, Literal
from ...plugins.context_providers.diff import DiffContextProvider
from ...plugins.context_providers.github import GitHubIssuesContextProvider
@ -27,3 +27,13 @@ CONTEXT_PROVIDER_NAME_TO_CLASS = {
"search": SearchContextProvider,
"url": URLContextProvider,
}
CLASS_TO_CONTEXT_PROVIDER_NAME: Dict[str, ContextProviderName] = {
"DiffContextProvider": "diff",
"GitHubIssuesContextProvider": "github",
"TerminalContextProvider": "terminal",
"OpenTabsContextProvider": "open",
"GoogleContextProvider": "google",
"SearchContextProvider": "search",
"URLContextProvider": "url",
}

View file

@ -111,7 +111,7 @@ ModelProvider = Literal[
MODEL_PROVIDER_TO_MODEL_CLASS = {
"openai": "OpenAI",
"openai-free-trial": "OpenAIFreeTrial",
"openai-aiohttp": "OpenAIFreeTrial",
"openai-aiohttp": "GGML",
"anthropic": "AnthropicLLM",
"together": "TogetherLLM",
"ollama": "Ollama",
@ -123,6 +123,20 @@ MODEL_PROVIDER_TO_MODEL_CLASS = {
"google-palm": "GooglePaLMAPI",
}
MODEL_CLASS_TO_MODEL_PROVIDER: Dict[str, ModelProvider] = {
"OpenAI": "openai",
"OpenAIFreeTrial": "openai-free-trial",
"AnthropicLLM": "anthropic",
"TogetherLLM": "together",
"Ollama": "ollama",
"HuggingFaceTGI": "huggingface-tgi",
"HuggingFaceInferenceAPI": "huggingface-inference-api",
"LlamaCpp": "llama.cpp",
"ReplicateLLM": "replicate",
"TextGenWebUI": "text-gen-webui",
"GooglePaLMAPI": "google-palm",
}
MODELS = [
# OpenAI
"gpt-3.5-turbo",

View file

@ -1,15 +1,10 @@
import uuid
from typing import Callable, Dict, List, Optional, Type, cast
from typing import Callable, Dict, List, Optional, Type
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, BaseCompletionOptions
from ..libs.llm.base import LLM
from ..libs.llm.ggml import GGML
from ..libs.llm.google_palm_api import GooglePaLMAPI
from ..libs.llm.hf_inference_api import HuggingFaceInferenceAPI
@ -21,7 +16,6 @@ from ..libs.llm.openai_free_trial import OpenAIFreeTrial
from ..libs.llm.replicate import ReplicateLLM
from ..libs.llm.text_gen_webui import TextGenWebUI
from ..libs.llm.together import TogetherLLM
from .config.serialized_config import ModelDescription, SerializedContinueConfig
class ContinueSDK(BaseModel):
@ -94,44 +88,6 @@ class Models(BaseModel):
return values["default"]
return v
@staticmethod
def from_serialized_config(config: SerializedContinueConfig) -> "Models":
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])
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)
saved = [
model_with_title(model.title, default)
for model in config.models
if model.title
not in [default.title, chat.title, edit.title, summarize.title]
]
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))
# Allow extra fields to be passed through
kwargs = {**model.dict(exclude_none=True)}
kwargs["completion_options"] = completion_options
kwargs["template_messages"] = autodetect_template_function(model.model)
kwargs["prompt_templates"] = autodetect_prompt_templates(model.model)
return model_class(**kwargs)
return Models(
default=create_llm(default),
chat=create_llm(chat),
edit=create_llm(edit),
summarize=create_llm(summarize),
saved=[create_llm(model) for model in saved],
)
def dict(self, **kwargs):
original_dict = super().dict(**kwargs)
return original_dict

View file

@ -15,7 +15,7 @@ from ..models.main import Range
from ..plugins.context_providers.highlighted_code import HighlightedCodeContextProvider
from ..server.protocols.gui_protocol import AbstractGUIProtocolServer
from ..server.protocols.ide_protocol import AbstractIdeProtocolServer
from .config.config import ContinueConfig
from .config import ContinueConfig
from .lsp import ContinueLSPClient
from .main import (
ChatMessage,

View file

@ -1,7 +1,7 @@
from typing import List, Optional, Union
from ..core.autopilot import Autopilot
from ..core.config.config import ContinueConfig
from ..core.config import ContinueConfig
from ..core.context import ContextManager, ContextProvider
from ..core.main import SessionState
from ..server.protocols.cli_gui import CommandLineGUI

View file

@ -1,10 +1,8 @@
import asyncio
from typing import AsyncGenerator
from ...core.config.config import ContinueConfig
from ...libs.index.chunkers.chunk_directory import (
stream_chunk_directory,
)
from ...core.config import ContinueConfig
from ...libs.index.chunkers.chunk_directory import stream_chunk_directory
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

View file

@ -145,6 +145,7 @@ def migrateConfigFile(existing: str) -> Optional[str]:
.replace("text_gen_interface", "text_gen_webui")
.replace(".steps.chroma", ".steps.codebase")
.replace("\xa0", " ")
.replace("server_url", "api_base")
)
if migrated != existing:
return migrated
@ -158,19 +159,21 @@ def getConfigFilePath(json: bool = False) -> str:
)
os.makedirs(os.path.dirname(path), exist_ok=True)
if not os.path.exists(path):
with open(path, "w") as f:
f.write(default_config)
else:
# Make any necessary migrations
with open(path, "r") as f:
existing_content = f.read()
migrated = migrateConfigFile(existing_content)
if migrated is not None:
# Until migration considered complete, don't do this for .json
if not json:
if not os.path.exists(path):
with open(path, "w") as f:
f.write(migrated)
f.write(default_config)
else:
# Make any necessary migrations
with open(path, "r") as f:
existing_content = f.read()
migrated = migrateConfigFile(existing_content)
if migrated is not None:
with open(path, "w") as f:
f.write(migrated)
return path

View file

@ -2,9 +2,8 @@ import os
from pydantic import schema_json_of
from ..core.config.config import ContinueConfig
from ..core.config.serialized_config import ModelDescription, SerializedContinueConfig
from ..core.config.shared import ModelName, ModelProvider
from ..core.config import ContinueConfig, ModelDescription, SerializedContinueConfig
from ..core.config_utils.shared import ModelName, ModelProvider
from ..core.context import ContextItem, ContextItemId
from ..core.main import (
ContextProviderDescription,

View file

@ -12,7 +12,7 @@
from textwrap import dedent
from typing import Literal
from ...core.config.config import ContinueConfig
from ...core.config import ContinueConfig
from ...core.main import Policy, SessionState, Step
from ...core.observation import TextObservation
from ...core.sdk import ContinueSDK

View file

@ -1,6 +1,6 @@
from typing import Type, Union
from ...core.config.config import ContinueConfig
from ...core.config import ContinueConfig
from ...core.main import Policy, SessionState, Step
from ...models.main import Position, PositionInFile
from ..steps.chat import SimpleChatStep

View file

@ -1,4 +1,4 @@
from ...core.config.config import ContinueConfig
from ...core.config import ContinueConfig
from ...core.main import Policy, SessionState, Step
from ...core.observation import TextObservation
from ...core.steps import ShellCommandsStep

View file

@ -9,7 +9,7 @@ from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from ..core.config.config import ContinueConfig
from ..core.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

View file

@ -5,8 +5,7 @@ import socketio
from pydantic import BaseModel
from ...core.autopilot import Autopilot
from ...core.config.config import ContinueConfig
from ...core.config.serialized_config import ModelDescription, SerializedContinueConfig
from ...core.config import ContinueConfig, ModelDescription, SerializedContinueConfig
from ...core.main import ContextItem, SessionState, SessionUpdate, Step, StepDescription
from ...libs.util.telemetry import posthog_logger
from ...libs.util.types import AsyncFunc

View file

@ -2,7 +2,7 @@ import traceback
from typing import Dict, Optional
from ..core.autopilot import Autopilot
from ..core.config.config import ContinueConfig
from ..core.config import ContinueConfig
from ..core.context import ContextManager
from ..core.main import SessionState
from ..libs.index.build_index import build_index

View file

@ -1,5 +1,5 @@
import pytest
from continuedev.core.config.config import ContinueConfig
from continuedev.core.config import ContinueConfig
from continuedev.core.steps import UserInputStep
from continuedev.headless import start_headless_session
from continuedev.models.filesystem import Range, RangeInFileWithContents

View file

@ -1,4 +1,4 @@
from continuedev.core.config.config import ContinueConfig
from continuedev.core.config import ContinueConfig
from continuedev.core.models import Models
from continuedev.libs.llm.openai_free_trial import OpenAIFreeTrial