fix: timestamp issue

This commit is contained in:
Louis 2024-12-17 17:12:03 +07:00
parent 66e37d80d6
commit 8613e35c15
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
6 changed files with 12 additions and 9 deletions

View File

@ -80,8 +80,8 @@ export abstract class OAIEngine extends AIEngine {
role: ChatCompletionRole.Assistant, role: ChatCompletionRole.Assistant,
content: [], content: [],
status: MessageStatus.Pending, status: MessageStatus.Pending,
created: timestamp, created_at: timestamp,
updated: timestamp, completed_at: timestamp,
object: 'thread.message', object: 'thread.message',
} }

View File

@ -194,8 +194,8 @@ export const createMessage = async (threadId: string, message: any) => {
id: msgId, id: msgId,
thread_id: threadId, thread_id: threadId,
status: MessageStatus.Ready, status: MessageStatus.Ready,
created: createdAt, created_at: createdAt,
updated: createdAt, completed_at: createdAt,
object: 'thread.message', object: 'thread.message',
role: message.role, role: message.role,
content: [ content: [

View File

@ -27,9 +27,9 @@ export type ThreadMessage = {
/** The status of this message. **/ /** The status of this message. **/
status: MessageStatus status: MessageStatus
/** The timestamp indicating when this message was created. Represented in Unix time. **/ /** The timestamp indicating when this message was created. Represented in Unix time. **/
created: number created_at: number
/** The timestamp indicating when this message was updated. Represented in Unix time. **/ /** The timestamp indicating when this message was updated. Represented in Unix time. **/
updated: number completed_at: number
/** The additional metadata of this message. **/ /** The additional metadata of this message. **/
metadata?: Record<string, unknown> metadata?: Record<string, unknown>

View File

@ -181,7 +181,7 @@ export default function useSendChatMessage() {
// Update thread state // Update thread state
const updatedThread: Thread = { const updatedThread: Thread = {
...activeThreadRef.current, ...activeThreadRef.current,
updated: newMessage.created, updated: newMessage.created_at,
metadata: { metadata: {
...activeThreadRef.current.metadata, ...activeThreadRef.current.metadata,
lastMessage: prompt, lastMessage: prompt,

View File

@ -91,7 +91,7 @@ const MessageContainer: React.FC<
: (activeAssistant?.assistant_name ?? props.role)} : (activeAssistant?.assistant_name ?? props.role)}
</div> </div>
<p className="text-xs font-medium text-gray-400"> <p className="text-xs font-medium text-gray-400">
{props.created && displayDate(props.created ?? new Date())} {props.created_at && displayDate(props.created_at ?? new Date())}
</p> </p>
</div> </div>

View File

@ -6,7 +6,10 @@ export const isToday = (timestamp: number) => {
export const displayDate = (timestamp?: string | number | Date) => { export const displayDate = (timestamp?: string | number | Date) => {
if (!timestamp) return 'N/A' if (!timestamp) return 'N/A'
const date = new Date(timestamp) const date =
typeof timestamp === 'number'
? new Date(timestamp * 1000)
: new Date(timestamp)
let displayDate = `${date.toLocaleDateString(undefined, { let displayDate = `${date.toLocaleDateString(undefined, {
day: '2-digit', day: '2-digit',