Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix timestamp bug #2

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AnythingLLMIcon from "@/assets/anything-llm-icon.svg";
import { formatDate } from "@/utils/date";

const PromptReply = forwardRef(
({ uuid, reply, pending, error, sources = [] }, ref) => {
({ uuid, reply, pending, error, sources = [], sentAt }, ref) => {
if (!reply && sources.length === 0 && !pending && !error) return null;
if (error) console.error(`ANYTHING_LLM_CHAT_WIDGET_ERROR: ${error}`);

Expand Down Expand Up @@ -98,11 +98,13 @@ const PromptReply = forwardRef(
</div>
</div>
</div>
<div
className={`allm-text-[10px] allm-text-gray-400 allm-ml-[54px] allm-mr-6 allm-mt-2 allm-text-left allm-font-sans`}
>
{formatDate(Date.now() / 1000)}
</div>
{sentAt && (
<div
className={`allm-text-[10px] allm-text-gray-400 allm-ml-[54px] allm-mr-6 allm-mt-2 allm-text-left allm-font-sans`}
>
{formatDate(sentAt)}
shatfield4 marked this conversation as resolved.
Show resolved Hide resolved
</div>
)}
</div>
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/components/ChatWindow/ChatContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ChatHistory from "./ChatHistory";
import PromptInput from "./PromptInput";
import handleChat from "@/utils/chat";
import ChatService from "@/models/chatService";
import { formatDate } from "@/utils/date";
shatfield4 marked this conversation as resolved.
Show resolved Hide resolved
export const SEND_TEXT_EVENT = "anythingllm-embed-send-prompt";

export default function ChatContainer({
Expand Down Expand Up @@ -32,13 +33,14 @@ export default function ChatContainer({

const prevChatHistory = [
...chatHistory,
{ content: message, role: "user" },
{ content: message, role: "user", sentAt: Math.floor(Date.now() / 1000) },
{
content: "",
role: "assistant",
pending: true,
userMessage: message,
animate: true,
sentAt: Math.floor(Date.now() / 1000),
},
];
setChatHistory(prevChatHistory);
Expand Down
10 changes: 10 additions & 0 deletions src/utils/chat/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default function handleChat(
errorMsg = null,
} = chatResult;

// Preserve the sentAt from the last message in the chat history
const lastMessage = _chatHistory[_chatHistory.length - 1];
const sentAt = lastMessage?.sentAt;

if (type === "abort") {
setLoadingResponse(false);
setChatHistory([
Expand All @@ -30,6 +34,7 @@ export default function handleChat(
errorMsg,
animate: false,
pending: false,
sentAt,
},
]);
_chatHistory.push({
Expand All @@ -42,6 +47,7 @@ export default function handleChat(
errorMsg,
animate: false,
pending: false,
sentAt,
});
} else if (type === "textResponse") {
setLoadingResponse(false);
Expand All @@ -57,6 +63,7 @@ export default function handleChat(
errorMsg,
animate: !close,
pending: false,
sentAt,
},
]);
_chatHistory.push({
Expand All @@ -69,6 +76,7 @@ export default function handleChat(
errorMsg,
animate: !close,
pending: false,
sentAt,
});
} else if (type === "textResponseChunk") {
const chatIdx = _chatHistory.findIndex((chat) => chat.uuid === uuid);
Expand All @@ -83,6 +91,7 @@ export default function handleChat(
closed: close,
animate: !close,
pending: false,
sentAt,
};
_chatHistory[chatIdx] = updatedHistory;
} else {
Expand All @@ -96,6 +105,7 @@ export default function handleChat(
closed: close,
animate: !close,
pending: false,
sentAt,
});
}
setChatHistory([..._chatHistory]);
Expand Down