Skip to content

Commit

Permalink
fix: local generations ignoring regenCache on continue
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed Jul 29, 2024
1 parent 102e1a3 commit f5edb30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/constants/APIState/LocalAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class LocalAPI extends APIBase {
}

const outputCompleted = (text: string) => {
Chats.useChat.getState().setBuffer(text.replaceAll(replace, ''))
const regenCache = Chats.useChat.getState().getRegenCache()
Chats.useChat.getState().setBuffer((regenCache + text).replaceAll(replace, ''))
if (mmkv.getBoolean(AppSettings.PrintContext)) Logger.log(`Completion Output:\n${text}`)
}

Expand Down
9 changes: 8 additions & 1 deletion app/constants/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { create } from 'zustand'
import { Characters } from './Characters'
import { AppSettings, Global } from './GlobalValues'
import { Logger } from './Logger'
import { mmkv } from './MMKV'
import { RecentMessages } from './RecentMessages'
import { convertToFormatInstruct } from './TextFormat'
import { Tokenizer } from './Tokenizer'
import { replaceMacros } from './Utils'
import { mmkv } from './MMKV'

export type ChatSwipe = {
id: number
Expand Down Expand Up @@ -66,6 +66,7 @@ export interface ChatState {
updateFromBuffer: () => Promise<void>
insertLastToBuffer: () => void
setRegenCache: () => void
getRegenCache: () => string
stopGenerating: () => void
startGenerating: () => void
abortFunction: undefined | AbortFunction
Expand Down Expand Up @@ -279,6 +280,12 @@ export namespace Chats {
data: state?.data ? { ...state.data, messages: messages } : state.data,
}))
},
getRegenCache: () => {
const messages = get()?.data?.messages
const message = messages?.[messages.length - 1]
if (!messages || !message) return ''
return message.swipes[message.swipe_id].regen_cache ?? ''
},
}))

export namespace db {
Expand Down

0 comments on commit f5edb30

Please sign in to comment.