修复模型选择继承的小bug

This commit is contained in:
sijinhui 2024-07-12 11:28:32 +08:00
parent 90bbcc06d6
commit 37392d068c
5 changed files with 27 additions and 8 deletions

View File

@ -472,9 +472,11 @@ export function ChatActions(props: {
// switch model // switch model
const currentModel = chatStore.currentSession().mask.modelConfig.model; const currentModel = chatStore.currentSession().mask.modelConfig.model;
// 这里获取的不准确看起来没有什么地方可以更新这个providerName
const currentProviderName = const currentProviderName =
chatStore.currentSession().mask.modelConfig?.providerName || chatStore.currentSession().mask.modelConfig?.providerName ||
ServiceProvider.OpenAI; ServiceProvider.OpenAI;
console.log("222222222", currentModel, currentProviderName);
const allModels = useAllModels(); const allModels = useAllModels();
const models = useMemo(() => { const models = useMemo(() => {
const filteredModels = allModels.filter((m) => m.available); const filteredModels = allModels.filter((m) => m.available);
@ -609,7 +611,7 @@ export function ChatActions(props: {
<ChatAction <ChatAction
onClick={() => setShowModelSelector(true)} onClick={() => setShowModelSelector(true)}
text={currentModel} text={currentModelName}
icon={<RobotIcon />} icon={<RobotIcon />}
/> />
@ -627,7 +629,7 @@ export function ChatActions(props: {
{/*/>*/} {/*/>*/}
{showModelSelector && ( {showModelSelector && (
<Selector <ModalSelector
defaultSelectedValue={`${currentModel}@${currentProviderName}`} defaultSelectedValue={`${currentModel}@${currentProviderName}`}
items={models.map((m) => ({ items={models.map((m) => ({
title: `${m.displayName}${ title: `${m.displayName}${

View File

@ -23,6 +23,7 @@ import {
NARROW_SIDEBAR_WIDTH, NARROW_SIDEBAR_WIDTH,
Path, Path,
REPO_URL, REPO_URL,
ServiceProvider,
} from "../constant"; } from "../constant";
import { Link, useNavigate } from "react-router-dom"; import { Link, useNavigate } from "react-router-dom";
@ -131,6 +132,10 @@ export function SideBar(props: { className?: string }) {
const chatStore = useChatStore(); const chatStore = useChatStore();
const currentModel = chatStore.currentSession().mask.modelConfig.model; const currentModel = chatStore.currentSession().mask.modelConfig.model;
const currentProviderName =
chatStore.currentSession().mask.modelConfig?.providerName ||
ServiceProvider.OpenAI;
// drag side bar // drag side bar
const { onDragStart, shouldNarrow } = useDragSideBar(); const { onDragStart, shouldNarrow } = useDragSideBar();
const navigate = useNavigate(); const navigate = useNavigate();
@ -249,7 +254,11 @@ export function SideBar(props: { className?: string }) {
text={shouldNarrow ? undefined : Locale.Home.NewChat} text={shouldNarrow ? undefined : Locale.Home.NewChat}
onClick={() => { onClick={() => {
if (config.dontShowMaskSplashScreen) { if (config.dontShowMaskSplashScreen) {
chatStore.newSession(undefined, currentModel); chatStore.newSession(
undefined,
currentModel,
currentProviderName,
);
navigate(Path.Chat); navigate(Path.Chat);
} else { } else {
navigate(Path.NewChat); navigate(Path.NewChat);

View File

@ -514,7 +514,7 @@ export function ModalSelector<T extends CheckGroupValueType>(props: {
onClose?: () => void; onClose?: () => void;
multiple?: boolean; multiple?: boolean;
}) { }) {
// console.log("-----", props); console.log("-----", props);
const getCheckCardAvatar = (value: string): React.ReactNode => { const getCheckCardAvatar = (value: string): React.ReactNode => {
if (value.startsWith("gpt")) { if (value.startsWith("gpt")) {

View File

@ -224,14 +224,22 @@ export const useChatStore = createPersistStore(
}); });
}, },
newSession(mask?: Mask, currentModel?: Mask["modelConfig"]["model"]) { newSession(
mask?: Mask,
currentModel?: Mask["modelConfig"]["model"],
currentProviderName?: ServiceProvider,
) {
const session = createEmptySession(); const session = createEmptySession();
const config = useAppConfig.getState(); const config = useAppConfig.getState();
// console.log("------", session, "2222", config); // console.log("------", session, "2222", config);
// 继承当前会话的模型 // 继承当前会话的模型,
// 新增继承模型提供者
if (currentModel) { if (currentModel) {
session.mask.modelConfig.model = currentModel; session.mask.modelConfig.model = currentModel;
} }
if (currentProviderName) {
session.mask.modelConfig.providerName = currentProviderName;
}
if (mask) { if (mask) {
const config = useAppConfig.getState(); const config = useAppConfig.getState();
const globalModelConfig = config.modelConfig; const globalModelConfig = config.modelConfig;

View File

@ -140,7 +140,7 @@ export const useAppConfig = createPersistStore(
}), }),
{ {
name: StoreKey.Config, name: StoreKey.Config,
version: 3.96, version: 3.97,
migrate(persistedState, version) { migrate(persistedState, version) {
const state = persistedState as ChatConfig; const state = persistedState as ChatConfig;
@ -176,7 +176,7 @@ export const useAppConfig = createPersistStore(
// return { ...DEFAULT_CONFIG }; // return { ...DEFAULT_CONFIG };
// } // }
if (version < 3.96) { if (version < 3.97) {
state.modelConfig = DEFAULT_CONFIG.modelConfig; state.modelConfig = DEFAULT_CONFIG.modelConfig;
// state.modelConfig.template = // state.modelConfig.template =
// state.modelConfig.template !== DEFAULT_INPUT_TEMPLATE // state.modelConfig.template !== DEFAULT_INPUT_TEMPLATE