feat: fallback to chat model in IDE
This commit is contained in:
parent
4006fbd58b
commit
b601c22d01
11 changed files with 42 additions and 65 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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")) {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,6 @@ export type ToIdeFromWebviewProtocol = ToIdeFromWebviewOrCoreProtocol & {
|
|||
{
|
||||
text: string;
|
||||
streamId: string;
|
||||
curSelectedModelTitle: string;
|
||||
filepath?: string;
|
||||
toolCallId?: string;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -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<Map<String, Any>>
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -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?
|
||||
)
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ export default function StepContainerPreToolbar(
|
|||
streamId: props.codeBlockStreamId,
|
||||
filepath: fileUri,
|
||||
text: codeBlockContent,
|
||||
curSelectedModelTitle: defaultModel.title,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,6 +38,10 @@ const ModelRoleSelector = ({
|
|||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const [hoveredIdx, setHoveredIdx] = useState<number | null>(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 ? (
|
||||
<span className="text-lightgray line-clamp-1 italic">{`No ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`}</span>
|
||||
) : noConfiguredModels ? (
|
||||
<span className="text-lightgray line-clamp-1 italic">{`No valid ${displayName} models${["Chat", "Apply", "Edit"].includes(displayName) ? ". Using chat model" : ""}`}</span>
|
||||
) : (
|
||||
<span className="line-clamp-1">
|
||||
{selectedModel?.title ?? `Select ${displayName} model`}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@ export const callTool = createAsyncThunk<void, undefined, ThunkApiType>(
|
|||
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,
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue