From cfcbee33a416a40f694108e7eed69318630c95d0 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 6 Apr 2025 15:01:04 -0700 Subject: [PATCH 01/19] isProperlyConfigured --- core/index.d.ts | 5 +++++ core/llm/index.ts | 6 ++++++ core/llm/llms/Relace.ts | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/core/index.d.ts b/core/index.d.ts index dd96d1699..f2c33e221 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -162,6 +162,11 @@ export interface ILLM extends LLMOptions { otherData: Record, canPutWordsInModelsMouth?: boolean, ): string | ChatMessage[]; + + /** + * This method should return false if the model is missing an API key or something else that would cause it to fail if called + */ + isProperlyConfigured(): boolean; } export interface ModelInstaller { diff --git a/core/llm/index.ts b/core/llm/index.ts index cc7d7123c..01116e92b 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -260,6 +260,12 @@ export abstract class BaseLLM implements ILLM { options.maxEmbeddingChunkSize ?? DEFAULT_MAX_CHUNK_SIZE; this.embeddingId = `${this.constructor.name}::${this.model}::${this.maxEmbeddingChunkSize}`; } + isProperlyConfigured(): boolean { + return true; + } + useLegacyCompletionsEndpoint?: boolean | undefined; + modelArn?: string | undefined; + env?: Record | undefined; protected createOpenAiAdapter() { return constructLlmApi({ diff --git a/core/llm/llms/Relace.ts b/core/llm/llms/Relace.ts index f7a27c9e3..b533853ea 100644 --- a/core/llm/llms/Relace.ts +++ b/core/llm/llms/Relace.ts @@ -9,4 +9,8 @@ export class Relace extends OpenAI { apiBase: "https://instantapply.endpoint.relace.run/v1/", }; protected useOpenAIAdapterFor: (LlmApiRequestType | "*")[] = ["*"]; + + isProperlyConfigured(): boolean { + return !!this.apiKey; + } } From dfe852f2749ebe2e68c46b4ef9a67c5024f09b39 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 6 Apr 2025 15:21:59 -0700 Subject: [PATCH 02/19] isProperlyConfigured false if continue-proxy apiKeyLocation is NotFound --- core/llm/llms/stubs/ContinueProxy.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index 181db2abd..c723eb07f 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -1,4 +1,8 @@ -import { ContinueProperties } from "@continuedev/config-yaml"; +import { + ContinueProperties, + decodeSecretLocation, + SecretType, +} from "@continuedev/config-yaml"; import { ControlPlaneProxyInfo } from "../../../control-plane/analytics/IAnalyticsProvider.js"; import { Telemetry } from "../../../util/posthog.js"; @@ -49,6 +53,18 @@ class ContinueProxy extends OpenAI { }; } + isProperlyConfigured(): boolean { + if (!this.apiKeyLocation) { + return true; + } + const secretLocation = decodeSecretLocation(this.apiKeyLocation); + if (secretLocation.secretType === SecretType.NotFound) { + return false; + } + + return true; + } + protected _getHeaders() { const headers: any = super._getHeaders(); headers["x-continue-unique-id"] = Telemetry.uniqueId; From 46e8dd7c38858173f375ac24f6857ed3bea2b190 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 13:21:17 -0700 Subject: [PATCH 03/19] feat: fallback to chat model from apply model --- core/config/load.ts | 1 + core/config/selectedModels.ts | 10 ++ core/config/yaml/loadYaml.ts | 26 ++++++ core/index.d.ts | 7 +- core/llm/constants.ts | 5 + core/llm/index.ts | 9 +- core/llm/llms/Relace.ts | 9 +- core/llm/llms/stubs/ContinueProxy.ts | 16 ++-- .../useMainEditorWebviewListeners.ts | 2 - gui/src/pages/config/ModelRoleSelector.tsx | 91 ++++++++++++++++--- 10 files changed, 142 insertions(+), 34 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index 1a3acd6c6..7c8fe87f0 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -602,6 +602,7 @@ function llmToSerializedModelDescription(llm: ILLM): ModelDescription { promptTemplates: llm.promptTemplates as any, capabilities: llm.capabilities, roles: llm.roles, + configurationStatus: llm.getConfigurationStatus(), }; } diff --git a/core/config/selectedModels.ts b/core/config/selectedModels.ts index dd537665d..6ad55f925 100644 --- a/core/config/selectedModels.ts +++ b/core/config/selectedModels.ts @@ -1,6 +1,7 @@ import { ModelRole } from "@continuedev/config-yaml"; import { ContinueConfig, ILLM } from ".."; +import { LLMConfigurationStatus } from "../llm/constants"; import { GlobalContext, GlobalContextModelSelections, @@ -29,9 +30,11 @@ export function rectifySelectedModelsFromGlobalContext( "embed", "rerank", ]; + for (const role of roles) { let newModel: ILLM | null = null; const currentSelection = currentForProfile[role] ?? null; + if (currentSelection) { const match = continueConfig.modelsByRole[role].find( (m) => m.title === currentSelection, @@ -40,12 +43,19 @@ export function rectifySelectedModelsFromGlobalContext( newModel = match; } } + if (!newModel && continueConfig.modelsByRole[role].length > 0) { newModel = continueConfig.modelsByRole[role][0]; } + if (!(currentSelection === (newModel?.title ?? null))) { fellBack = true; } + + if (newModel?.getConfigurationStatus() !== LLMConfigurationStatus.VALID) { + break; + } + configCopy.selectedModelByRole[role] = newModel; } diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index f157bf21d..9805beb2f 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -42,6 +42,7 @@ import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader"; import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; import { getControlPlaneEnvSync } from "../../control-plane/env"; +import { LLMConfigurationStatus } from "../../llm/constants"; import { llmsFromModelConfig } from "./models"; export class LocalPlatformClient implements PlatformClient { @@ -235,6 +236,31 @@ async function configYamlToContinueConfig( if (model.roles?.includes("apply")) { continueConfig.modelsByRole.apply.push(...llms); + + if ( + llms.every( + (llm) => + llm.getConfigurationStatus() !== LLMConfigurationStatus.VALID, + ) + ) { + const chatModelForApplyFallback = config.models?.find((model) => + model.roles?.includes("chat"), + ); + if (chatModelForApplyFallback) { + const [chatLlmForApplyFallback] = await llmsFromModelConfig({ + model: chatModelForApplyFallback, + ide, + uniqueId, + ideSettings, + writeLog, + platformConfigMetadata, + config: continueConfig, + }); + + continueConfig.modelsByRole.apply.unshift(chatLlmForApplyFallback); + continueConfig.selectedModelByRole.apply = chatLlmForApplyFallback; + } + } } if (model.roles?.includes("edit")) { diff --git a/core/index.d.ts b/core/index.d.ts index f2c33e221..dfccadeb6 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,5 +1,6 @@ import { DataDestination, ModelRole, Rule } from "@continuedev/config-yaml"; import Parser from "web-tree-sitter"; +import { LLMConfigurationStatus } from "./llm/constants"; import { GetGhTokenArgs } from "./protocol/ide"; declare global { @@ -163,10 +164,7 @@ export interface ILLM extends LLMOptions { canPutWordsInModelsMouth?: boolean, ): string | ChatMessage[]; - /** - * This method should return false if the model is missing an API key or something else that would cause it to fail if called - */ - isProperlyConfigured(): boolean; + getConfigurationStatus(): LLMConfigurationStatus; } export interface ModelInstaller { @@ -978,6 +976,7 @@ export interface ModelDescription { cacheBehavior?: CacheBehavior; capabilities?: ModelCapability; roles?: ModelRole[]; + configurationStatus?: LLMConfigurationStatus; } export interface EmbedOptions { diff --git a/core/llm/constants.ts b/core/llm/constants.ts index 333c79e70..1315b865a 100644 --- a/core/llm/constants.ts +++ b/core/llm/constants.ts @@ -32,6 +32,11 @@ const PROXY_URL = "http://localhost:65433"; const DEFAULT_MAX_CHUNK_SIZE = 500; // 512 - buffer for safety (in case of differing tokenizers) const DEFAULT_MAX_BATCH_SIZE = 64; +export enum LLMConfigurationStatus { + VALID = "valid", + MISSING_API_KEY = "missing-api-key", +} + export { CONTEXT_LENGTH_FOR_MODEL, DEFAULT_ARGS, diff --git a/core/llm/index.ts b/core/llm/index.ts index 01116e92b..ff8bad889 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -44,6 +44,7 @@ import { DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_TOKENS, + LLMConfigurationStatus, } from "./constants.js"; import { compileChatMessages, @@ -260,12 +261,10 @@ export abstract class BaseLLM implements ILLM { options.maxEmbeddingChunkSize ?? DEFAULT_MAX_CHUNK_SIZE; this.embeddingId = `${this.constructor.name}::${this.model}::${this.maxEmbeddingChunkSize}`; } - isProperlyConfigured(): boolean { - return true; + + getConfigurationStatus() { + return LLMConfigurationStatus.VALID; } - useLegacyCompletionsEndpoint?: boolean | undefined; - modelArn?: string | undefined; - env?: Record | undefined; protected createOpenAiAdapter() { return constructLlmApi({ diff --git a/core/llm/llms/Relace.ts b/core/llm/llms/Relace.ts index b533853ea..344ae17c5 100644 --- a/core/llm/llms/Relace.ts +++ b/core/llm/llms/Relace.ts @@ -1,4 +1,5 @@ import { LLMOptions } from "../.."; +import { LLMConfigurationStatus } from "../constants"; import { LlmApiRequestType } from "../openaiTypeConverters"; import OpenAI from "./OpenAI"; @@ -10,7 +11,11 @@ export class Relace extends OpenAI { }; protected useOpenAIAdapterFor: (LlmApiRequestType | "*")[] = ["*"]; - isProperlyConfigured(): boolean { - return !!this.apiKey; + getConfigurationStatus() { + if (!this.apiKey) { + return LLMConfigurationStatus.MISSING_API_KEY; + } + + return LLMConfigurationStatus.VALID; } } diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index c723eb07f..4477143d2 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -9,6 +9,7 @@ import { Telemetry } from "../../../util/posthog.js"; import OpenAI from "../OpenAI.js"; import type { Chunk, LLMOptions } from "../../../index.js"; +import { LLMConfigurationStatus } from "../../constants.js"; class ContinueProxy extends OpenAI { set controlPlaneProxyInfo(value: ControlPlaneProxyInfo) { @@ -53,16 +54,17 @@ class ContinueProxy extends OpenAI { }; } - isProperlyConfigured(): boolean { + getConfigurationStatus() { if (!this.apiKeyLocation) { - return true; - } - const secretLocation = decodeSecretLocation(this.apiKeyLocation); - if (secretLocation.secretType === SecretType.NotFound) { - return false; + return LLMConfigurationStatus.VALID; } - return true; + const secretLocation = decodeSecretLocation(this.apiKeyLocation); + if (secretLocation.secretType === SecretType.NotFound) { + return LLMConfigurationStatus.MISSING_API_KEY; + } + + return LLMConfigurationStatus.VALID; } protected _getHeaders() { diff --git a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts index 6e7808ba7..400f08019 100644 --- a/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts +++ b/gui/src/components/mainInput/TipTapEditor/useMainEditorWebviewListeners.ts @@ -123,8 +123,6 @@ export function useMainEditorWebviewListeners({ } } - debugger; - editor .chain() .insertContentAt(index, { diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index cdc0d16d1..8756329f6 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -1,5 +1,12 @@ -import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/24/outline"; -import { type ModelDescription } from "core"; +import { + CheckIcon, + ChevronUpDownIcon, + Cog6ToothIcon, + CubeIcon, +} from "@heroicons/react/24/outline"; +import { ModelDescription } from "core"; +import { LLMConfigurationStatus } from "core/llm/constants"; +import { MouseEvent, useContext, useState } from "react"; import { defaultBorderRadius } from "../../components"; import { ToolTip } from "../../components/gui/Tooltip"; import InfoHover from "../../components/InfoHover"; @@ -10,6 +17,7 @@ import { ListboxOptions, Transition, } from "../../components/ui"; +import { IdeMessengerContext } from "../../context/IdeMessenger"; import { fontSize } from "../../util"; interface ModelRoleSelectorProps { @@ -27,10 +35,29 @@ const ModelRoleSelector = ({ displayName, description, }: ModelRoleSelectorProps) => { + const ideMessenger = useContext(IdeMessengerContext); + const [hoveredIdx, setHoveredIdx] = useState(null); + function handleSelect(title: string | null) { onSelect(models.find((m) => m.title === title) ?? null); } + function onClickGear(e: MouseEvent) { + e.stopPropagation(); + e.preventDefault(); + ideMessenger.post("config/openProfile", { profileId: undefined }); + } + + function handleOptionClick( + showMissingApiKeyMsg: boolean, + e: MouseEvent, + ) { + if (showMissingApiKeyMsg) { + e.preventDefault(); + e.stopPropagation(); + } + } + return ( <>
@@ -71,19 +98,55 @@ const ModelRoleSelector = ({ style={{ borderRadius: defaultBorderRadius }} className="min-w-40" > - {models.map((option, idx) => ( - - { + const showMissingApiKeyMsg = + option.configurationStatus === + LLMConfigurationStatus.MISSING_API_KEY; + + return ( + setHoveredIdx(idx)} + onMouseLeave={() => setHoveredIdx(null)} + onClick={(e: any) => + handleOptionClick(showMissingApiKeyMsg, e) + } + className={""} > - {option.title} - - {option.title === selectedModel?.title && ( - - ))} +
+
+
+ + + {option.title} + {showMissingApiKeyMsg && ( + + (Missing API key) + + )} + +
+
+ {hoveredIdx === idx && ( + + )} + {option.title === selectedModel?.title && ( + + )} +
+
+
+ + ); + })}
From fa3c5f7a152baef48d4e69c39f7ec5e383fc333a Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 13:29:27 -0700 Subject: [PATCH 04/19] rename to "LLMConfigurationStatuses" --- core/config/selectedModels.ts | 4 ++-- core/config/yaml/loadYaml.ts | 4 ++-- core/index.d.ts | 6 +++--- core/llm/constants.ts | 2 +- core/llm/index.ts | 4 ++-- core/llm/llms/Relace.ts | 6 +++--- core/llm/llms/stubs/ContinueProxy.ts | 8 ++++---- gui/src/pages/config/ModelRoleSelector.tsx | 4 ++-- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core/config/selectedModels.ts b/core/config/selectedModels.ts index 6ad55f925..c2ef111c0 100644 --- a/core/config/selectedModels.ts +++ b/core/config/selectedModels.ts @@ -1,7 +1,7 @@ import { ModelRole } from "@continuedev/config-yaml"; import { ContinueConfig, ILLM } from ".."; -import { LLMConfigurationStatus } from "../llm/constants"; +import { LLMConfigurationStatuses } from "../llm/constants"; import { GlobalContext, GlobalContextModelSelections, @@ -52,7 +52,7 @@ export function rectifySelectedModelsFromGlobalContext( fellBack = true; } - if (newModel?.getConfigurationStatus() !== LLMConfigurationStatus.VALID) { + if (newModel?.getConfigurationStatus() !== LLMConfigurationStatuses.VALID) { break; } diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 9805beb2f..33b7b4693 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -42,7 +42,7 @@ import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader"; import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; import { getControlPlaneEnvSync } from "../../control-plane/env"; -import { LLMConfigurationStatus } from "../../llm/constants"; +import { LLMConfigurationStatuses } from "../../llm/constants"; import { llmsFromModelConfig } from "./models"; export class LocalPlatformClient implements PlatformClient { @@ -240,7 +240,7 @@ async function configYamlToContinueConfig( if ( llms.every( (llm) => - llm.getConfigurationStatus() !== LLMConfigurationStatus.VALID, + llm.getConfigurationStatus() !== LLMConfigurationStatuses.VALID, ) ) { const chatModelForApplyFallback = config.models?.find((model) => diff --git a/core/index.d.ts b/core/index.d.ts index dfccadeb6..18813703e 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1,6 +1,6 @@ import { DataDestination, ModelRole, Rule } from "@continuedev/config-yaml"; import Parser from "web-tree-sitter"; -import { LLMConfigurationStatus } from "./llm/constants"; +import { LLMConfigurationStatuses } from "./llm/constants"; import { GetGhTokenArgs } from "./protocol/ide"; declare global { @@ -164,7 +164,7 @@ export interface ILLM extends LLMOptions { canPutWordsInModelsMouth?: boolean, ): string | ChatMessage[]; - getConfigurationStatus(): LLMConfigurationStatus; + getConfigurationStatus(): LLMConfigurationStatuses; } export interface ModelInstaller { @@ -976,7 +976,7 @@ export interface ModelDescription { cacheBehavior?: CacheBehavior; capabilities?: ModelCapability; roles?: ModelRole[]; - configurationStatus?: LLMConfigurationStatus; + configurationStatus?: LLMConfigurationStatuses; } export interface EmbedOptions { diff --git a/core/llm/constants.ts b/core/llm/constants.ts index 1315b865a..8532aa33b 100644 --- a/core/llm/constants.ts +++ b/core/llm/constants.ts @@ -32,7 +32,7 @@ const PROXY_URL = "http://localhost:65433"; const DEFAULT_MAX_CHUNK_SIZE = 500; // 512 - buffer for safety (in case of differing tokenizers) const DEFAULT_MAX_BATCH_SIZE = 64; -export enum LLMConfigurationStatus { +export enum LLMConfigurationStatuses { VALID = "valid", MISSING_API_KEY = "missing-api-key", } diff --git a/core/llm/index.ts b/core/llm/index.ts index ff8bad889..363e45395 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -44,7 +44,7 @@ import { DEFAULT_MAX_BATCH_SIZE, DEFAULT_MAX_CHUNK_SIZE, DEFAULT_MAX_TOKENS, - LLMConfigurationStatus, + LLMConfigurationStatuses, } from "./constants.js"; import { compileChatMessages, @@ -263,7 +263,7 @@ export abstract class BaseLLM implements ILLM { } getConfigurationStatus() { - return LLMConfigurationStatus.VALID; + return LLMConfigurationStatuses.VALID; } protected createOpenAiAdapter() { diff --git a/core/llm/llms/Relace.ts b/core/llm/llms/Relace.ts index 344ae17c5..d65a94dc1 100644 --- a/core/llm/llms/Relace.ts +++ b/core/llm/llms/Relace.ts @@ -1,5 +1,5 @@ import { LLMOptions } from "../.."; -import { LLMConfigurationStatus } from "../constants"; +import { LLMConfigurationStatuses } from "../constants"; import { LlmApiRequestType } from "../openaiTypeConverters"; import OpenAI from "./OpenAI"; @@ -13,9 +13,9 @@ export class Relace extends OpenAI { getConfigurationStatus() { if (!this.apiKey) { - return LLMConfigurationStatus.MISSING_API_KEY; + return LLMConfigurationStatuses.MISSING_API_KEY; } - return LLMConfigurationStatus.VALID; + return LLMConfigurationStatuses.VALID; } } diff --git a/core/llm/llms/stubs/ContinueProxy.ts b/core/llm/llms/stubs/ContinueProxy.ts index 4477143d2..e43e2bfe2 100644 --- a/core/llm/llms/stubs/ContinueProxy.ts +++ b/core/llm/llms/stubs/ContinueProxy.ts @@ -9,7 +9,7 @@ import { Telemetry } from "../../../util/posthog.js"; import OpenAI from "../OpenAI.js"; import type { Chunk, LLMOptions } from "../../../index.js"; -import { LLMConfigurationStatus } from "../../constants.js"; +import { LLMConfigurationStatuses } from "../../constants.js"; class ContinueProxy extends OpenAI { set controlPlaneProxyInfo(value: ControlPlaneProxyInfo) { @@ -56,15 +56,15 @@ class ContinueProxy extends OpenAI { getConfigurationStatus() { if (!this.apiKeyLocation) { - return LLMConfigurationStatus.VALID; + return LLMConfigurationStatuses.VALID; } const secretLocation = decodeSecretLocation(this.apiKeyLocation); if (secretLocation.secretType === SecretType.NotFound) { - return LLMConfigurationStatus.MISSING_API_KEY; + return LLMConfigurationStatuses.MISSING_API_KEY; } - return LLMConfigurationStatus.VALID; + return LLMConfigurationStatuses.VALID; } protected _getHeaders() { diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index 8756329f6..5af026f61 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -5,7 +5,7 @@ import { CubeIcon, } from "@heroicons/react/24/outline"; import { ModelDescription } from "core"; -import { LLMConfigurationStatus } from "core/llm/constants"; +import { LLMConfigurationStatuses } from "core/llm/constants"; import { MouseEvent, useContext, useState } from "react"; import { defaultBorderRadius } from "../../components"; import { ToolTip } from "../../components/gui/Tooltip"; @@ -101,7 +101,7 @@ const ModelRoleSelector = ({ {models.map((option, idx) => { const showMissingApiKeyMsg = option.configurationStatus === - LLMConfigurationStatus.MISSING_API_KEY; + LLMConfigurationStatuses.MISSING_API_KEY; return ( Date: Tue, 8 Apr 2025 13:45:06 -0700 Subject: [PATCH 05/19] Update loadYaml.ts --- core/config/yaml/loadYaml.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index f68fd8cbd..867917ac0 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -253,7 +253,7 @@ async function configYamlToContinueConfig( ide, uniqueId, ideSettings, - writeLog, + llmLogger, platformConfigMetadata, config: continueConfig, }); From b601c22d01478d74a66bf162f3e12c4c4e1a93d7 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 17:02:29 -0700 Subject: [PATCH 06/19] feat: fallback to chat model in IDE --- core/config/selectedModels.ts | 6 +++- core/config/yaml/loadYaml.ts | 26 ---------------- core/protocol/ideWebview.ts | 1 - .../continue/IdeProtocolClient.kt | 30 ++++++++++++------- .../protocol/ideWebview.kt | 1 - extensions/vscode/package-lock.json | 4 +-- .../vscode/src/extension/VsCodeMessenger.ts | 18 +++++------ .../StepContainerPreActionButtons.tsx | 11 ++----- .../StepContainerPreToolbar.tsx | 1 - gui/src/pages/config/ModelRoleSelector.tsx | 6 ++++ gui/src/redux/thunks/callTool.ts | 3 -- 11 files changed, 42 insertions(+), 65 deletions(-) diff --git a/core/config/selectedModels.ts b/core/config/selectedModels.ts index c2ef111c0..99d89e1a0 100644 --- a/core/config/selectedModels.ts +++ b/core/config/selectedModels.ts @@ -52,7 +52,11 @@ export function rectifySelectedModelsFromGlobalContext( fellBack = true; } - if (newModel?.getConfigurationStatus() !== LLMConfigurationStatuses.VALID) { + // Currently only check for configuration status for apply + if ( + role === "apply" && + newModel?.getConfigurationStatus() !== LLMConfigurationStatuses.VALID + ) { break; } diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 867917ac0..1edb48604 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -43,7 +43,6 @@ import { PlatformConfigMetadata } from "../profile/PlatformProfileLoader"; import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; import { getControlPlaneEnvSync } from "../../control-plane/env"; -import { LLMConfigurationStatuses } from "../../llm/constants"; import { llmsFromModelConfig } from "./models"; export class LocalPlatformClient implements PlatformClient { @@ -237,31 +236,6 @@ async function configYamlToContinueConfig( if (model.roles?.includes("apply")) { continueConfig.modelsByRole.apply.push(...llms); - - if ( - llms.every( - (llm) => - llm.getConfigurationStatus() !== LLMConfigurationStatuses.VALID, - ) - ) { - const chatModelForApplyFallback = config.models?.find((model) => - model.roles?.includes("chat"), - ); - if (chatModelForApplyFallback) { - const [chatLlmForApplyFallback] = await llmsFromModelConfig({ - model: chatModelForApplyFallback, - ide, - uniqueId, - ideSettings, - llmLogger, - platformConfigMetadata, - config: continueConfig, - }); - - continueConfig.modelsByRole.apply.unshift(chatLlmForApplyFallback); - continueConfig.selectedModelByRole.apply = chatLlmForApplyFallback; - } - } } if (model.roles?.includes("edit")) { diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 6aae337f0..47c28680c 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -17,7 +17,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { { text: string; streamId: string; - curSelectedModelTitle: string; filepath?: string; toolCallId?: string; }, diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 41c2c4892..5f4316f8e 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -497,21 +497,29 @@ class IdeProtocolClient( val config = result["config"] as Map<*, *> val selectedModels = config["selectedModelByRole"] as? Map<*, *> - val applyCodeBlockModel = selectedModels?.get("apply") as? Map<*, *> + var applyCodeBlockModel = selectedModels?.get("apply") as? Map<*, *> + + // If "apply" role model is not found, try "chat" role + if (applyCodeBlockModel == null) { + applyCodeBlockModel = selectedModels?.get("chat") as? Map<*, *> + } + + // If neither "apply" nor "chat" models are available in selectedModelByRole, + // fallback to modelsByRole.chat[0] + if (applyCodeBlockModel == null) { + val modelsByRole = config["modelsByRole"] as? Map<*, *> + val chatModels = modelsByRole?.get("chat") as? List<*> + if (chatModels != null && chatModels.isNotEmpty()) { + applyCodeBlockModel = chatModels[0] as? Map<*, *> + } + } + if (applyCodeBlockModel != null) { continuation.resume(applyCodeBlockModel) } else { - val models = - config["models"] as List> - val curSelectedModel = - models.find { it["title"] == params.curSelectedModelTitle } - - if (curSelectedModel == null) { - continuation.resumeWithException(IllegalStateException("Model '${params.curSelectedModelTitle}' not found in config.")) - } else { - continuation.resume(curSelectedModel) - } + // If neither "apply" nor "chat" models are available, return with exception + continuation.resumeWithException(IllegalStateException("No 'apply' or 'chat' model found in configuration.")) } } catch (e: Exception) { continuation.resumeWithException(e) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt index 5c587c54d..718755a99 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/protocol/ideWebview.kt @@ -11,7 +11,6 @@ data class SetGitHubAuthTokenParams( data class ApplyToFileParams( val text: String, val streamId: String, - val curSelectedModelTitle: String, val filepath: String?, val toolCallId: String? ) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 108520e49..efc342f19 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.21", + "version": "1.1.22", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.21", + "version": "1.1.22", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 9563eb8a9..910b33c1f 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -18,7 +18,6 @@ import { stripImages } from "core/util/messageContent"; import { getUriPathBasename } from "core/util/uri"; import * as vscode from "vscode"; -import { ILLM } from "core"; import { VerticalDiffManager } from "../diff/vertical/manager"; import EditDecorationManager from "../quickEdit/EditDecorationManager"; import { @@ -180,19 +179,16 @@ export class VsCodeMessenger { return; } - let llm: ILLM | null | undefined = config.selectedModelByRole.apply; + let llm = + config.selectedModelByRole.apply ?? + config.selectedModelByRole.chat ?? + config.modelsByRole.chat[0]; if (!llm) { - llm = config.models.find( - (model) => model.title === data.curSelectedModelTitle, + vscode.window.showErrorMessage( + `No model with roles "apply" or "chat" found in config.`, ); - - if (!llm) { - vscode.window.showErrorMessage( - `Model ${data.curSelectedModelTitle} not found in config.`, - ); - return; - } + return; } const fastLlm = getModelByRole(config, "repoMapFileSelection") ?? llm; diff --git a/gui/src/components/markdown/StepContainerPreActionButtons.tsx b/gui/src/components/markdown/StepContainerPreActionButtons.tsx index 85ece0990..7e42dfb1c 100644 --- a/gui/src/components/markdown/StepContainerPreActionButtons.tsx +++ b/gui/src/components/markdown/StepContainerPreActionButtons.tsx @@ -13,10 +13,7 @@ import { import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppSelector } from "../../redux/hooks"; -import { - selectDefaultModel, - selectUIConfig, -} from "../../redux/slices/configSlice"; +import { selectUIConfig } from "../../redux/slices/configSlice"; import { isJetBrains } from "../../util"; import { CopyIconButton } from "../gui/CopyIconButton"; import HeaderButtonWithToolTip from "../gui/HeaderButtonWithToolTip"; @@ -56,16 +53,14 @@ export default function StepContainerPreActionButtons({ streamIdRef.current = uuidv4(); } - const defaultModel = useAppSelector(selectDefaultModel); - function onClickApply() { - if (!defaultModel || !streamIdRef.current) { + if (!streamIdRef.current) { return; } + ideMessenger.post("applyToFile", { streamId: streamIdRef.current, text: codeBlockContent, - curSelectedModelTitle: defaultModel.title, }); } diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index f09ed1a9f..a415f6f84 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -97,7 +97,6 @@ export default function StepContainerPreToolbar( streamId: props.codeBlockStreamId, filepath: fileUri, text: codeBlockContent, - curSelectedModelTitle: defaultModel.title, }); } diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index 5af026f61..c6d2e5a98 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -38,6 +38,10 @@ const ModelRoleSelector = ({ const ideMessenger = useContext(IdeMessengerContext); const [hoveredIdx, setHoveredIdx] = useState(null); + const noConfiguredModels = models.every( + (model) => model.configurationStatus !== LLMConfigurationStatuses.VALID, + ); + function handleSelect(title: string | null) { onSelect(models.find((m) => m.title === title) ?? null); } @@ -81,6 +85,8 @@ const ModelRoleSelector = ({ > {models.length === 0 ? ( {`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} + ) : noConfiguredModels ? ( + {`No valid ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} ) : ( {selectedModel?.title ?? `Select ${displayName} model`} diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index bf15e7ae8..76b37b6fd 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -54,7 +54,6 @@ export const callTool = createAsyncThunk( args, extra.ideMessenger, state.session.activeToolStreamId[0], - defaultModel.title, toolCallState.toolCallId, ); } catch (e) { @@ -125,7 +124,6 @@ async function customGuiEditImpl( args: EditToolArgs, ideMessenger: IIdeMessenger, streamId: string, - modelTitle: string, toolCallId: string, ) { const firstUriMatch = await resolveRelativePathInDir( @@ -138,7 +136,6 @@ async function customGuiEditImpl( const apply = await ideMessenger.request("applyToFile", { streamId, text: args.new_contents, - curSelectedModelTitle: modelTitle, toolCallId, filepath: firstUriMatch, }); From a02012da321f0bc80a3686934ee146b3ec451485 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 17:19:24 -0700 Subject: [PATCH 07/19] Update ContinuePluginToolWindowFactory.kt --- .../toolWindow/ContinuePluginToolWindowFactory.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt index 5d8335220..d0d44655c 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/toolWindow/ContinuePluginToolWindowFactory.kt @@ -11,7 +11,7 @@ import com.intellij.openapi.wm.ToolWindowFactory import com.intellij.ui.content.ContentFactory import javax.swing.* -const val JS_QUERY_POOL_SIZE = 200 +const val JS_QUERY_POOL_SIZE = "200" class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware { override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) { @@ -43,6 +43,11 @@ class ContinuePluginToolWindowFactory : ToolWindowFactory, DumbAware { class ContinuePluginWindow(project: Project) { private val defaultGUIUrl = "http://continue/index.html" + init { + System.setProperty("ide.browser.jcef.jsQueryPoolSize", JS_QUERY_POOL_SIZE) + System.setProperty("ide.browser.jcef.contextMenu.devTools.enabled", "true") + } + val browser: ContinueBrowser by lazy { val url = System.getenv("GUI_URL")?.toString() ?: defaultGUIUrl From 1bf359a55fdb833569878167a1440e66c65d7249 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 17:55:11 -0700 Subject: [PATCH 08/19] feat: remove defaultTitle --- core/config/selectedModels.ts | 5 +- gui/src/components/Footer.tsx | 4 +- .../components/BestExperienceConfigForm.tsx | 6 +- .../tabs/OnboardingLocalTab.tsx | 6 +- .../StepContainer/ThinkingIndicator.tsx | 4 +- .../mainInput/AtMentionDropdown/index.tsx | 9 ++- gui/src/components/mainInput/InputToolbar.tsx | 4 +- .../mainInput/Lump/sections/ModelsSection.tsx | 27 +-------- .../mainInput/TipTapEditor/TipTapEditor.tsx | 4 +- .../TipTapEditor/utils/editorConfig.ts | 4 +- .../StepContainerPreToolbar.tsx | 4 +- .../components/modelSelection/ModeSelect.tsx | 4 +- .../components/modelSelection/ModelSelect.tsx | 10 ++-- .../platform/AssistantSelect.tsx | 37 ++++++------ gui/src/forms/AddModelForm.tsx | 8 +-- gui/src/hooks/useSetup.ts | 4 +- gui/src/pages/gui/Chat.tsx | 4 +- gui/src/pages/gui/StreamError.tsx | 4 +- gui/src/redux/slices/configSlice.ts | 59 ++++++------------- gui/src/redux/thunks/callTool.ts | 4 +- gui/src/redux/thunks/gatherContext.ts | 4 +- gui/src/redux/thunks/session.ts | 4 +- gui/src/redux/thunks/streamNormalInput.ts | 6 +- gui/src/redux/thunks/streamResponse.ts | 4 +- .../thunks/streamResponseAfterToolCall.ts | 4 +- 25 files changed, 94 insertions(+), 139 deletions(-) diff --git a/core/config/selectedModels.ts b/core/config/selectedModels.ts index 99d89e1a0..20dfb5063 100644 --- a/core/config/selectedModels.ts +++ b/core/config/selectedModels.ts @@ -20,15 +20,14 @@ export function rectifySelectedModelsFromGlobalContext( let fellBack = false; - // chat and summarize not implemented yet - // default chat model is stored in GUI still - + // summarize not implemented yet const roles: ModelRole[] = [ "autocomplete", "apply", "edit", "embed", "rerank", + "chat", ]; for (const role of roles) { diff --git a/gui/src/components/Footer.tsx b/gui/src/components/Footer.tsx index b2efd221c..d6e79651c 100644 --- a/gui/src/components/Footer.tsx +++ b/gui/src/components/Footer.tsx @@ -1,11 +1,11 @@ import { useAppSelector } from "../redux/hooks"; -import { selectDefaultModel } from "../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../redux/slices/configSlice"; import { FREE_TRIAL_LIMIT_REQUESTS } from "../util/freeTrial"; import { getLocalStorage } from "../util/localStorage"; import FreeTrialProgressBar from "./loaders/FreeTrialProgressBar"; function Footer() { - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); if (defaultModel?.provider === "free-trial") { return ( diff --git a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx index 389ed72dd..d05481dfb 100644 --- a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx +++ b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx @@ -5,7 +5,7 @@ import { Button, Input, InputSubtext, lightGray } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { models } from "../../../pages/AddNewModel/configs/models"; import { providers } from "../../../pages/AddNewModel/configs/providers"; -import { setDefaultModel } from "../../../redux/slices/configSlice"; +import { setSelectedChatModel } from "../../../redux/slices/configSlice"; import AddModelButtonSubtext from "../../AddModelButtonSubtext"; const { anthropic, mistral } = providers; @@ -61,7 +61,9 @@ function BestExperienceConfigForm({ model: repoMapConfig, role: "repoMapFileSelection", }); - dispatch(setDefaultModel({ title: chatModelConfig.title, force: true })); + dispatch( + setSelectedChatModel({ title: chatModelConfig.title, force: true }), + ); if (!!autocompleteApiKey) { await ideMessenger.request("addAutocompleteModel", { diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx index 81b0a7a6b..54f036118 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx +++ b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx @@ -9,12 +9,12 @@ import { useContext, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; import { Button } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; +import { setSelectedChatModel } from "../../../redux/slices/configSlice"; +import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; import AddModelButtonSubtext from "../../AddModelButtonSubtext"; import OllamaModelDownload from "../components/OllamaModelDownload"; import { OllamaStatus } from "../components/OllamaStatus"; import { useSubmitOnboarding } from "../hooks"; -import { setDefaultModel } from "../../../redux/slices/configSlice"; -import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; const OLLAMA_CHECK_INTERVAL_MS = 3000; @@ -137,7 +137,7 @@ function OnboardingLocalTab({ isDialog }: OnboardingLocalTabProps) { // Set the selected model to the local chat model dispatch( - setDefaultModel({ + setSelectedChatModel({ title: LOCAL_ONBOARDING_CHAT_TITLE, force: true, // Because it doesn't exist in the webview's config object yet }), diff --git a/gui/src/components/StepContainer/ThinkingIndicator.tsx b/gui/src/components/StepContainer/ThinkingIndicator.tsx index 862351872..3dcbf9491 100644 --- a/gui/src/components/StepContainer/ThinkingIndicator.tsx +++ b/gui/src/components/StepContainer/ThinkingIndicator.tsx @@ -1,7 +1,7 @@ import { ChatHistoryItem } from "core"; import { useEffect, useState } from "react"; import { useAppSelector } from "../../redux/hooks"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; interface ThinkingIndicatorProps { historyItem: ChatHistoryItem; @@ -22,7 +22,7 @@ const ThinkingIndicator = ({ historyItem }: ThinkingIndicatorProps) => { }; }, []); - const selectedModel = useAppSelector(selectDefaultModel); + const selectedModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); const hasContent = Array.isArray(historyItem.message.content) diff --git a/gui/src/components/mainInput/AtMentionDropdown/index.tsx b/gui/src/components/mainInput/AtMentionDropdown/index.tsx index c028b7a87..9d5a10bec 100644 --- a/gui/src/components/mainInput/AtMentionDropdown/index.tsx +++ b/gui/src/components/mainInput/AtMentionDropdown/index.tsx @@ -26,6 +26,7 @@ import { } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useAppSelector } from "../../../redux/hooks"; +import { selectSelectedChatModel } from "../../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; import { fontSize } from "../../../util"; import FileIcon from "../../FileIcon"; @@ -161,9 +162,7 @@ const AtMentionDropdown = forwardRef((props: AtMentionDropdownProps, ref) => { const ideMessenger = useContext(IdeMessengerContext); - const selectedModelTitle = useAppSelector( - (store) => store.config.defaultModelTitle, - ); + const selectedModelTitle = useAppSelector(selectSelectedChatModel); const [selectedIndex, setSelectedIndex] = useState(0); @@ -192,7 +191,7 @@ const AtMentionDropdown = forwardRef((props: AtMentionDropdownProps, ref) => { query, fullInput: "", selectedCode, - selectedModelTitle: selectedModelTitle ?? "", + selectedModelTitle: selectedModelTitle?.title ?? "", }, ); @@ -205,7 +204,7 @@ const AtMentionDropdown = forwardRef((props: AtMentionDropdownProps, ref) => { // Check if the context item exceeds the context length of the selected model const result = await ideMessenger.request("isItemTooBig", { item, - selectedModelTitle: selectedModelTitle, + selectedModelTitle: selectedModelTitle?.title, }); if (result.status === "error") { diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 20e40d9a9..252126425 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -14,7 +14,7 @@ import { import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseActiveFile } from "../../redux/selectors"; import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { selectHasCodeToEdit, selectIsInEditMode, @@ -92,7 +92,7 @@ interface InputToolbarProps { function InputToolbar(props: InputToolbarProps) { const dispatch = useAppDispatch(); const fileInputRef = useRef(null); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); const useActiveFile = useAppSelector(selectUseActiveFile); const isInEditMode = useAppSelector(selectIsInEditMode); const hasCodeToEdit = useAppSelector(selectHasCodeToEdit); diff --git a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx index 05e9352f0..f6edc7400 100644 --- a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx @@ -5,11 +5,7 @@ import { useAuth } from "../../../../context/Auth"; import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import ModelRoleSelector from "../../../../pages/config/ModelRoleSelector"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; -import { - selectDefaultModel, - setDefaultModel, - updateConfig, -} from "../../../../redux/slices/configSlice"; +import { updateConfig } from "../../../../redux/slices/configSlice"; import { isJetBrains } from "../../../../util"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; @@ -20,7 +16,6 @@ export function ModelsSection() { const config = useAppSelector((state) => state.config.config); const jetbrains = isJetBrains(); - const selectedChatModel = useAppSelector(selectDefaultModel); function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { if (!selectedProfile) { @@ -43,14 +38,6 @@ export function ModelsSection() { }); } - // TODO use handleRoleUpdate for chat - function handleChatModelSelection(model: ModelDescription | null) { - if (!model) { - return; - } - dispatch(setDefaultModel({ title: model.title })); - } - return (
@@ -58,16 +45,8 @@ export function ModelsSection() { displayName="Chat" description="Used in the chat interface" models={config.modelsByRole.chat} - selectedModel={ - selectedChatModel - ? { - title: selectedChatModel.title, - provider: selectedChatModel.provider, - model: selectedChatModel.model, - } - : null - } - onSelect={(model) => handleChatModelSelection(model)} + selectedModel={config.selectedModelByRole.chat} + onSelect={(model) => handleRoleUpdate("chat", model)} /> state.session.isStreaming); const isInEditMode = useAppSelector(selectIsInEditMode); const historyLength = useAppSelector((store) => store.session.history.length); diff --git a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts index e50769ac8..9c56819e3 100644 --- a/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts +++ b/gui/src/components/mainInput/TipTapEditor/utils/editorConfig.ts @@ -21,7 +21,7 @@ import { useInputHistory } from "../../../../hooks/useInputHistory"; import useUpdatingRef from "../../../../hooks/useUpdatingRef"; import { useAppSelector } from "../../../../redux/hooks"; import { selectUseActiveFile } from "../../../../redux/selectors"; -import { selectDefaultModel } from "../../../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../../../redux/slices/configSlice"; import { addCodeToEdit, selectHasCodeToEdit, @@ -83,7 +83,7 @@ export function createEditorConfig(options: { const posthog = usePostHog(); const { getSubmenuContextItems } = useSubmenuContextProviders(); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); const useActiveFile = useAppSelector(selectUseActiveFile); const historyLength = useAppSelector((store) => store.session.history.length); diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index a415f6f84..ed4a7ea47 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -11,7 +11,7 @@ import { import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { useWebviewListener } from "../../../hooks/useWebviewListener"; import { useAppSelector } from "../../../redux/hooks"; -import { selectDefaultModel } from "../../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../../redux/slices/configSlice"; import { selectApplyStateByStreamId, selectIsInEditMode, @@ -81,7 +81,7 @@ export default function StepContainerPreToolbar( const isNextCodeBlock = nextCodeBlockIndex === props.codeBlockIndex; const hasFileExtension = /\.[0-9a-z]+$/i.test(props.relativeFilepath); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); async function onClickApply() { if (!defaultModel) { diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 0e14adfad..92395f545 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -12,7 +12,7 @@ import { useEffect, useMemo } from "react"; import styled from "styled-components"; import { lightGray } from ".."; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { cycleMode, selectCurrentMode, @@ -40,7 +40,7 @@ const ShortcutText = styled.span` function ModeSelect() { const dispatch = useAppDispatch(); const mode = useAppSelector(selectCurrentMode); - const selectedModel = useAppSelector(selectDefaultModel); + const selectedModel = useAppSelector(selectSelectedChatModel); const agentModeSupported = selectedModel && modelSupportsTools(selectedModel); const jetbrains = useMemo(() => { diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 4c2e31387..a6e7756ac 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -14,8 +14,8 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; import { useAppSelector } from "../../redux/hooks"; import { - selectDefaultModel, - setDefaultModel, + selectSelectedChatModel, + setSelectedChatModel, } from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; @@ -123,7 +123,7 @@ function ModelOption({ function ModelSelect() { const dispatch = useDispatch(); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); const allModels = useAppSelector((state) => state.config.config.models); const buttonRef = useRef(null); const [options, setOptions] = useState([]); @@ -164,7 +164,7 @@ function ModelSelect() { let nextIndex = (currentIndex + 1 * direction) % options.length; if (nextIndex < 0) nextIndex = options.length - 1; const newModelTitle = options[nextIndex].value; - dispatch(setDefaultModel({ title: newModelTitle })); + dispatch(setSelectedChatModel({ title: newModelTitle })); } }; @@ -199,7 +199,7 @@ function ModelSelect() { { if (val === defaultModel?.title) return; - dispatch(setDefaultModel({ title: val })); + dispatch(setSelectedChatModel({ title: val })); }} >
diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index e0d88dc12..649cb2684 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -1,5 +1,5 @@ import { - ArrowPathRoundedSquareIcon, + ArrowPathIcon, ArrowTopRightOnSquareIcon, BuildingOfficeIcon, ChevronDownIcon, @@ -291,6 +291,20 @@ export default function AssistantSelect() { +
+ Assistants +
{ + e.stopPropagation(); + refreshProfiles(); + buttonRef.current?.click(); + }} + > + +
+
+
@@ -314,8 +328,9 @@ export default function AssistantSelect() { }} /> -
+
login(false)} @@ -330,24 +345,6 @@ export default function AssistantSelect() { New Assistant
-
{ - e.stopPropagation(); - refreshProfiles(); - buttonRef.current?.click(); - }} - > - - - Refresh - -
void; @@ -115,7 +115,7 @@ function AddModelForm({ profileId: "local", }); - dispatch(setDefaultModel({ title: model.title, force: true })); + dispatch(setSelectedChatModel({ title: model.title, force: true })); onDone(); } diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 5b3e665ad..f840c49b4 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -11,7 +11,7 @@ import { } from "../redux"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { - selectDefaultModel, + selectSelectedChatModel, setConfigResult, } from "../redux/slices/configSlice"; import { updateIndexingStatus } from "../redux/slices/indexingSlice"; @@ -35,7 +35,7 @@ function useSetup() { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const history = useAppSelector((store) => store.session.history); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); const selectedProfileId = useAppSelector( (store) => store.profiles.selectedProfileId, ); diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index 682671cbb..ec195d9c9 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -31,7 +31,7 @@ import { useWebviewListener } from "../../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseHub } from "../../redux/selectors"; import { selectCurrentToolCall } from "../../redux/selectors/selectCurrentToolCall"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { submitEdit } from "../../redux/slices/editModeState"; import { newSession, @@ -105,7 +105,7 @@ export function Chat() { const showSessionTabs = useAppSelector( (store) => store.config.config.ui?.showSessionTabs, ); - const defaultModel = useAppSelector(selectDefaultModel); + const defaultModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); const [stepsOpen, setStepsOpen] = useState<(boolean | undefined)[]>([]); const mainTextInputRef = useRef(null); diff --git a/gui/src/pages/gui/StreamError.tsx b/gui/src/pages/gui/StreamError.tsx index 389528cd0..35fe3dc91 100644 --- a/gui/src/pages/gui/StreamError.tsx +++ b/gui/src/pages/gui/StreamError.tsx @@ -9,7 +9,7 @@ import { IdeMessengerContext } from "../../context/IdeMessenger"; import { selectSelectedProfile } from "../../redux/"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; import { selectUseHub } from "../../redux/selectors"; -import { selectDefaultModel } from "../../redux/slices/configSlice"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { isLocalProfile } from "../../util"; import { providers } from "../AddNewModel/configs/providers"; @@ -20,7 +20,7 @@ interface StreamErrorProps { const StreamErrorDialog = ({ error }: StreamErrorProps) => { const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); - const selectedModel = useAppSelector(selectDefaultModel); + const selectedModel = useAppSelector(selectSelectedChatModel); const hubEnabled = useAppSelector(selectUseHub); const selectedProfile = useAppSelector(selectSelectedProfile); const { session, refreshProfiles } = useAuth(); diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index 3092f01c5..c1528daa9 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -6,7 +6,6 @@ import { DEFAULT_MAX_TOKENS } from "core/llm/constants"; export type ConfigState = { configError: ConfigValidationError[] | undefined; config: BrowserSerializedContinueConfig; - defaultModelTitle?: string; }; const EMPTY_CONFIG: BrowserSerializedContinueConfig = { @@ -47,7 +46,6 @@ const EMPTY_CONFIG: BrowserSerializedContinueConfig = { const initialState: ConfigState = { configError: undefined, - defaultModelTitle: undefined, config: EMPTY_CONFIG, }; @@ -70,12 +68,8 @@ export const configSlice = createSlice({ // Don't invalidate the loaded config if (!config) { state.config = EMPTY_CONFIG; - state.defaultModelTitle = undefined; } else { state.config = config; - state.defaultModelTitle = - config.models.find((model) => model.title === state.defaultModelTitle) - ?.title || config.models[0]?.title; } }, updateConfig: ( @@ -84,63 +78,48 @@ export const configSlice = createSlice({ ) => { state.config = config; }, - setDefaultModel: ( + setSelectedChatModel: ( state, { payload }: PayloadAction<{ title: string; force?: boolean }>, ) => { - const model = state.config.models.find( + const model = state.config.modelsByRole["chat"].find( (model) => model.title === payload.title, ); + if (!model && !payload.force) return; - return { - ...state, - defaultModelTitle: payload.title, - }; - }, - cycleDefaultModel: (state, { payload }: PayloadAction<"next" | "prev">) => { - const currentIndex = state.config.models.findIndex( - (model) => model.title === state.defaultModelTitle, - ); - const nextIndex = - (currentIndex + - (payload === "next" ? 1 : -1) + - state.config.models.length) % - state.config.models.length; - return { - ...state, - defaultModelTitle: state.config.models[nextIndex].title, + + state.config = { + ...state.config, + selectedModelByRole: { + ...state.config.selectedModelByRole, + chat: model ?? null, + }, }; }, }, selectors: { - selectDefaultModel: (state) => { - return state.config.models.find( - (model) => model.title === state.defaultModelTitle, - ); - }, - selectDefaultModelContextLength: (state): number => { + selectSelectedChatModelContextLength: (state): number => { return ( - configSlice.getSelectors().selectDefaultModel(state)?.contextLength || + state.config.selectedModelByRole.chat?.contextLength || DEFAULT_MAX_TOKENS ); }, + selectSelectedChatModel: (state) => { + return state.config.selectedModelByRole.chat; + }, selectUIConfig: (state) => { return state.config?.ui ?? null; }, }, }); -export const { - setDefaultModel, - cycleDefaultModel, - updateConfig, - setConfigResult, -} = configSlice.actions; +export const { updateConfig, setConfigResult, setSelectedChatModel } = + configSlice.actions; export const { - selectDefaultModel, - selectDefaultModelContextLength, + selectSelectedChatModelContextLength, selectUIConfig, + selectSelectedChatModel, } = configSlice.selectors; export default configSlice.reducer; diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index 76b37b6fd..04d49007f 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -5,7 +5,7 @@ import { EditToolArgs } from "core/tools/definitions/editFile"; import { resolveRelativePathInDir } from "core/util/ideUtils"; import { IIdeMessenger } from "../../context/IdeMessenger"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { acceptToolCall, cancelToolCall, @@ -30,7 +30,7 @@ export const callTool = createAsyncThunk( return; } - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); if (!defaultModel) { throw new Error("No model selected"); } diff --git a/gui/src/redux/thunks/gatherContext.ts b/gui/src/redux/thunks/gatherContext.ts index 450471164..e810e1025 100644 --- a/gui/src/redux/thunks/gatherContext.ts +++ b/gui/src/redux/thunks/gatherContext.ts @@ -9,7 +9,7 @@ import { } from "core"; import * as URI from "uri-js"; import { resolveEditorContent } from "../../components/mainInput/TipTapEditor/utils"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { ThunkApiType } from "../store"; export const gatherContext = createAsyncThunk< @@ -37,7 +37,7 @@ export const gatherContext = createAsyncThunk< { dispatch, extra, getState }, ) => { const state = getState(); - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); const defaultContextProviders = state.config.config.experimental?.defaultContext ?? []; diff --git a/gui/src/redux/thunks/session.ts b/gui/src/redux/thunks/session.ts index b5ef0ac9a..413c3c678 100644 --- a/gui/src/redux/thunks/session.ts +++ b/gui/src/redux/thunks/session.ts @@ -3,7 +3,7 @@ import { ChatMessage, Session, SessionMetadata } from "core"; import { NEW_SESSION_TITLE } from "core/util/constants"; import { renderChatMessage } from "core/util/messageContent"; import { IIdeMessenger } from "../../context/IdeMessenger"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { deleteSessionMetadata, newSession, @@ -167,7 +167,7 @@ export const saveCurrentSession = createAsyncThunk< // Now save previous session and update chat title if relevant let title = state.session.title; if (title === NEW_SESSION_TITLE) { - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); if (!state.config.config?.disableSessionTitles && defaultModel) { let assistantResponse = state.session.history ?.filter((h) => h.message.role === "assistant")[0] diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index afc80fbe4..47cccff2d 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -3,13 +3,13 @@ import { ChatMessage } from "core"; import { modelSupportsTools } from "core/llm/autodetect"; import { ToCoreProtocol } from "core/protocol"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { abortStream, addPromptCompletionPair, selectUseTools, setToolGenerated, - streamUpdate + streamUpdate, } from "../slices/sessionSlice"; import { ThunkApiType } from "../store"; import { callTool } from "./callTool"; @@ -29,7 +29,7 @@ export const streamNormalInput = createAsyncThunk< ) => { // Gather state const state = getState(); - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); const toolSettings = state.ui.toolSettings; const toolGroupSettings = state.ui.toolGroupSettings; const streamAborter = state.session.streamAborter; diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index 9b802ffbb..e7c013fca 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -4,7 +4,7 @@ import { InputModifiers } from "core"; import { constructMessages } from "core/llm/constructMessages"; import posthog from "posthog-js"; import { v4 as uuidv4 } from "uuid"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { submitEditorAndInitAtIndex, updateHistoryItemAtIndex, @@ -34,7 +34,7 @@ export const streamResponseThunk = createAsyncThunk< await dispatch( streamThunkWrapper(async () => { const state = getState(); - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); const slashCommands = state.config.config.slashCommands || []; const inputIndex = index ?? state.session.history.length; // Either given index or concat to end diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 99554a628..8605d190d 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -2,7 +2,7 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { ChatMessage, ContextItem } from "core"; import { constructMessages } from "core/llm/constructMessages"; import { renderContextItems } from "core/util/messageContent"; -import { selectDefaultModel } from "../slices/configSlice"; +import { selectSelectedChatModel } from "../slices/configSlice"; import { addContextItemsAtIndex, setActive, @@ -27,7 +27,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< streamThunkWrapper(async () => { const state = getState(); const initialHistory = state.session.history; - const defaultModel = selectDefaultModel(state); + const defaultModel = selectSelectedChatModel(state); if (!defaultModel) { throw new Error("No model selected"); From e179bb73deacdd688c5711236558800dfb003f83 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 17:56:56 -0700 Subject: [PATCH 09/19] Update AssistantSelect.tsx --- gui/src/components/modelSelection/platform/AssistantSelect.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 649cb2684..71a10547e 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -99,7 +99,7 @@ const AssistantSelectOption = ({ fontSize: tinyFont, }} > -
+
From ea753e98d42ff6ed785d992e0bc4f380840edbaf Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 17:58:43 -0700 Subject: [PATCH 10/19] remove stale code --- .../continue/IdeProtocolClient.kt | 11 ----------- extensions/vscode/src/extension/VsCodeMessenger.ts | 4 +--- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt index 5f4316f8e..5bdb31cd4 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/IdeProtocolClient.kt @@ -504,17 +504,6 @@ class IdeProtocolClient( applyCodeBlockModel = selectedModels?.get("chat") as? Map<*, *> } - // If neither "apply" nor "chat" models are available in selectedModelByRole, - // fallback to modelsByRole.chat[0] - if (applyCodeBlockModel == null) { - val modelsByRole = config["modelsByRole"] as? Map<*, *> - val chatModels = modelsByRole?.get("chat") as? List<*> - if (chatModels != null && chatModels.isNotEmpty()) { - applyCodeBlockModel = chatModels[0] as? Map<*, *> - } - } - - if (applyCodeBlockModel != null) { continuation.resume(applyCodeBlockModel) } else { diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 910b33c1f..898e6eac2 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -180,9 +180,7 @@ export class VsCodeMessenger { } let llm = - config.selectedModelByRole.apply ?? - config.selectedModelByRole.chat ?? - config.modelsByRole.chat[0]; + config.selectedModelByRole.apply ?? config.selectedModelByRole.chat; if (!llm) { vscode.window.showErrorMessage( From eae1dd20bb296099db94175c43bf7af445e97200 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 18:47:29 -0700 Subject: [PATCH 11/19] feat: use thunj --- core/config/yaml/loadYaml.ts | 2 +- .../components/BestExperienceConfigForm.tsx | 15 +++-- .../tabs/OnboardingLocalTab.tsx | 16 ++--- .../mainInput/Lump/sections/ModelsSection.tsx | 24 +++----- .../components/modelSelection/ModelSelect.tsx | 45 +++++++++----- gui/src/forms/AddModelForm.tsx | 16 +++-- gui/src/redux/slices/configSlice.ts | 21 +------ gui/src/redux/thunks/index.ts | 1 + .../redux/thunks/updateSelectedModelByRole.ts | 58 +++++++++++++++++++ 9 files changed, 129 insertions(+), 69 deletions(-) create mode 100644 gui/src/redux/thunks/updateSelectedModelByRole.ts diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 1edb48604..1ad9fd2c6 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -157,7 +157,7 @@ async function configYamlToContinueConfig( summarize: [], }, selectedModelByRole: { - chat: null, // not currently used - defaultModel on GUI is used + chat: null, edit: null, // not currently used apply: null, embed: null, diff --git a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx index d05481dfb..d739a8434 100644 --- a/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx +++ b/gui/src/components/OnboardingCard/components/BestExperienceConfigForm.tsx @@ -1,11 +1,12 @@ import { CubeIcon } from "@heroicons/react/24/outline"; import { FormEventHandler, useContext, useState } from "react"; -import { useDispatch } from "react-redux"; import { Button, Input, InputSubtext, lightGray } from "../.."; +import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { models } from "../../../pages/AddNewModel/configs/models"; import { providers } from "../../../pages/AddNewModel/configs/providers"; -import { setSelectedChatModel } from "../../../redux/slices/configSlice"; +import { useAppDispatch } from "../../../redux/hooks"; +import { updateSelectedModelByRole } from "../../../redux/thunks"; import AddModelButtonSubtext from "../../AddModelButtonSubtext"; const { anthropic, mistral } = providers; @@ -25,7 +26,8 @@ interface BestExperienceConfigFormProps { function BestExperienceConfigForm({ onComplete, }: BestExperienceConfigFormProps) { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); + const { selectedProfile } = useAuth(); const ideMessenger = useContext(IdeMessengerContext); @@ -61,8 +63,13 @@ function BestExperienceConfigForm({ model: repoMapConfig, role: "repoMapFileSelection", }); + dispatch( - setSelectedChatModel({ title: chatModelConfig.title, force: true }), + updateSelectedModelByRole({ + selectedProfile, + role: "chat", + modelTitle: chatModelConfig.title, + }), ); if (!!autocompleteApiKey) { diff --git a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx index 54f036118..0f1e05da0 100644 --- a/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx +++ b/gui/src/components/OnboardingCard/tabs/OnboardingLocalTab.tsx @@ -6,11 +6,12 @@ import { LOCAL_ONBOARDING_PROVIDER_TITLE, } from "core/config/onboarding"; import { useContext, useEffect, useState } from "react"; -import { useDispatch } from "react-redux"; import { Button } from "../.."; +import { useAuth } from "../../../context/Auth"; import { IdeMessengerContext } from "../../../context/IdeMessenger"; -import { setSelectedChatModel } from "../../../redux/slices/configSlice"; +import { useAppDispatch } from "../../../redux/hooks"; import { setDialogMessage, setShowDialog } from "../../../redux/slices/uiSlice"; +import { updateSelectedModelByRole } from "../../../redux/thunks"; import AddModelButtonSubtext from "../../AddModelButtonSubtext"; import OllamaModelDownload from "../components/OllamaModelDownload"; import { OllamaStatus } from "../components/OllamaStatus"; @@ -23,13 +24,14 @@ interface OnboardingLocalTabProps { } function OnboardingLocalTab({ isDialog }: OnboardingLocalTabProps) { - const dispatch = useDispatch(); + const dispatch = useAppDispatch(); const ideMessenger = useContext(IdeMessengerContext); const { submitOnboarding } = useSubmitOnboarding("Local", isDialog); const [hasLoadedChatModel, setHasLoadedChatModel] = useState(false); const [downloadedOllamaModels, setDownloadedOllamaModels] = useState< string[] >([]); + const { selectedProfile } = useAuth(); const [isOllamaConnected, setIsOllamaConnected] = useState(false); @@ -135,11 +137,11 @@ function OnboardingLocalTab({ isDialog }: OnboardingLocalTabProps) { dispatch(setShowDialog(false)); } - // Set the selected model to the local chat model dispatch( - setSelectedChatModel({ - title: LOCAL_ONBOARDING_CHAT_TITLE, - force: true, // Because it doesn't exist in the webview's config object yet + updateSelectedModelByRole({ + selectedProfile, + role: "chat", + modelTitle: LOCAL_ONBOARDING_CHAT_TITLE, }), ); }} diff --git a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx index f6edc7400..b128db0a2 100644 --- a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx @@ -1,41 +1,31 @@ import { ModelRole } from "@continuedev/config-yaml"; import { ModelDescription } from "core"; -import { useContext } from "react"; import { useAuth } from "../../../../context/Auth"; -import { IdeMessengerContext } from "../../../../context/IdeMessenger"; import ModelRoleSelector from "../../../../pages/config/ModelRoleSelector"; import { useAppDispatch, useAppSelector } from "../../../../redux/hooks"; -import { updateConfig } from "../../../../redux/slices/configSlice"; +import { updateSelectedModelByRole } from "../../../../redux/thunks"; import { isJetBrains } from "../../../../util"; import { ExploreBlocksButton } from "./ExploreBlocksButton"; export function ModelsSection() { const { selectedProfile } = useAuth(); const dispatch = useAppDispatch(); - const ideMessenger = useContext(IdeMessengerContext); const config = useAppSelector((state) => state.config.config); const jetbrains = isJetBrains(); function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { - if (!selectedProfile) { + if (!model) { return; } - // Optimistic update + dispatch( - updateConfig({ - ...config, - selectedModelByRole: { - ...config.selectedModelByRole, - [role]: model, - }, + updateSelectedModelByRole({ + role, + selectedProfile, + modelTitle: model.title, }), ); - ideMessenger.post("config/updateSelectedModel", { - profileId: selectedProfile.id, - role, - title: model?.title ?? null, - }); } return ( diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index a6e7756ac..a25fd210d 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -6,18 +6,15 @@ import { PlusIcon, } from "@heroicons/react/24/outline"; import { useContext, useEffect, useRef, useState } from "react"; -import { useDispatch } from "react-redux"; import styled from "styled-components"; import { defaultBorderRadius, lightGray } from ".."; import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import AddModelForm from "../../forms/AddModelForm"; -import { useAppSelector } from "../../redux/hooks"; -import { - selectSelectedChatModel, - setSelectedChatModel, -} from "../../redux/slices/configSlice"; +import { useAppDispatch, useAppSelector } from "../../redux/hooks"; +import { selectSelectedChatModel } from "../../redux/slices/configSlice"; import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; +import { updateSelectedModelByRole } from "../../redux/thunks"; import { getMetaKeyLabel, isMetaEquivalentKeyPressed } from "../../util"; import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui"; @@ -122,8 +119,8 @@ function ModelOption({ } function ModelSelect() { - const dispatch = useDispatch(); - const defaultModel = useAppSelector(selectSelectedChatModel); + const dispatch = useAppDispatch(); + const selectedChatModel = useAppSelector(selectSelectedChatModel); const allModels = useAppSelector((state) => state.config.config.models); const buttonRef = useRef(null); const [options, setOptions] = useState([]); @@ -157,14 +154,25 @@ function ModelSelect() { useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "'" && isMetaEquivalentKeyPressed(event as any)) { + if (!selectedProfile) { + return; + } + const direction = event.shiftKey ? -1 : 1; const currentIndex = options.findIndex( - (option) => option.value === defaultModel?.title, + (option) => option.value === selectedChatModel?.title, ); let nextIndex = (currentIndex + 1 * direction) % options.length; if (nextIndex < 0) nextIndex = options.length - 1; const newModelTitle = options[nextIndex].value; - dispatch(setSelectedChatModel({ title: newModelTitle })); + + dispatch( + updateSelectedModelByRole({ + selectedProfile, + role: "chat", + modelTitle: newModelTitle, + }), + ); } }; @@ -172,7 +180,7 @@ function ModelSelect() { return () => { window.removeEventListener("keydown", handleKeyDown); }; - }, [options, defaultModel]); + }, [options, selectedChatModel]); function onClickAddModel(e: MouseEvent) { e.stopPropagation(); @@ -195,11 +203,16 @@ function ModelSelect() { } return ( - // Hiad sfasdfasdf asdfasdf { - if (val === defaultModel?.title) return; - dispatch(setSelectedChatModel({ title: val })); + if (val === selectedChatModel?.title) return; + dispatch( + updateSelectedModelByRole({ + selectedProfile, + role: "chat", + modelTitle: val, + }), + ); }} >
@@ -209,7 +222,7 @@ function ModelSelect() { className="h-[18px] gap-1 border-none text-gray-400" > - {modelSelectTitle(defaultModel) || "Select model"} + {modelSelectTitle(selectedChatModel) || "Select model"} ))}
diff --git a/gui/src/forms/AddModelForm.tsx b/gui/src/forms/AddModelForm.tsx index 259d7c1d3..94a26adbc 100644 --- a/gui/src/forms/AddModelForm.tsx +++ b/gui/src/forms/AddModelForm.tsx @@ -1,11 +1,11 @@ import { ArrowTopRightOnSquareIcon } from "@heroicons/react/24/outline"; import { useContext, useEffect, useState } from "react"; import { FormProvider, useForm } from "react-hook-form"; -import { useDispatch } from "react-redux"; import { Button, Input, InputSubtext, StyledActionButton } from "../components"; import AddModelButtonSubtext from "../components/AddModelButtonSubtext"; import Alert from "../components/gui/Alert"; import ModelSelectionListbox from "../components/modelSelection/ModelSelectionListbox"; +import { useAuth } from "../context/Auth"; import { IdeMessengerContext } from "../context/IdeMessenger"; import { completionParamsInputs } from "../pages/AddNewModel/configs/completionParamsInputs"; import { DisplayInfo } from "../pages/AddNewModel/configs/models"; @@ -13,7 +13,8 @@ import { ProviderInfo, providers, } from "../pages/AddNewModel/configs/providers"; -import { setSelectedChatModel } from "../redux/slices/configSlice"; +import { useAppDispatch } from "../redux/hooks"; +import { updateSelectedModelByRole } from "../redux/thunks"; import { FREE_TRIAL_LIMIT_REQUESTS, hasPassedFTL } from "../util/freeTrial"; interface QuickModelSetupProps { @@ -33,13 +34,14 @@ function AddModelForm({ const [selectedProvider, setSelectedProvider] = useState( providers["openai"]!, ); + const dispatch = useAppDispatch(); + const { selectedProfile } = useAuth(); const [selectedModel, setSelectedModel] = useState( selectedProvider.packages[0], ); const formMethods = useForm(); - const dispatch = useDispatch(); const ideMessenger = useContext(IdeMessengerContext); const popularProviderTitles = [ @@ -115,7 +117,13 @@ function AddModelForm({ profileId: "local", }); - dispatch(setSelectedChatModel({ title: model.title, force: true })); + dispatch( + updateSelectedModelByRole({ + selectedProfile, + role: "chat", + modelTitle: model.title, + }), + ); onDone(); } diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index c1528daa9..ca1856421 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -78,24 +78,6 @@ export const configSlice = createSlice({ ) => { state.config = config; }, - setSelectedChatModel: ( - state, - { payload }: PayloadAction<{ title: string; force?: boolean }>, - ) => { - const model = state.config.modelsByRole["chat"].find( - (model) => model.title === payload.title, - ); - - if (!model && !payload.force) return; - - state.config = { - ...state.config, - selectedModelByRole: { - ...state.config.selectedModelByRole, - chat: model ?? null, - }, - }; - }, }, selectors: { selectSelectedChatModelContextLength: (state): number => { @@ -113,8 +95,7 @@ export const configSlice = createSlice({ }, }); -export const { updateConfig, setConfigResult, setSelectedChatModel } = - configSlice.actions; +export const { updateConfig, setConfigResult } = configSlice.actions; export const { selectSelectedChatModelContextLength, diff --git a/gui/src/redux/thunks/index.ts b/gui/src/redux/thunks/index.ts index 59b556f8d..ad987fafa 100644 --- a/gui/src/redux/thunks/index.ts +++ b/gui/src/redux/thunks/index.ts @@ -5,3 +5,4 @@ export { streamNormalInput } from "./streamNormalInput"; export { streamResponseThunk } from "./streamResponse"; export { streamResponseAfterToolCall } from "./streamResponseAfterToolCall"; export { streamThunkWrapper } from "./streamThunkWrapper"; +export { updateSelectedModelByRole } from "./updateSelectedModelByRole"; diff --git a/gui/src/redux/thunks/updateSelectedModelByRole.ts b/gui/src/redux/thunks/updateSelectedModelByRole.ts new file mode 100644 index 000000000..8ad4f3df5 --- /dev/null +++ b/gui/src/redux/thunks/updateSelectedModelByRole.ts @@ -0,0 +1,58 @@ +import { ModelRole } from "@continuedev/config-yaml"; +import { createAsyncThunk } from "@reduxjs/toolkit"; +import { ProfileDescription } from "core/config/ProfileLifecycleManager"; +import { updateConfig } from "../slices/configSlice"; +import { ThunkApiType } from "../store"; + +export const updateSelectedModelByRole = createAsyncThunk< + void, + { + role: ModelRole; + modelTitle: string; + selectedProfile: ProfileDescription | null; + }, + ThunkApiType +>( + "config/updateSelectedModel", + async ( + { role, modelTitle, selectedProfile }, + { dispatch, extra, getState }, + ) => { + if (!selectedProfile) { + return; + } + + const state = getState(); + + const { + config: { config }, + } = state; + + const model = state.config.config.modelsByRole[role]?.find( + (m) => m.title === modelTitle, + ); + + if (!model) { + console.error( + `Model with title "${modelTitle}" not found for role "${role}"`, + ); + return; + } + + dispatch( + updateConfig({ + ...config, + selectedModelByRole: { + ...config.selectedModelByRole, + [role]: model, + }, + }), + ); + + extra.ideMessenger.post("config/updateSelectedModel", { + role, + profileId: selectedProfile.id, + title: modelTitle, + }); + }, +); From 7f8882eee136b90db9400175f9ee00fa1aa3ad93 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 19:28:48 -0700 Subject: [PATCH 12/19] feat: remove `models` property --- binary/test/binary.test.ts | 10 +-- core/config/ConfigHandler.test.ts | 4 +- core/config/ConfigHandler.ts | 27 -------- core/config/load.ts | 6 +- core/config/profile/doLoadConfig.ts | 2 +- core/config/selectedModels.ts | 2 +- core/config/util.ts | 2 +- core/config/yaml/loadYaml.ts | 16 ++--- .../providers/_context-providers.test.ts | 2 +- core/core.ts | 61 +++++++++++++++---- core/index.d.ts | 2 - core/llm/streamChat.ts | 13 ++-- .../OnboardingCard/OnboardingCard.tsx | 2 +- .../platform/PlatformOnboardingCard.tsx | 2 +- .../components/modelSelection/ModelSelect.tsx | 4 +- gui/src/hooks/useSetup.ts | 1 + gui/src/redux/slices/configSlice.ts | 1 - 17 files changed, 84 insertions(+), 73 deletions(-) diff --git a/binary/test/binary.test.ts b/binary/test/binary.test.ts index bd8504986..fb1be39bb 100644 --- a/binary/test/binary.test.ts +++ b/binary/test/binary.test.ts @@ -234,15 +234,17 @@ describe("Test Suite", () => { result: { config }, } = await messenger.request("config/getSerializedProfileInfo", undefined); - expect(config!.models.some((m) => m.title === model.title)).toBe(true); + expect(config!.modelsByRole.chat.some((m) => m.title === model.title)).toBe( + true, + ); await messenger.request("config/deleteModel", { title: model.title }); const { result: { config: configAfterDelete }, } = await messenger.request("config/getSerializedProfileInfo", undefined); - expect(configAfterDelete!.models.some((m) => m.title === model.title)).toBe( - false, - ); + expect( + configAfterDelete!.modelsByRole.chat.some((m) => m.title === model.title), + ).toBe(false); }); it("should make an LLM completion", async () => { diff --git a/core/config/ConfigHandler.test.ts b/core/config/ConfigHandler.test.ts index bf71952e9..4b4be0762 100644 --- a/core/config/ConfigHandler.test.ts +++ b/core/config/ConfigHandler.test.ts @@ -19,7 +19,9 @@ describe.skip("Test the ConfigHandler and E2E config loading", () => { test("should load the default config successfully", async () => { const result = await testConfigHandler.loadConfig(); - expect(result.config!.models.length).toBe(defaultConfig.models?.length); + expect(result.config!.modelsByRole.chat.length).toBe( + defaultConfig.models?.length, + ); }); test.skip("should add a system message from config.ts", async () => { diff --git a/core/config/ConfigHandler.ts b/core/config/ConfigHandler.ts index 2d4a471d5..6fa6e4204 100644 --- a/core/config/ConfigHandler.ts +++ b/core/config/ConfigHandler.ts @@ -11,17 +11,11 @@ import { IContextProvider, IDE, IdeSettings, - ILLM, ILLMLogger, } from "../index.js"; -import Ollama from "../llm/llms/Ollama.js"; import { GlobalContext } from "../util/GlobalContext.js"; import { getAllAssistantFiles } from "./loadLocalAssistants.js"; -import { - LOCAL_ONBOARDING_CHAT_MODEL, - LOCAL_ONBOARDING_PROVIDER_TITLE, -} from "./onboarding.js"; import ControlPlaneProfileLoader from "./profile/ControlPlaneProfileLoader.js"; import LocalProfileLoader from "./profile/LocalProfileLoader.js"; import PlatformProfileLoader from "./profile/PlatformProfileLoader.js"; @@ -473,27 +467,6 @@ export class ConfigHandler { } } - // Only used till we move to using selectedModelByRole.chat - async llmFromTitle(title?: string): Promise { - const { config } = await this.loadConfig(); - const model = config?.models.find((m) => m.title === title); - if (!model) { - if (title === LOCAL_ONBOARDING_PROVIDER_TITLE) { - // Special case, make calls to Ollama before we have it in the config - const ollama = new Ollama({ - model: LOCAL_ONBOARDING_CHAT_MODEL, - }); - return ollama; - } else if (config?.models?.length) { - return config?.models[0]; - } - - throw new Error("No model found"); - } - - return model; - } - // Ancient method of adding custom providers through vs code private additionalContextProviders: IContextProvider[] = []; registerCustomContextProvider(contextProvider: IContextProvider) { diff --git a/core/config/load.ts b/core/config/load.ts index ed7164681..8575206ad 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -504,7 +504,6 @@ async function intermediateToFinalConfig( const continueConfig: ContinueConfig = { ...config, contextProviders, - models, tools: [...allTools], mcpServerStatuses: [], slashCommands: config.slashCommands ?? [], @@ -544,7 +543,7 @@ async function intermediateToFinalConfig( // Handle experimental modelRole config values for apply and edit const inlineEditModel = getModelByRole(continueConfig, "inlineEdit")?.title; if (inlineEditModel) { - const match = continueConfig.models.find( + const match = continueConfig.modelsByRole.chat.find( (m) => m.title === inlineEditModel, ); if (match) { @@ -563,7 +562,7 @@ async function intermediateToFinalConfig( "applyCodeBlock", )?.title; if (applyBlockModel) { - const match = continueConfig.models.find( + const match = continueConfig.modelsByRole.chat.find( (m) => m.title === applyBlockModel, ); if (match) { @@ -617,7 +616,6 @@ async function finalToBrowserConfig( ): Promise { return { allowAnonymousTelemetry: final.allowAnonymousTelemetry, - models: final.models.map(llmToSerializedModelDescription), systemMessage: final.systemMessage, completionOptions: final.completionOptions, slashCommands: final.slashCommands?.map( diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 626546b74..2957ca9d6 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -258,7 +258,7 @@ async function injectControlPlaneProxyInfo( } }); - config.models.forEach((model) => { + config.modelsByRole.chat.forEach((model) => { if (model.providerName === "continue-proxy") { (model as ContinueProxy).controlPlaneProxyInfo = info; } diff --git a/core/config/selectedModels.ts b/core/config/selectedModels.ts index 20dfb5063..42b966cf7 100644 --- a/core/config/selectedModels.ts +++ b/core/config/selectedModels.ts @@ -56,7 +56,7 @@ export function rectifySelectedModelsFromGlobalContext( role === "apply" && newModel?.getConfigurationStatus() !== LLMConfigurationStatuses.VALID ) { - break; + continue; } configCopy.selectedModelByRole[role] = newModel; diff --git a/core/config/util.ts b/core/config/util.ts index ee827c2f9..957e6c6ff 100644 --- a/core/config/util.ts +++ b/core/config/util.ts @@ -94,7 +94,7 @@ export function getModelByRole( return undefined; } - const matchingModel = config.models.find( + const matchingModel = config.modelsByRole.chat.find( (model) => model.title === roleTitle, ); diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 1ad9fd2c6..ff6fb8212 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -125,7 +125,6 @@ async function configYamlToContinueConfig( const localErrors: ConfigValidationError[] = []; const continueConfig: ContinueConfig = { slashCommands: [], - models: [], tools: [...allTools], mcpServerStatuses: [], systemMessage: undefined, @@ -222,10 +221,6 @@ async function configYamlToContinueConfig( config: continueConfig, }); - if (modelsArrayRoles.some((role) => model.roles?.includes(role))) { - continueConfig.models.push(...llms); - } - if (model.roles?.includes("chat")) { continueConfig.modelsByRole.chat.push(...llms); } @@ -323,7 +318,7 @@ async function configYamlToContinueConfig( if (allowFreeTrial) { // Obtain auth token (iff free trial being used) - const freeTrialModels = continueConfig.models.filter( + const freeTrialModels = continueConfig.modelsByRole.chat.filter( (model) => model.providerName === "free-trial", ); if (freeTrialModels.length > 0) { @@ -338,14 +333,15 @@ async function configYamlToContinueConfig( message: `Failed to obtain GitHub auth token for free trial:\n${e instanceof Error ? e.message : e}`, }); // Remove free trial models - continueConfig.models = continueConfig.models.filter( - (model) => model.providerName !== "free-trial", - ); + continueConfig.modelsByRole.chat = + continueConfig.modelsByRole.chat.filter( + (model) => model.providerName !== "free-trial", + ); } } } else { // Remove free trial models - continueConfig.models = continueConfig.models.filter( + continueConfig.modelsByRole.chat = continueConfig.modelsByRole.chat.filter( (model) => model.providerName !== "free-trial", ); } diff --git a/core/context/providers/_context-providers.test.ts b/core/context/providers/_context-providers.test.ts index d8eb90ef9..468aac6ec 100644 --- a/core/context/providers/_context-providers.test.ts +++ b/core/context/providers/_context-providers.test.ts @@ -45,7 +45,7 @@ async function getContextProviderExtras( config, embeddingsProvider: config.selectedModelByRole.embed, fetch: fetch, - llm: config.models[0], + llm: config.modelsByRole.chat[0], reranker: config.selectedModelByRole.rerank, selectedCode: [], }; diff --git a/core/core.ts b/core/core.ts index e929a863b..9bdf00750 100644 --- a/core/core.ts +++ b/core/core.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-lines-per-function */ import { fetchwithRequestOptions } from "@continuedev/fetch"; import * as URI from "uri-js"; import { v4 as uuidv4 } from "uuid"; @@ -60,7 +61,13 @@ async function* streamDiffLinesGenerator( msg: Message, ): AsyncGenerator { const data = msg.data; - const llm = await configHandler.llmFromTitle(msg.data.modelTitle); + const llm = (await configHandler.loadConfig()).config?.selectedModelByRole + .chat; + + if (!llm) { + throw new Error("No chat model selected"); + } + for await (const diffLine of streamDiffLines( data.prefix, data.highlighted, @@ -430,7 +437,13 @@ export class Core { ); on("llm/complete", async (msg) => { - const model = await this.configHandler.llmFromTitle(msg.data.title); + const model = (await this.configHandler.loadConfig()).config + ?.selectedModelByRole.chat; + + if (!model) { + throw new Error("No chat model selected"); + } + const completion = await model.complete( msg.data.prompt, new AbortController().signal, @@ -449,9 +462,13 @@ export class Core { }); on("chatDescriber/describe", async (msg) => { - const currentModel = await this.configHandler.llmFromTitle( - msg.data.selectedModelTitle, - ); + const currentModel = (await this.configHandler.loadConfig()).config + ?.selectedModelByRole.chat; + + if (!currentModel) { + throw new Error("No chat model selected"); + } + return await ChatDescriber.describe(currentModel, {}, msg.data.text); }); @@ -681,7 +698,12 @@ export class Core { throw new Error(`Tool ${toolCall.function.name} not found`); } - const llm = await this.configHandler.llmFromTitle(selectedModelTitle); + const llm = (await this.configHandler.loadConfig()).config + ?.selectedModelByRole.chat; + + if (!llm) { + throw new Error("No chat model selected"); + } const contextItems = await callTool( tool, @@ -711,7 +733,12 @@ export class Core { return false; } - const llm = await this.configHandler.llmFromTitle(selectedModelTitle); + const llm = (await this.configHandler.loadConfig()).config + ?.selectedModelByRole.chat; + + if (!llm) { + throw new Error("No chat model selected"); + } // Count the size of the file tokenwise const tokens = countTokens(item.content); @@ -789,8 +816,13 @@ export class Core { } const model = - config.models.find((model) => model.title === msg.data.title) ?? - config.models.find((model) => model.title?.startsWith(msg.data.title)); + config.modelsByRole.chat.find( + (model) => model.title === msg.data.title, + ) ?? + config.modelsByRole.chat.find((model) => + model.title?.startsWith(msg.data.title), + ); + try { if (model) { return await model.listModels(); @@ -854,10 +886,15 @@ export class Core { return []; } - const { name, query, fullInput, selectedCode, selectedModelTitle } = - msg.data; + const { name, query, fullInput, selectedCode } = msg.data; + + const llm = (await this.configHandler.loadConfig()).config + ?.selectedModelByRole.chat; + + if (!llm) { + throw new Error("No chat model selected"); + } - const llm = await this.configHandler.llmFromTitle(selectedModelTitle); const provider = config.contextProviders?.find( (provider) => provider.description.title === name, diff --git a/core/index.d.ts b/core/index.d.ts index d951da60d..f81f14262 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1393,7 +1393,6 @@ export interface Config { // in the actual Continue source code export interface ContinueConfig { allowAnonymousTelemetry?: boolean; - models: ILLM[]; systemMessage?: string; completionOptions?: BaseCompletionOptions; requestOptions?: RequestOptions; @@ -1417,7 +1416,6 @@ export interface ContinueConfig { export interface BrowserSerializedContinueConfig { allowAnonymousTelemetry?: boolean; - models: ModelDescription[]; systemMessage?: string; completionOptions?: BaseCompletionOptions; requestOptions?: RequestOptions; diff --git a/core/llm/streamChat.ts b/core/llm/streamChat.ts index 9b1ea87b3..223b5b20e 100644 --- a/core/llm/streamChat.ts +++ b/core/llm/streamChat.ts @@ -23,19 +23,22 @@ export async function* llmStreamChat( void TTS.kill(); } - const { title, legacySlashCommandData, completionOptions, messages } = - msg.data; + const { legacySlashCommandData, completionOptions, messages } = msg.data; - const model = await configHandler.llmFromTitle(title); + const model = config.selectedModelByRole.chat; + + if (!model) { + throw new Error("No chat model selected"); + } // Log to return in case of error const errorPromptLog = { - modelTitle: model.title ?? model.model, + modelTitle: model?.title ?? model?.model, completion: "", prompt: "", completionOptions: { ...msg.data.completionOptions, - model: model.model, + model: model?.model, }, }; diff --git a/gui/src/components/OnboardingCard/OnboardingCard.tsx b/gui/src/components/OnboardingCard/OnboardingCard.tsx index a4baa9a1e..aa8be2a29 100644 --- a/gui/src/components/OnboardingCard/OnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/OnboardingCard.tsx @@ -37,7 +37,7 @@ export function OnboardingCard({ isDialog }: OnboardingCardProps) { return ( onboardingCard.close()} testId="onboarding-card" > diff --git a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx index 4c0deda74..daa064ea2 100644 --- a/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx +++ b/gui/src/components/OnboardingCard/platform/PlatformOnboardingCard.tsx @@ -28,7 +28,7 @@ export function PlatformOnboardingCard({ isDialog }: OnboardingCardProps) { return ( onboardingCard.close()} >
diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index a25fd210d..df0b5dc58 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -121,7 +121,9 @@ function ModelOption({ function ModelSelect() { const dispatch = useAppDispatch(); const selectedChatModel = useAppSelector(selectSelectedChatModel); - const allModels = useAppSelector((state) => state.config.config.models); + const allModels = useAppSelector( + (state) => state.config.config.modelsByRole.chat, + ); const buttonRef = useRef(null); const [options, setOptions] = useState([]); const [sortedOptions, setSortedOptions] = useState([]); diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index f840c49b4..67880839e 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -50,6 +50,7 @@ function useSetup() { organizations, selectedOrgId, } = result; + debugger; if (isInitial && hasDoneInitialConfigLoad.current) { return; } diff --git a/gui/src/redux/slices/configSlice.ts b/gui/src/redux/slices/configSlice.ts index ca1856421..9c33ec3ff 100644 --- a/gui/src/redux/slices/configSlice.ts +++ b/gui/src/redux/slices/configSlice.ts @@ -20,7 +20,6 @@ const EMPTY_CONFIG: BrowserSerializedContinueConfig = { }, ], contextProviders: [], - models: [], tools: [], mcpServerStatuses: [], usePlatform: true, From 045c6bdfec45ffadb25b3db2306b78f34780e84b Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 19:31:44 -0700 Subject: [PATCH 13/19] feat: model name update --- extensions/vscode/package-lock.json | 2 +- gui/src/components/modelSelection/ModelSelect.tsx | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index efc342f19..19b4e5384 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -106,7 +106,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.71", + "@continuedev/config-yaml": "^1.0.77", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index df0b5dc58..aa84f9f33 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -121,7 +121,7 @@ function ModelOption({ function ModelSelect() { const dispatch = useAppDispatch(); const selectedChatModel = useAppSelector(selectSelectedChatModel); - const allModels = useAppSelector( + const allChatModels = useAppSelector( (state) => state.config.config.modelsByRole.chat, ); const buttonRef = useRef(null); @@ -141,7 +141,7 @@ function ModelSelect() { useEffect(() => { setOptions( - allModels + allChatModels .filter((m) => !m.roles || m.roles.includes("chat")) .map((model) => { return { @@ -151,7 +151,7 @@ function ModelSelect() { }; }), ); - }, [allModels]); + }, [allChatModels]); useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { From 96863db15ca71965f6c4784e8603155755a01921 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 21:35:45 -0700 Subject: [PATCH 14/19] remove default model title --- core/protocol/ideWebview.ts | 1 - core/protocol/passThrough.ts | 1 - .../constants/MessageTypes.kt | 1 - .../continue/CoreMessenger.kt | 15 ---- extensions/vscode/package-lock.json | 2 +- extensions/vscode/src/commands.ts | 21 +++-- .../vscode/src/diff/vertical/manager.ts | 15 ++-- .../vscode/src/extension/VsCodeMessenger.ts | 14 +++- .../src/quickEdit/ModelSelectionQuickPick.ts | 32 -------- .../src/quickEdit/QuickEditQuickPick.ts | 77 ++++--------------- .../vscode/src/test/test-suites/main.test.ts | 28 ------- .../StepContainerPreToolbar.tsx | 1 + gui/src/hooks/useSetup.ts | 14 ---- gui/src/pages/config/ModelRoleSelector.tsx | 12 ++- gui/src/pages/gui/Chat.tsx | 1 - manual-testing-sandbox/test.js | 1 - manual-testing-sandbox/test.kt | 1 + 17 files changed, 55 insertions(+), 182 deletions(-) delete mode 100644 extensions/vscode/src/quickEdit/ModelSelectionQuickPick.ts delete mode 100644 extensions/vscode/src/test/test-suites/main.test.ts diff --git a/core/protocol/ideWebview.ts b/core/protocol/ideWebview.ts index 47c28680c..b477fcce9 100644 --- a/core/protocol/ideWebview.ts +++ b/core/protocol/ideWebview.ts @@ -51,7 +51,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & { { prompt: MessageContent; range: RangeInFileWithContents; - selectedModelTitle: string; }, void, ]; diff --git a/core/protocol/passThrough.ts b/core/protocol/passThrough.ts index 9564f557d..1d854f948 100644 --- a/core/protocol/passThrough.ts +++ b/core/protocol/passThrough.ts @@ -68,7 +68,6 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] = export const CORE_TO_WEBVIEW_PASS_THROUGH: (keyof ToWebviewFromCoreProtocol)[] = [ "configUpdate", - "getDefaultModelTitle", "indexProgress", // Codebase "indexing/statusUpdate", // Docs, etc. "addContextItem", diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt index 5d17fbe6c..100ee2aad 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/constants/MessageTypes.kt @@ -60,7 +60,6 @@ class MessageTypes { // core/protocol/passThrough.ts val PASS_THROUGH_TO_WEBVIEW = listOf( "configUpdate", - "getDefaultModelTitle", "indexProgress", // Codebase "indexing/statusUpdate", // Docs, etc. "addContextItem", diff --git a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt index 4378d273d..cbcee8e98 100644 --- a/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt +++ b/extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/CoreMessenger.kt @@ -65,21 +65,6 @@ class CoreMessenger( // Forward to webview if (MessageTypes.PASS_THROUGH_TO_WEBVIEW.contains(messageType)) { - // TODO: Currently we aren't set up to receive a response back from the webview - // Can circumvent for getDefaultsModelTitle here for now - if (messageType == "getDefaultModelTitle") { - val continueSettingsService = service() - val defaultModelTitle = continueSettingsService.continueState.lastSelectedInlineEditModel - val message = - gson.toJson( - mapOf( - "messageId" to messageId, - "messageType" to messageType, - "data" to defaultModelTitle - ) - ) - write(message) - } val continuePluginService = project.service() continuePluginService.sendToWebview(messageType, responseMap["data"], messageType) } diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 19b4e5384..efc342f19 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -106,7 +106,7 @@ "@aws-sdk/client-sagemaker-runtime": "^3.777.0", "@aws-sdk/credential-providers": "^3.778.0", "@continuedev/config-types": "^1.0.13", - "@continuedev/config-yaml": "^1.0.77", + "@continuedev/config-yaml": "^1.0.71", "@continuedev/fetch": "^1.0.4", "@continuedev/llm-info": "^1.0.8", "@continuedev/openai-adapters": "^1.0.18", diff --git a/extensions/vscode/src/commands.ts b/extensions/vscode/src/commands.ts index 9009d2b58..719c1a5d1 100644 --- a/extensions/vscode/src/commands.ts +++ b/extensions/vscode/src/commands.ts @@ -12,7 +12,10 @@ import { ConfigHandler } from "core/config/ConfigHandler"; import { ContinueServerClient } from "core/continueServer/stubs/client"; import { EXTENSION_NAME } from "core/control-plane/env"; import { Core } from "core/core"; +import { LOCAL_DEV_DATA_VERSION } from "core/data/log"; import { walkDirAsync } from "core/indexing/walkDir"; +import { isModelInstaller } from "core/llm"; +import { startLocalOllama } from "core/util/ollamaHelper"; import { getDevDataFilePath } from "core/util/paths"; import { Telemetry } from "core/util/posthog"; import readLastLines from "read-last-lines"; @@ -29,7 +32,6 @@ import { } from "./autocomplete/statusBar"; import { ContinueConsoleWebviewViewProvider } from "./ContinueConsoleWebviewViewProvider"; import { ContinueGUIWebviewViewProvider } from "./ContinueGUIWebviewViewProvider"; - import { VerticalDiffManager } from "./diff/vertical/manager"; import EditDecorationManager from "./quickEdit/EditDecorationManager"; import { QuickEdit, QuickEditShowParams } from "./quickEdit/QuickEditQuickPick"; @@ -37,9 +39,6 @@ import { Battery } from "./util/battery"; import { getMetaKeyLabel } from "./util/util"; import { VsCodeIde } from "./VsCodeIde"; -import { LOCAL_DEV_DATA_VERSION } from "core/data/log"; -import { isModelInstaller } from "core/llm"; -import { startLocalOllama } from "core/util/ollamaHelper"; import type { VsCodeWebviewProtocol } from "./webviewProtocol"; let fullScreenPanel: vscode.WebviewPanel | undefined; @@ -364,18 +363,18 @@ const getCommandsMap: ( throw new Error("Config not loaded"); } - const modelTitle = - config.selectedModelByRole.edit?.title ?? - (await sidebar.webviewProtocol.request( - "getDefaultModelTitle", - undefined, - )); + const llm = + config.selectedModelByRole.edit ?? config.selectedModelByRole.chat; + + if (!llm) { + throw new Error("No edit or chat model selected"); + } void sidebar.webviewProtocol.request("incrementFtc", undefined); await verticalDiffManager.streamEdit( config.experimental?.contextMenuPrompts?.[promptName] ?? fallbackPrompt, - modelTitle, + llm, undefined, onlyOneInsertion, undefined, diff --git a/extensions/vscode/src/diff/vertical/manager.ts b/extensions/vscode/src/diff/vertical/manager.ts index 4d4256a1f..48741a142 100644 --- a/extensions/vscode/src/diff/vertical/manager.ts +++ b/extensions/vscode/src/diff/vertical/manager.ts @@ -1,4 +1,4 @@ -import { ChatMessage, DiffLine } from "core"; +import { ChatMessage, DiffLine, ILLM } from "core"; import { ConfigHandler } from "core/config/ConfigHandler"; import { streamDiffLines } from "core/edit/streamDiffLines"; import { pruneLinesFromBottom, pruneLinesFromTop } from "core/llm/countTokens"; @@ -7,9 +7,9 @@ import * as URI from "uri-js"; import * as vscode from "vscode"; import EditDecorationManager from "../../quickEdit/EditDecorationManager"; +import { handleLLMError } from "../../util/errorHandling"; import { VsCodeWebviewProtocol } from "../../webviewProtocol"; -import { handleLLMError } from "../../util/errorHandling"; import { VerticalDiffHandler, VerticalDiffHandlerOptions } from "./handler"; export interface VerticalDiffCodeLens { @@ -272,7 +272,7 @@ export class VerticalDiffManager { async streamEdit( input: string, - modelTitle: string | undefined, + llm: ILLM, streamId?: string, onlyOneInsertion?: boolean, quickEdit?: string, @@ -308,13 +308,13 @@ export class VerticalDiffManager { // Previous diff was a quickEdit // Check if user has highlighted a range let rangeBool = - startLine != endLine || - editor.selection.start.character != editor.selection.end.character; + startLine !== endLine || + editor.selection.start.character !== editor.selection.end.character; // Check if the range is different from the previous range let newRangeBool = - startLine != existingHandler.range.start.line || - endLine != existingHandler.range.end.line; + startLine !== existingHandler.range.start.line || + endLine !== existingHandler.range.end.line; if (!rangeBool || !newRangeBool) { // User did not highlight a new range -> use start/end from the previous quickEdit @@ -374,7 +374,6 @@ export class VerticalDiffManager { ); } - const llm = await this.configHandler.llmFromTitle(modelTitle); const rangeContent = editor.document.getText(selectedRange); const prefix = pruneLinesFromTop( editor.document.getText( diff --git a/extensions/vscode/src/extension/VsCodeMessenger.ts b/extensions/vscode/src/extension/VsCodeMessenger.ts index 898e6eac2..591c82454 100644 --- a/extensions/vscode/src/extension/VsCodeMessenger.ts +++ b/extensions/vscode/src/extension/VsCodeMessenger.ts @@ -223,7 +223,7 @@ export class VsCodeMessenger { await verticalDiffManager.streamEdit( prompt, - llm.title, + llm, data.streamId, undefined, undefined, @@ -286,9 +286,19 @@ export class VsCodeMessenger { const { start, end } = msg.data.range.range; const verticalDiffManager = await verticalDiffManagerPromise; + const configHandler = await configHandlerPromise; + const { config } = await configHandler.loadConfig(); + + const model = + config?.selectedModelByRole.edit ?? config?.selectedModelByRole.chat; + + if (!model) { + throw new Error("No Edit or Chat model selected"); + } + const fileAfterEdit = await verticalDiffManager.streamEdit( stripImages(prompt), - msg.data.selectedModelTitle, + model, "edit", undefined, undefined, diff --git a/extensions/vscode/src/quickEdit/ModelSelectionQuickPick.ts b/extensions/vscode/src/quickEdit/ModelSelectionQuickPick.ts deleted file mode 100644 index d46ed6d43..000000000 --- a/extensions/vscode/src/quickEdit/ModelSelectionQuickPick.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { ContinueConfig } from "core"; -import { QuickPickItem, window } from "vscode"; - -export async function getModelQuickPickVal( - curModelTitle: string, - config: ContinueConfig, -) { - const modelItems: QuickPickItem[] = config.models.map((model) => { - const isCurModel = curModelTitle === model.title; - - return { - label: model.title - ? `${isCurModel ? "$(check)" : " "} ${model.title}` - : "Model title not set", - }; - }); - - const selectedItem = await window.showQuickPick(modelItems, { - title: "Models", - placeHolder: "Select a model", - }); - - if (!selectedItem) { - return undefined; - } - - const selectedModelTitle = config.models.find( - (model) => model.title && selectedItem.label.includes(model.title), - )?.title; - - return selectedModelTitle; -} diff --git a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts index ec84eb81b..e0c826fb1 100644 --- a/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts +++ b/extensions/vscode/src/quickEdit/QuickEditQuickPick.ts @@ -1,6 +1,7 @@ /* eslint-disable @typescript-eslint/naming-convention */ -import { IDE } from "core"; +import { IDE, ILLM } from "core"; import { ConfigHandler } from "core/config/ConfigHandler"; +import { DataLogger } from "core/data/log"; import { Telemetry } from "core/util/posthog"; import * as vscode from "vscode"; @@ -8,10 +9,8 @@ import { VerticalDiffManager } from "../diff/vertical/manager"; import { FileSearch } from "../util/FileSearch"; import { VsCodeWebviewProtocol } from "../webviewProtocol"; -import { DataLogger } from "core/data/log"; import { getContextProviderQuickPickVal } from "./ContextProvidersQuickPick"; import { appendToHistory, getHistoryQuickPickVal } from "./HistoryQuickPick"; -import { getModelQuickPickVal } from "./ModelSelectionQuickPick"; // @ts-ignore - error finding typings // @ts-ignore @@ -23,7 +22,6 @@ import { getModelQuickPickVal } from "./ModelSelectionQuickPick"; enum QuickEditInitialItemLabels { History = "History", ContextProviders = "Context providers", - Model = "Model", Submit = "Submit", } @@ -100,11 +98,6 @@ export class QuickEdit { */ private contextProviderStr?: string; - /** - * Stores the current model title for potential changes - */ - private _curModelTitle?: string; - constructor( private readonly verticalDiffManager: VerticalDiffManager, private readonly configHandler: ConfigHandler, @@ -224,7 +217,7 @@ export class QuickEdit { default: break; } - let model = await this.getCurModelTitle(); + let model = await this.getCurModel(); void DataLogger.getInstance().logDevData({ name: "quickEdit", @@ -233,7 +226,7 @@ export class QuickEdit { path, label, diffs: this.verticalDiffManager.logDiffs, - model, + model: model?.title, }, }); @@ -245,12 +238,12 @@ export class QuickEdit { prompt: string, path: string | undefined, ) => { - const modelTitle = await this.getCurModelTitle(); - if (!modelTitle) { + const model = await this.getCurModel(); + if (!model) { throw new Error("No model selected"); } - await this._streamEditWithInputAndContext(prompt, modelTitle); + await this._streamEditWithInputAndContext(prompt, model); this.openAcceptRejectMenu(prompt, path); }; @@ -266,25 +259,13 @@ export class QuickEdit { /** * Gets the model title the user has chosen, or their default model */ - private async getCurModelTitle(): Promise { - if (this._curModelTitle) { - return this._curModelTitle; - } - + private async getCurModel(): Promise { const { config } = await this.configHandler.loadConfig(); if (!config) { - return undefined; + return null; } - return ( - config.selectedModelByRole.edit?.title ?? - (await this.webviewProtocol.request( - "getDefaultModelTitle", - undefined, - false, - )) ?? - config.models[0]?.title - ); + return config.selectedModelByRole.edit ?? config.selectedModelByRole.chat; } /** @@ -314,10 +295,7 @@ export class QuickEdit { }`; }; - private async _streamEditWithInputAndContext( - prompt: string, - modelTitle: string, - ) { + private async _streamEditWithInputAndContext(prompt: string, model: ILLM) { // Extracts all file references from the prompt string, // which are denoted by an '@' symbol followed by // one or more non-whitespace characters. @@ -343,7 +321,7 @@ export class QuickEdit { await this.verticalDiffManager.streamEdit( prompt, - modelTitle, + model, undefined, undefined, this.previousInput, @@ -351,7 +329,7 @@ export class QuickEdit { ); } - private getInitialItems(modelTitle: string): vscode.QuickPickItem[] { + private getInitialItems(): vscode.QuickPickItem[] { return [ { label: QuickEditInitialItemLabels.History, @@ -361,10 +339,6 @@ export class QuickEdit { label: QuickEditInitialItemLabels.ContextProviders, detail: "$(add) Add context to your prompt", }, - { - label: QuickEditInitialItemLabels.Model, - detail: `$(chevron-down) ${modelTitle}`, - }, ]; } @@ -372,7 +346,7 @@ export class QuickEdit { label: QuickEditInitialItemLabels | undefined; value: string | undefined; }> { - const modelTitle = await this.getCurModelTitle(); + const modelTitle = await this.getCurModel(); if (!modelTitle) { this.ide.showToast("error", "Please configure a model to use Quick Edit"); @@ -381,7 +355,7 @@ export class QuickEdit { const quickPick = vscode.window.createQuickPick(); - const initialItems = this.getInitialItems(modelTitle); + const initialItems = this.getInitialItems(); quickPick.items = initialItems; quickPick.placeholder = "Enter a prompt to edit your code (@ to search files, ⏎ to submit)"; @@ -552,27 +526,6 @@ export class QuickEdit { break; - case QuickEditInitialItemLabels.Model: - const curModelTitle = await this.getCurModelTitle(); - - if (!curModelTitle) { - break; - } - - const selectedModelTitle = await getModelQuickPickVal( - curModelTitle, - config, - ); - - if (selectedModelTitle) { - this._curModelTitle = selectedModelTitle; - } - - // Recurse back to let the user write their prompt - this.initiateNewQuickPick(editor, params); - - break; - case QuickEditInitialItemLabels.Submit: if (selectedValue) { prompt = selectedValue; diff --git a/extensions/vscode/src/test/test-suites/main.test.ts b/extensions/vscode/src/test/test-suites/main.test.ts deleted file mode 100644 index 2cd1945fa..000000000 --- a/extensions/vscode/src/test/test-suites/main.test.ts +++ /dev/null @@ -1,28 +0,0 @@ -import assert from "node:assert"; - -import { describe, test } from "mocha"; -import * as vscode from "vscode"; - -import { VsCodeExtension } from "../../extension/VsCodeExtension"; - -describe("Extension Test Suite", () => { - vscode.window.showInformationMessage("Start all tests."); - - // test("Make sure that nothing breaks after 10 seconds", async () => { - // await new Promise((resolve) => setTimeout(resolve, 10_000)); - // }); - - test("Get the default model from webview", async () => { - const continueExtensionApi = - vscode.extensions.getExtension("continue.continue"); - const extension: VsCodeExtension = continueExtensionApi?.exports.extension; - await new Promise((resolve) => setTimeout(resolve, 400)); - await vscode.commands.executeCommand("continue.focusContinueInput"); - await new Promise((resolve) => setTimeout(resolve, 400)); - const title = await ( - await extension.webviewProtocolPromise - ).request("getDefaultModelTitle", undefined); - assert.strictEqual(typeof title, "string"); - assert.strictEqual(title, "Test Model"); - }); -}); diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index ed4a7ea47..0571913b6 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -31,6 +31,7 @@ const TopDiv = styled.div` outline-offset: -0.5px; border-radius: ${defaultBorderRadius}; margin-bottom: 8px !important; + margin-top: 8px !important; background-color: ${vscEditorBackground}; min-width: 0; `; diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 67880839e..3f65ecfa3 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -254,26 +254,12 @@ function useSetup() { dispatch(updateIndexingStatus(data)); }); - useWebviewListener( - "getDefaultModelTitle", - async () => { - return defaultModel?.title; - }, - [defaultModel], - ); - const activeToolStreamId = useAppSelector( (store) => store.session.activeToolStreamId, ); useWebviewListener( "updateApplyState", async (state) => { - // dispatch( - // updateCurCheckpoint({ - // filepath: state.filepath, - // content: state.fileContent, - // }), - // ); dispatch(updateApplyState(state)); if ( activeToolStreamId && diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index c6d2e5a98..e3464a6f2 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -83,10 +83,14 @@ const ModelRoleSelector = ({ disabled={models.length === 0} className={`bg-vsc-editor-background hover:bg-list-active hover:text-list-active-foreground w-full justify-between`} > - {models.length === 0 ? ( - {`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} - ) : noConfiguredModels ? ( - {`No valid ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`} + {models.length === 0 || noConfiguredModels ? ( + + {`No ${models.length === 0 ? "" : "valid "}${displayName} models${ + ["Chat", "Apply", "Edit"].includes(displayName) + ? ". Using Chat model" + : "" + }`} + ) : ( {selectedModel?.title ?? `Select ${displayName} model`} diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index ec195d9c9..b6fa33ee8 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -259,7 +259,6 @@ export function Chat() { ideMessenger.post("edit/sendPrompt", { prompt, range: codeToEdit[0] as RangeInFileWithContents, - selectedModelTitle: defaultModel.title, }); dispatch(submitEdit(prompt)); diff --git a/manual-testing-sandbox/test.js b/manual-testing-sandbox/test.js index 44c55402e..eee0aa7c5 100644 --- a/manual-testing-sandbox/test.js +++ b/manual-testing-sandbox/test.js @@ -9,7 +9,6 @@ class Calculator { } subtract(number) { - this.result -= number; return this; } diff --git a/manual-testing-sandbox/test.kt b/manual-testing-sandbox/test.kt index 683993e81..bb13ae9ee 100644 --- a/manual-testing-sandbox/test.kt +++ b/manual-testing-sandbox/test.kt @@ -30,3 +30,4 @@ class Test { return this } } + From ab0e6b22ef73a9147d9c45572f3936b7cd527480 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 21:42:02 -0700 Subject: [PATCH 15/19] Update ContextProvidersQuickPick.ts --- extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts b/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts index 074ec4d86..684508a7f 100644 --- a/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts +++ b/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts @@ -43,7 +43,7 @@ export async function getContextProvidersString( ide, embeddingsProvider: config.selectedModelByRole.embed, reranker: config.selectedModelByRole.rerank, - llm: config.models[0], + llm: config.selectedModelByRole.chat, fullInput: "", selectedCode: [], fetch: (url, init) => From ae72f3a29358d8e6a4dbd90a99bfd7ab3b2efe5d Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 21:54:34 -0700 Subject: [PATCH 16/19] remove eslint disable for max line error --- core/core.ts | 70 +++++++++---------- gui/src/redux/thunks/callTool.ts | 3 +- gui/src/redux/thunks/gatherContext.ts | 3 +- gui/src/redux/thunks/session.ts | 3 +- gui/src/redux/thunks/streamNormalInput.ts | 3 +- gui/src/redux/thunks/streamResponse.ts | 3 +- .../thunks/streamResponseAfterToolCall.ts | 2 +- 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/core/core.ts b/core/core.ts index 9bdf00750..68aa605ac 100644 --- a/core/core.ts +++ b/core/core.ts @@ -1,4 +1,3 @@ -/* eslint-disable max-lines-per-function */ import { fetchwithRequestOptions } from "@continuedev/fetch"; import * as URI from "uri-js"; import { v4 as uuidv4 } from "uuid"; @@ -33,6 +32,7 @@ import { TTS } from "./util/tts"; import { DiffLine, IdeSettings, + ModelDescription, RangeInFile, type ContextItemId, type IDE, @@ -494,32 +494,7 @@ export class Core { on("completeOnboarding", this.handleCompleteOnboarding); - on("addAutocompleteModel", (msg) => { - const model = msg.data.model; - editConfigFile( - (config) => { - return { - ...config, - tabAutocompleteModel: model, - }; - }, - (config) => ({ - ...config, - models: [ - ...(config.models ?? []), - { - name: model.title, - provider: model.provider, - model: model.model, - apiKey: model.apiKey, - roles: ["autocomplete"], - apiBase: model.apiBase, - }, - ], - }), - ); - void this.configHandler.reloadConfig(); - }); + on("addAutocompleteModel", this.handleAddAutocompleteModel); on("stats/getTokensPerDay", async (msg) => { const rows = await DevDataSqliteDb.getTokensPerDay(); @@ -530,7 +505,6 @@ export class Core { return rows; }); - // Codebase indexing on("index/forceReIndex", async ({ data }) => { const { config } = await this.configHandler.loadConfig(); if (!config || config.disableIndexing) { @@ -616,11 +590,7 @@ export class Core { } }); - on("files/opened", async ({ data }) => { - if (data?.uris?.length) { - // Do something on files opened - } - }); + on("files/opened", async () => {}); // Docs, etc. indexing on("indexing/reindex", async (msg) => { @@ -635,7 +605,6 @@ export class Core { }); on("indexing/setPaused", async (msg) => { if (msg.data.type === "docs") { - // this.docsService.setPaused(msg.data.id, msg.data.paused); // not supported yet } }); on("docs/initStatuses", async (msg) => { @@ -740,10 +709,8 @@ export class Core { throw new Error("No chat model selected"); } - // Count the size of the file tokenwise const tokens = countTokens(item.content); - // File exceeds context length of the model if (tokens > llm.contextLength - llm.completionOptions!.maxTokens!) { return true; } @@ -752,6 +719,37 @@ export class Core { }); } + private handleAddAutocompleteModel( + msg: Message<{ + model: ModelDescription; + }>, + ) { + const model = msg.data.model; + editConfigFile( + (config) => { + return { + ...config, + tabAutocompleteModel: model, + }; + }, + (config) => ({ + ...config, + models: [ + ...(config.models ?? []), + { + name: model.title, + provider: model.provider, + model: model.model, + apiKey: model.apiKey, + roles: ["autocomplete"], + apiBase: model.apiBase, + }, + ], + }), + ); + void this.configHandler.reloadConfig(); + } + private async handleFilesChanged({ data, }: Message<{ diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index 04d49007f..31e67b6d3 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -30,7 +30,8 @@ export const callTool = createAsyncThunk( return; } - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); + if (!defaultModel) { throw new Error("No model selected"); } diff --git a/gui/src/redux/thunks/gatherContext.ts b/gui/src/redux/thunks/gatherContext.ts index e810e1025..abc547c41 100644 --- a/gui/src/redux/thunks/gatherContext.ts +++ b/gui/src/redux/thunks/gatherContext.ts @@ -37,7 +37,8 @@ export const gatherContext = createAsyncThunk< { dispatch, extra, getState }, ) => { const state = getState(); - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); + const defaultContextProviders = state.config.config.experimental?.defaultContext ?? []; diff --git a/gui/src/redux/thunks/session.ts b/gui/src/redux/thunks/session.ts index 413c3c678..f5d40c4d4 100644 --- a/gui/src/redux/thunks/session.ts +++ b/gui/src/redux/thunks/session.ts @@ -167,7 +167,8 @@ export const saveCurrentSession = createAsyncThunk< // Now save previous session and update chat title if relevant let title = state.session.title; if (title === NEW_SESSION_TITLE) { - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); + if (!state.config.config?.disableSessionTitles && defaultModel) { let assistantResponse = state.session.history ?.filter((h) => h.message.role === "assistant")[0] diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 47cccff2d..507382d3f 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -29,7 +29,8 @@ export const streamNormalInput = createAsyncThunk< ) => { // Gather state const state = getState(); - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); + const toolSettings = state.ui.toolSettings; const toolGroupSettings = state.ui.toolGroupSettings; const streamAborter = state.session.streamAborter; diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index e7c013fca..b6c806a2e 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -34,7 +34,8 @@ export const streamResponseThunk = createAsyncThunk< await dispatch( streamThunkWrapper(async () => { const state = getState(); - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); + const slashCommands = state.config.config.slashCommands || []; const inputIndex = index ?? state.session.history.length; // Either given index or concat to end diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index 8605d190d..cb0de2756 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -27,7 +27,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< streamThunkWrapper(async () => { const state = getState(); const initialHistory = state.session.history; - const defaultModel = selectSelectedChatModel(state); + const selectedChatModel = selectSelectedChatModel(state); if (!defaultModel) { throw new Error("No model selected"); From fe97190e40b04c7b08bcd8775957e2dc880c20ef Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 22:00:54 -0700 Subject: [PATCH 17/19] fix linting errors --- .../StepContainerPreToolbar.tsx | 4 ++-- gui/src/pages/gui/Chat.tsx | 10 +++++----- gui/src/redux/thunks/callTool.ts | 4 ++-- gui/src/redux/thunks/gatherContext.ts | 2 +- gui/src/redux/thunks/streamNormalInput.ts | 4 ++-- gui/src/redux/thunks/streamResponse.ts | 4 +--- gui/src/redux/thunks/streamResponseAfterToolCall.ts | 2 +- 7 files changed, 14 insertions(+), 16 deletions(-) diff --git a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx index 0571913b6..c00290e4c 100644 --- a/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx +++ b/gui/src/components/markdown/StepContainerPreToolbar/StepContainerPreToolbar.tsx @@ -82,10 +82,10 @@ export default function StepContainerPreToolbar( const isNextCodeBlock = nextCodeBlockIndex === props.codeBlockIndex; const hasFileExtension = /\.[0-9a-z]+$/i.test(props.relativeFilepath); - const defaultModel = useAppSelector(selectSelectedChatModel); + const selectedChatModel = useAppSelector(selectSelectedChatModel); async function onClickApply() { - if (!defaultModel) { + if (!selectedChatModel) { return; } diff --git a/gui/src/pages/gui/Chat.tsx b/gui/src/pages/gui/Chat.tsx index b6fa33ee8..0ffd577c1 100644 --- a/gui/src/pages/gui/Chat.tsx +++ b/gui/src/pages/gui/Chat.tsx @@ -105,7 +105,7 @@ export function Chat() { const showSessionTabs = useAppSelector( (store) => store.config.config.ui?.showSessionTabs, ); - const defaultModel = useAppSelector(selectSelectedChatModel); + const selectedChatModel = useAppSelector(selectSelectedChatModel); const isStreaming = useAppSelector((state) => state.session.isStreaming); const [stepsOpen, setStepsOpen] = useState<(boolean | undefined)[]>([]); const mainTextInputRef = useRef(null); @@ -165,7 +165,7 @@ export function Chat() { "Cannot submit message while awaiting tool confirmation", ); } - if (defaultModel?.provider === "free-trial") { + if (selectedChatModel?.provider === "free-trial") { const newCount = incrementFreeTrialCount(); if (newCount === FREE_TRIAL_LIMIT_REQUESTS) { @@ -224,7 +224,7 @@ export function Chat() { }, [ history, - defaultModel, + selectedChatModel, streamResponse, isSingleRangeEditOrInsertion, codeToEdit, @@ -233,7 +233,7 @@ export function Chat() { ); async function handleSingleRangeEditOrInsertion(editorState: JSONContent) { - if (!defaultModel) { + if (!selectedChatModel) { console.error("No selected chat model"); return; } @@ -248,7 +248,7 @@ export function Chat() { defaultContextProviders: [], availableSlashCommands: [], dispatch, - selectedModelTitle: defaultModel.title, + selectedModelTitle: selectedChatModel.title, }); const prompt = [ diff --git a/gui/src/redux/thunks/callTool.ts b/gui/src/redux/thunks/callTool.ts index 31e67b6d3..cb875f805 100644 --- a/gui/src/redux/thunks/callTool.ts +++ b/gui/src/redux/thunks/callTool.ts @@ -32,7 +32,7 @@ export const callTool = createAsyncThunk( const selectedChatModel = selectSelectedChatModel(state); - if (!defaultModel) { + if (!selectedChatModel) { throw new Error("No model selected"); } @@ -77,7 +77,7 @@ export const callTool = createAsyncThunk( } else { const result = await extra.ideMessenger.request("tools/call", { toolCall: toolCallState.toolCall, - selectedModelTitle: defaultModel.title, + selectedModelTitle: selectedChatModel.title, }); if (result.status === "error") { errorMessage = result.error; diff --git a/gui/src/redux/thunks/gatherContext.ts b/gui/src/redux/thunks/gatherContext.ts index abc547c41..927866ed8 100644 --- a/gui/src/redux/thunks/gatherContext.ts +++ b/gui/src/redux/thunks/gatherContext.ts @@ -42,7 +42,7 @@ export const gatherContext = createAsyncThunk< const defaultContextProviders = state.config.config.experimental?.defaultContext ?? []; - if (!defaultModel) { + if (!selectedChatModel) { console.error( "gatherContext thunk: Cannot gather context, no model selected", ); diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 507382d3f..447ac3d3d 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -35,10 +35,10 @@ export const streamNormalInput = createAsyncThunk< const toolGroupSettings = state.ui.toolGroupSettings; const streamAborter = state.session.streamAborter; const useTools = selectUseTools(state); - if (!defaultModel) { + if (!selectedChatModel) { throw new Error("Default model not defined"); } - const includeTools = useTools && modelSupportsTools(defaultModel); + const includeTools = useTools && modelSupportsTools(selectedChatModel); // Send request const gen = extra.ideMessenger.llmStreamChat( diff --git a/gui/src/redux/thunks/streamResponse.ts b/gui/src/redux/thunks/streamResponse.ts index b6c806a2e..e79bcdf85 100644 --- a/gui/src/redux/thunks/streamResponse.ts +++ b/gui/src/redux/thunks/streamResponse.ts @@ -35,11 +35,9 @@ export const streamResponseThunk = createAsyncThunk< streamThunkWrapper(async () => { const state = getState(); const selectedChatModel = selectSelectedChatModel(state); - - const slashCommands = state.config.config.slashCommands || []; const inputIndex = index ?? state.session.history.length; // Either given index or concat to end - if (!defaultModel) { + if (!selectedChatModel) { throw new Error("No chat model selected"); } diff --git a/gui/src/redux/thunks/streamResponseAfterToolCall.ts b/gui/src/redux/thunks/streamResponseAfterToolCall.ts index cb0de2756..3fa335d8b 100644 --- a/gui/src/redux/thunks/streamResponseAfterToolCall.ts +++ b/gui/src/redux/thunks/streamResponseAfterToolCall.ts @@ -29,7 +29,7 @@ export const streamResponseAfterToolCall = createAsyncThunk< const initialHistory = state.session.history; const selectedChatModel = selectSelectedChatModel(state); - if (!defaultModel) { + if (!selectedChatModel) { throw new Error("No model selected"); } From 70c6a0a42382aa0e9c794ba698e1baa439da5153 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 22:06:34 -0700 Subject: [PATCH 18/19] linting --- gui/src/redux/thunks/gatherContext.ts | 6 +++--- gui/src/redux/thunks/session.ts | 4 ++-- gui/src/redux/thunks/streamNormalInput.ts | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gui/src/redux/thunks/gatherContext.ts b/gui/src/redux/thunks/gatherContext.ts index 927866ed8..2ba244d3f 100644 --- a/gui/src/redux/thunks/gatherContext.ts +++ b/gui/src/redux/thunks/gatherContext.ts @@ -58,12 +58,12 @@ export const gatherContext = createAsyncThunk< defaultContextProviders, availableSlashCommands: state.config.config.slashCommands, dispatch, - selectedModelTitle: defaultModel.title, + selectedModelTitle: selectedChatModel.title, }); // Automatically use currently open file if (!modifiers.noContext) { - const usingFreeTrial = defaultModel.provider === "free-trial"; + const usingFreeTrial = selectedChatModel.provider === "free-trial"; const currentFileResponse = await extra.ideMessenger.request( "context/getContextItems", @@ -72,7 +72,7 @@ export const gatherContext = createAsyncThunk< query: "non-mention-usage", fullInput: "", selectedCode: [], - selectedModelTitle: defaultModel.title, + selectedModelTitle: selectedChatModel.title, }, ); if (currentFileResponse.status === "success") { diff --git a/gui/src/redux/thunks/session.ts b/gui/src/redux/thunks/session.ts index f5d40c4d4..7572b1fe4 100644 --- a/gui/src/redux/thunks/session.ts +++ b/gui/src/redux/thunks/session.ts @@ -169,7 +169,7 @@ export const saveCurrentSession = createAsyncThunk< if (title === NEW_SESSION_TITLE) { const selectedChatModel = selectSelectedChatModel(state); - if (!state.config.config?.disableSessionTitles && defaultModel) { + if (!state.config.config?.disableSessionTitles && selectedChatModel) { let assistantResponse = state.session.history ?.filter((h) => h.message.role === "assistant")[0] ?.message?.content?.toString(); @@ -180,7 +180,7 @@ export const saveCurrentSession = createAsyncThunk< "chatDescriber/describe", { text: assistantResponse, - selectedModelTitle: defaultModel.title, + selectedModelTitle: selectedChatModel.title, }, ); if (result.status === "success" && result.content) { diff --git a/gui/src/redux/thunks/streamNormalInput.ts b/gui/src/redux/thunks/streamNormalInput.ts index 447ac3d3d..c8b10dc37 100644 --- a/gui/src/redux/thunks/streamNormalInput.ts +++ b/gui/src/redux/thunks/streamNormalInput.ts @@ -52,7 +52,7 @@ export const streamNormalInput = createAsyncThunk< ), } : {}, - title: defaultModel.title, + title: selectedChatModel.title, messages, legacySlashCommandData, }, @@ -82,8 +82,8 @@ export const streamNormalInput = createAsyncThunk< data: { prompt: next.value.prompt, completion: next.value.completion, - modelProvider: defaultModel.provider, - modelTitle: defaultModel.title, + modelProvider: selectedChatModel.provider, + modelTitle: selectedChatModel.title, sessionId: state.session.id, }, }); @@ -94,8 +94,8 @@ export const streamNormalInput = createAsyncThunk< // data: { // prompt: next.value.prompt, // completion: next.value.completion, - // modelProvider: defaultModel.provider, - // modelTitle: defaultModel.title, + // modelProvider: selectedChatModel.provider, + // modelTitle: selectedChatModel.title, // }, // }); // } From 71ec4518995bdce0b516891efe64e32fa369aedd Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 8 Apr 2025 22:11:30 -0700 Subject: [PATCH 19/19] Update ContextProvidersQuickPick.ts --- extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts b/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts index 684508a7f..f982c5c55 100644 --- a/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts +++ b/extensions/vscode/src/quickEdit/ContextProvidersQuickPick.ts @@ -34,7 +34,7 @@ export async function getContextProvidersString( provider.description.displayTitle === selectedProvider.label, ); - if (!provider) { + if (!provider || !config.selectedModelByRole.chat) { return []; }