Skip to content

Commit

Permalink
Enable to set historyMessageCount for each chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Reekin committed Mar 17, 2024
1 parent cc0eae7 commit c66c509
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
34 changes: 32 additions & 2 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ import { ExportMessageModal } from "./exporter";
import { getClientConfig } from "../config/client";
import { useAllModels } from "../utils/hooks";
import { MultimodalContent } from "../client/api";
import { listen } from "@tauri-apps/api/event";
import { InputRange } from "./input-range";
import { config } from "process";

const Markdown = dynamic(async () => (await import("./markdown")).Markdown, {
loading: () => <LoadingIcon />,
Expand Down Expand Up @@ -625,6 +628,31 @@ export function EditMessageModal(props: { onClose: () => void }) {
}
></input>
</ListItem>
<ListItem
title={Locale.Settings.HistoryCount.Title}
subTitle={Locale.Settings.HistoryCount.SubTitle}
>
<InputRange
title={(
session.overrideModelConfig?.historyMessageCount ??
session.mask.modelConfig.historyMessageCount
).toString()}
value={
session.overrideModelConfig?.historyMessageCount ??
session.mask.modelConfig.historyMessageCount
}
min="0"
max="64"
step="1"
onChange={(e) =>
chatStore.updateCurrentSession(
(session) =>
((session.overrideModelConfig ??= {}).historyMessageCount =
e.currentTarget.valueAsNumber),
)
}
></InputRange>
</ListItem>
</List>
<ContextPrompts
context={messages}
Expand Down Expand Up @@ -1100,11 +1128,13 @@ function _Chat() {
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const handlePaste = useCallback(
async (event: React.ClipboardEvent<HTMLTextAreaElement>) => {
const currentModel = chatStore.currentSession().mask.modelConfig.model;
if(!isVisionModel(currentModel)){return;}
if (!isVisionModel(currentModel)) {
return;
}
const items = (event.clipboardData || window.clipboardData).items;
for (const item of items) {
if (item.kind === "file" && item.type.startsWith("image/")) {
Expand Down
13 changes: 11 additions & 2 deletions app/store/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface ChatSession {
clearContextIndex?: number;

mask: Mask;

overrideModelConfig?: Partial<ModelConfig>;
}

export const DEFAULT_TOPIC = Locale.Store.DefaultTopic;
Expand Down Expand Up @@ -466,7 +468,9 @@ export const useChatStore = createPersistStore(
// short term memory
const shortTermMemoryStartIndex = Math.max(
0,
totalMessageCount - modelConfig.historyMessageCount,
totalMessageCount -
(session.overrideModelConfig?.historyMessageCount ??
modelConfig.historyMessageCount),
);

// lets concat send messages, including 4 parts:
Expand Down Expand Up @@ -580,7 +584,12 @@ export const useChatStore = createPersistStore(
if (historyMsgLength > modelConfig?.max_tokens ?? 4000) {
const n = toBeSummarizedMsgs.length;
toBeSummarizedMsgs = toBeSummarizedMsgs.slice(
Math.max(0, n - modelConfig.historyMessageCount),
Math.max(
0,
n -
(session.overrideModelConfig?.historyMessageCount ??
modelConfig.historyMessageCount),
),
);
}

Expand Down

0 comments on commit c66c509

Please sign in to comment.