Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
Yidadaa committed Jun 23, 2023
1 parent cd6588a commit e186fe2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
6 changes: 3 additions & 3 deletions app/masks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const BUILTIN_MASK_ID = 100000;

export const BUILTIN_MASK_STORE = {
buildinId: BUILTIN_MASK_ID,
masks: {} as Record<number, Mask>,
masks: {} as Record<number, BuiltinMask>,
get(id?: number) {
if (!id) return undefined;
return this.masks[id] as Mask | undefined;
Expand All @@ -21,6 +21,6 @@ export const BUILTIN_MASK_STORE = {
},
};

export const BUILTIN_MASKS: Mask[] = [...CN_MASKS, ...EN_MASKS].map((m) =>
BUILTIN_MASK_STORE.add(m),
export const BUILTIN_MASKS: BuiltinMask[] = [...CN_MASKS, ...EN_MASKS].map(
(m) => BUILTIN_MASK_STORE.add(m),
);
6 changes: 4 additions & 2 deletions app/masks/typing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ModelConfig } from "../store";
import { type Mask } from "../store/mask";

export type BuiltinMask = Omit<Mask, "id"> & {
builtin: true;
export type BuiltinMask = Omit<Mask, "id" | "modelConfig"> & {
builtin: Boolean;
modelConfig: Partial<ModelConfig>;
};
13 changes: 11 additions & 2 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { trimTopic } from "../utils";

import Locale, { getLang } from "../locales";
import { showToast } from "../components/ui-lib";
import { ModelConfig, ModelType } from "./config";
import { ModelConfig, ModelType, useAppConfig } from "./config";
import { createEmptyMask, Mask } from "./mask";
import { DEFAULT_INPUT_TEMPLATE, StoreKey } from "../constant";
import { api, RequestMessage } from "../client/api";
Expand Down Expand Up @@ -181,7 +181,16 @@ export const useChatStore = create<ChatStore>()(
session.id = get().globalId;

if (mask) {
session.mask = { ...mask };
const config = useAppConfig.getState();
const globalModelConfig = config.modelConfig;

session.mask = {
...mask,
modelConfig: {
...globalModelConfig,
...mask.modelConfig,
},
};
session.topic = mask.name;
}

Expand Down
15 changes: 13 additions & 2 deletions app/store/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { persist } from "zustand/middleware";
import { BUILTIN_MASKS } from "../masks";
import { getLang, Lang } from "../locales";
import { DEFAULT_TOPIC, ChatMessage } from "./chat";
import { ModelConfig, ModelType, useAppConfig } from "./config";
import { ModelConfig, useAppConfig } from "./config";
import { StoreKey } from "../constant";

export type Mask = {
Expand Down Expand Up @@ -89,7 +89,18 @@ export const useMaskStore = create<MaskStore>()(
const userMasks = Object.values(get().masks).sort(
(a, b) => b.id - a.id,
);
return userMasks.concat(BUILTIN_MASKS);
const config = useAppConfig.getState();
const buildinMasks = BUILTIN_MASKS.map(
(m) =>
({
...m,
modelConfig: {
...config.modelConfig,
...m.modelConfig,
},
} as Mask),
);
return userMasks.concat(buildinMasks);
},
search(text) {
return Object.values(get().masks);
Expand Down

0 comments on commit e186fe2

Please sign in to comment.