diff --git a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx index 279b3709a..249ba77bb 100644 --- a/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx +++ b/gui/src/components/mainInput/Lump/sections/ModelsSection.tsx @@ -1,5 +1,110 @@ -import React from 'react'; +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 { + selectDefaultModel, + setDefaultModel, + updateConfig, +} from "../../../../redux/slices/configSlice"; +import { isJetBrains } from "../../../../util"; export function ModelsSection() { - return
Models content
; -} \ No newline at end of file + const { selectedProfile } = useAuth(); + const dispatch = useAppDispatch(); + const ideMessenger = useContext(IdeMessengerContext); + + const config = useAppSelector((state) => state.config.config); + const jetbrains = isJetBrains(); + const selectedChatModel = useAppSelector(selectDefaultModel); + + function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { + if (!selectedProfile) { + return; + } + // Optimistic update + dispatch( + updateConfig({ + ...config, + selectedModelByRole: { + ...config.selectedModelByRole, + [role]: model, + }, + }), + ); + ideMessenger.post("config/updateSelectedModel", { + profileId: selectedProfile.id, + role, + title: model?.title ?? null, + }); + } + + // TODO use handleRoleUpdate for chat + function handleChatModelSelection(model: ModelDescription | null) { + if (!model) { + return; + } + dispatch(setDefaultModel({ title: model.title })); + } + + return ( +
+ handleChatModelSelection(model)} + /> + handleRoleUpdate("autocomplete", model)} + /> + {/* Jetbrains has a model selector inline */} + {!jetbrains && ( + handleRoleUpdate("edit", model)} + /> + )} + handleRoleUpdate("apply", model)} + /> + handleRoleUpdate("embed", model)} + /> + handleRoleUpdate("rerank", model)} + /> +
+ ); +} diff --git a/gui/src/pages/config/index.tsx b/gui/src/pages/config/index.tsx index 14128ffda..f966af2c0 100644 --- a/gui/src/pages/config/index.tsx +++ b/gui/src/pages/config/index.tsx @@ -1,4 +1,3 @@ -import { ModelRole } from "@continuedev/config-yaml"; import { Listbox, Transition } from "@headlessui/react"; import { ArrowTopRightOnSquareIcon, @@ -7,7 +6,6 @@ import { PlusCircleIcon, XMarkIcon, } from "@heroicons/react/24/outline"; -import { ModelDescription } from "core"; import { SharedConfigSchema, modifyAnyConfigWithSharedConfig, @@ -24,15 +22,10 @@ import { useAuth } from "../../context/Auth"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useNavigationListener } from "../../hooks/useNavigationListener"; import { useAppDispatch, useAppSelector } from "../../redux/hooks"; -import { - selectDefaultModel, - setDefaultModel, - updateConfig, -} from "../../redux/slices/configSlice"; +import { updateConfig } from "../../redux/slices/configSlice"; import { selectProfileThunk } from "../../redux/thunks/profileAndOrg"; -import { getFontSize, isJetBrains } from "../../util"; +import { getFontSize } from "../../util"; import { AccountButton } from "./AccountButton"; -import ModelRoleSelector from "./ModelRoleSelector"; import { ScopeSelect } from "./ScopeSelect"; function ConfigPage() { @@ -76,7 +69,6 @@ function ConfigPage() { /////// User settings section ////// const config = useAppSelector((state) => state.config.config); - const selectedChatModel = useAppSelector(selectDefaultModel); function handleUpdate(sharedConfig: SharedConfigSchema) { // Optimistic update @@ -89,35 +81,6 @@ function ConfigPage() { ideMessenger.post("config/updateSharedConfig", sharedConfig); } - function handleRoleUpdate(role: ModelRole, model: ModelDescription | null) { - if (!selectedProfile) { - return; - } - // Optimistic update - dispatch( - updateConfig({ - ...config, - selectedModelByRole: { - ...config.selectedModelByRole, - [role]: model, - }, - }), - ); - ideMessenger.post("config/updateSelectedModel", { - profileId: selectedProfile.id, - role, - title: model?.title ?? null, - }); - } - - // TODO use handleRoleUpdate for chat - function handleChatModelSelection(model: ModelDescription | null) { - if (!model) { - return; - } - dispatch(setDefaultModel({ title: model.title })); - } - // TODO defaults are in multiple places, should be consolidated and probably not explicit here const showSessionTabs = config.ui?.showSessionTabs ?? false; const codeWrap = config.ui?.codeWrap ?? false; @@ -178,8 +141,6 @@ function ConfigPage() { setFormPromptPath(promptPath); }, [promptPath]); - const jetbrains = isJetBrains(); - return (
- {/* Model Roles as a separate section */} -
-
-

Model Roles

-
- handleChatModelSelection(model)} - /> - handleRoleUpdate("autocomplete", model)} - /> - {/* Jetbrains has a model selector inline */} - {!jetbrains && ( - handleRoleUpdate("edit", model)} - /> - )} - handleRoleUpdate("apply", model)} - /> - handleRoleUpdate("embed", model)} - /> - handleRoleUpdate("rerank", model)} - /> -
-
-
- {!controlServerBetaEnabled || hubEnabled ? (