fix: new chatStore of param with old chatStore

This commit is contained in:
2024-02-18 22:31:41 +08:00
parent e8650e2c7e
commit 159d0615c9

View File

@@ -94,7 +94,10 @@ export const newChatStore = (
postBeginIndex: 0, postBeginIndex: 0,
tokenMargin: 1024, tokenMargin: 1024,
totalTokens: 0, totalTokens: 0,
maxTokens: getDefaultParams("max", models[getDefaultParams("model", model)]?.maxToken ?? 2048), maxTokens: getDefaultParams(
"max",
models[getDefaultParams("model", model)]?.maxToken ?? 2048
),
maxGenTokens: 2048, maxGenTokens: 2048,
maxGenTokens_enabled: true, maxGenTokens_enabled: true,
apiKey: getDefaultParams("key", apiKey), apiKey: getDefaultParams("key", apiKey),
@@ -259,7 +262,7 @@ export function App() {
[] []
); );
const handleNewChatStore = async () => { const handleNewChatStoreWithOldOne = async (chatStore: ChatStore) => {
const newKey = await ( const newKey = await (
await db await db
).add( ).add(
@@ -288,6 +291,9 @@ export function App() {
setSelectedChatIndex(newKey as number); setSelectedChatIndex(newKey as number);
setAllChatStoreIndexes(await (await db).getAllKeys(STORAGE_NAME)); setAllChatStoreIndexes(await (await db).getAllKeys(STORAGE_NAME));
}; };
const handleNewChatStore = async () => {
return handleNewChatStoreWithOldOne(chatStore);
};
// if there are any params in URL, create a new chatStore // if there are any params in URL, create a new chatStore
useEffect(() => { useEffect(() => {
@@ -299,7 +305,7 @@ export function App() {
const mode = getDefaultParams("mode", ""); const mode = getDefaultParams("mode", "");
const model = getDefaultParams("model", ""); const model = getDefaultParams("model", "");
const max = getDefaultParams("max", 0); const max = getDefaultParams("max", 0);
console.log('max is', max, 'chatStore.max is', chatStore.maxTokens) console.log("max is", max, "chatStore.max is", chatStore.maxTokens);
// only create new chatStore if the params in URL are NOT // only create new chatStore if the params in URL are NOT
// equal to the current selected chatStore // equal to the current selected chatStore
if ( if (
@@ -310,8 +316,8 @@ export function App() {
(model && model !== chatStore.model) || (model && model !== chatStore.model) ||
(max !== 0 && max !== chatStore.maxTokens) (max !== 0 && max !== chatStore.maxTokens)
) { ) {
console.log('create new chatStore because of params in URL') console.log("create new chatStore because of params in URL");
handleNewChatStore(); handleNewChatStoreWithOldOne(chatStore);
} }
await db; await db;
const allidx = await (await db).getAllKeys(STORAGE_NAME); const allidx = await (await db).getAllKeys(STORAGE_NAME);
@@ -342,7 +348,8 @@ export function App() {
return ( return (
<li> <li>
<button <button
className={`w-full my-1 p-1 rounded hover:bg-blue-500 ${i === selectedChatIndex ? "bg-blue-500" : "bg-blue-200" className={`w-full my-1 p-1 rounded hover:bg-blue-500 ${
i === selectedChatIndex ? "bg-blue-500" : "bg-blue-200"
}`} }`}
onClick={() => { onClick={() => {
setSelectedChatIndex(i); setSelectedChatIndex(i);