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

Update button text fix chat history state #222

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 5 additions & 10 deletions src/app/ui/pages/chat/AnnotatePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -724,9 +724,8 @@ console.log(output,"kk");
case "InstructionDrivenChat":
componentToRender = (
<InstructionDrivenChatPage
key={`annotations-${annotations?.length}-${
annotations?.[0]?.id || "default"
}`} handleClick={handleAnnotationClick}
key={annotations?.length > 0 ? `annotations-${annotations[0]?.id}` : "annotations-default"}
handleClick={handleAnnotationClick}
chatHistory={chatHistory}
setChatHistory={setChatHistory}
formatResponse={formatResponse}
Expand All @@ -745,9 +744,7 @@ console.log(output,"kk");
case "ModelInteractionEvaluation":
componentToRender = (
<ModelInteractionEvaluation
key={`annotations-${annotations?.length}-${
annotations?.[0]?.id || "default"
}`}
key={annotations?.length > 0 ? `annotations-${annotations[0]?.id}` : "annotations-default"}
setCurrentInteraction={setCurrentInteraction}
currentInteraction={currentInteraction}
interactions={interactions}
Expand All @@ -766,9 +763,7 @@ console.log(output,"kk");
case "MultipleInteractionEvaluation":
componentToRender = (
<PreferenceRanking
key={`annotations-${annotations?.length}-${
annotations?.[0]?.id || "default"
}`}
key={annotations?.length > 0 ? `annotations-${annotations[0]?.id}` : "annotations-default"}
setCurrentInteraction={setCurrentInteraction}
currentInteraction={currentInteraction}
interactions={interactions}
Expand Down Expand Up @@ -1128,7 +1123,7 @@ console.log(output,"kk");
<Tooltip
title={
<span style={{ fontFamily: "Roboto, sans-serif" }}>
skip to next task
Skip to next task
</span>
}
>
Expand Down
47 changes: 16 additions & 31 deletions src/app/ui/pages/chat/InstructionDrivenChatPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,38 +164,23 @@ const grey = {


useEffect(() => {
let modifiedChatHistory = [];
if (
annotation &&
Array.isArray(annotation[0]?.result) &&
[...annotation[0]?.result]?.length
) {
// if (ProjectDetails?.metadata_json?.blank_response == true) {
// modifiedChatHistory = annotation[0]?.result?.map((interaction) => ({
// ...interaction,
// output: [],
// }));
// console.log(modifiedChatHistory);

// setChatHistory(modifiedChatHistory);
// }
// else {
modifiedChatHistory = annotation[0]?.result?.map((interaction,index) => {
const isLastInteraction = index === annotation[0]?.result?.length - 1;
return {
...interaction,
output: formatResponse(interaction.output,isLastInteraction),
};
});
// }
setChatHistory([...modifiedChatHistory]);
let modifiedChatHistory = [];
if (annotation && Array.isArray(annotation[0]?.result) && annotation[0]?.result.length > 0) {
modifiedChatHistory = annotation[0]?.result.map((interaction, index) => {
const isLastInteraction = index === annotation[0]?.result.length - 1;
return {
...interaction,
output: formatResponse(interaction.output, isLastInteraction),
};
});
setChatHistory(modifiedChatHistory);
} else {
setChatHistory([]);
}
setAnnotationId(annotation[0]?.id);
if (annotation[0]?.result) setShowChatContainer(true);
}, []);

setChatHistory([]);
}
setAnnotationId(annotation[0]?.id);
setShowChatContainer(!!annotation[0]?.result);
}, [annotation]);
const cleanMetaInfo = (value) =>
value.replace(/\(for example:.*?\)/gi, "").trim();

Expand Down
34 changes: 23 additions & 11 deletions src/app/ui/pages/chat/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ const codeStyle = {
const Chat = () => {
/* eslint-disable react-hooks/exhaustive-deps */
const tooltipStyle = useStyles();
let inputValue = "";
const [inputValue, setInputValue] = useState("");
const classes = headerStyle();
const navigate = useNavigate();
const bottomRef = useRef(null);
const [loading, setLoading] = useState(false);
const [chatHistory, setChatHistory] = useState(() => {
return JSON.parse(sessionStorage.getItem("interaction_json")) || [];
});
const [chatHistory, setChatHistory] = useState([]);


const [showChatContainer, setShowChatContainer] = useState(
chatHistory.length > 0 ? true : false,
);
Expand All @@ -54,12 +54,24 @@ const Chat = () => {
const loggedInUserData = useSelector((state) => state.getLoggedInData.data);

useEffect(() => {
bottomRef.current?.scrollIntoView({ behavior: "smooth" });
window.sessionStorage.setItem(
"interaction_json",
JSON.stringify(chatHistory),
);
}, [chatHistory]);
const storedHistory = sessionStorage.getItem("interaction_json");
if (storedHistory) {
console.log("Stored History found in sessionStorage:", storedHistory);
setChatHistory(JSON.parse(storedHistory));
setShowChatContainer(true);
} else {
console.log("No stored history found in sessionStorage.");
}
}, []);

useEffect(() => {
console.log("chatHistory updated:", chatHistory);
if (chatHistory.length > 0) {
sessionStorage.setItem("interaction_json", JSON.stringify(chatHistory));
console.log("sessionStorage updated with new chat history");
}
}, [chatHistory]);


const formatResponse = (response) => {
response = String(response);
Expand Down Expand Up @@ -147,7 +159,7 @@ const Chat = () => {
};

const handleOnchange = (prompt) => {
inputValue = prompt;
setInputValue(prompt);
};

const renderSnackBar = () => {
Expand Down