Skip to content

Commit

Permalink
fix: chat timestamp not updating in real time
Browse files Browse the repository at this point in the history
  • Loading branch information
Vali-98 committed May 17, 2024
1 parent b2bb338 commit 846c165
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
28 changes: 10 additions & 18 deletions components/ChatMenu/ChatWindow/ChatFrame.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { View, Text, Image, StyleSheet } from 'react-native'
import { ReactNode, useEffect, useState } from 'react'
import { ChatEntry, Chats } from '@constants/Chat'
import { Chats } from '@constants/Chat'
import { Characters, Style } from '@globals'
import TTSMenu from './TTS'
import { useShallow } from 'zustand/react/shallow'

type ChatFrameProps = {
children?: ReactNode
userName: string
TTSenabled: boolean
id: number
charId: number
Expand All @@ -17,15 +16,15 @@ type ChatFrameProps = {

const ChatFrame: React.FC<ChatFrameProps> = ({
children,
userName,
TTSenabled,
id,
nowGenerating,
isLast,
}) => {
const { message } = Chats.useChat(
const { message, buffer } = Chats.useChat(
useShallow((state) => ({
message: state?.data?.messages?.[id] ?? Chats.dummyEntry,
buffer: state.buffer,
}))
)

Expand All @@ -51,21 +50,14 @@ const ChatFrame: React.FC<ChatFrameProps> = ({
setImageSource(require('@assets/user.png'))
}

const getDeltaTime = () =>
Math.round(
Math.max(
0,
((nowGenerating && isLast ? new Date().getTime() : swipe.gen_finished.getTime()) -
swipe.gen_started.getTime()) /
1000
)
const deltaTime = Math.round(
Math.max(
0,
((nowGenerating && isLast ? new Date().getTime() : swipe.gen_finished.getTime()) -
swipe.gen_started.getTime()) /
1000
)

const [deltaTime, setDeltaTime] = useState(getDeltaTime())

useEffect(() => {
setDeltaTime(getDeltaTime())
}, [nowGenerating])
)

// TODO: Change TTS to take id and simply retrieve that data on TTS as needed
return (
Expand Down
1 change: 0 additions & 1 deletion components/ChatMenu/ChatWindow/ChatItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const ChatItem: React.FC<ChatItemProps> = ({
}}>
<ChatFrame
charId={charId}
userName={userName}
id={id}
nowGenerating={nowGenerating}
isLast={isLastMessage}
Expand Down
4 changes: 2 additions & 2 deletions constants/Chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export interface ChatState {
updateEntry: (
index: number,
message: string,
updateTime?: boolean,
resetTime?: boolean
updateFinished?: boolean,
updateStarted?: boolean
) => Promise<void>
deleteEntry: (index: number) => Promise<void>
reset: () => void
Expand Down
3 changes: 0 additions & 3 deletions constants/Inference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@ const constructStopSequence = (instruct: InstructType): Array<string> => {
const sequence: Array<string> = []
if (instruct.stop_sequence !== '')
instruct.stop_sequence.split(',').forEach((item) => item !== '' && sequence.push(item))
// maybe people rather this not be removed?
//sequence.push(instruct.input_sequence)
return sequence
}

Expand Down Expand Up @@ -509,7 +507,6 @@ const constructOpenRouterPayload = () => {
const openRouterModel = getObject(Global.OpenRouterModel)
const currentInstruct = Instructs.useInstruct.getState().replacedMacros()
const preset = getObject(Global.PresetData)
console.log(getSeed(preset.seed))
return {
messages: buildChatCompletionContext(openRouterModel.context_length),
model: openRouterModel.id,
Expand Down

0 comments on commit 846c165

Please sign in to comment.