I am interacting with the Gradio API using a chatbot, but I want to continue the chat on another device like chatgpt history where it continues the chatting. How can I achieve this?
const [chatHistory, setChatHistory] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [input, setInput] = useState("");
const [previewMessage, setPreviewMessage] = useState("");
const [clientt, setClientt] = useState(null);
useEffect(() => {
(async () => {
const cli = await Client.connect("Qwen/Qwen2.5-VL-72B-Instruct");
setClientt(cli);
})();
}, []);
useEffect(() => {
console.log('History:', JSON.stringify(chatHistory));
}, [chatHistory])
const sendMessage = async () => {
if (!input.trim()) return;
const newMessage = input;
setInput('');
setIsLoading(true);
try {
const a = await clientt.predict(
"/add_text", {
history: chatHistory,
text: newMessage,
});
await clientt.predict(
"/reset_user_input",
);
const data = await clientt.predict(
"/predict", {
_chatbot: [[newMessage, "null"]],
});
// console.log(JSON.stringify(data.data[0][0]));
let botResponse = data.data[0][0] || "I couldn't understand that.";
setChatHistory(prev => [...prev, botResponse]);
// console.log('resp: ', JSON.stringify(data.data));
} catch (error) {
console.error("Error communicating with the model:", error);
setChatHistory((prev) => [
...prev,
[newMessage, "Sorry, there was an error processing your request."],
]);
} finally {
setIsLoading(false);
}
};
I have checked this discussion:
https://discuss.huggingface.co/t/implementing-chatbot-history-like-chatgpt-on-gradio-gr-chatinterface/52186
No, thats not the solution. It just stores the chat but i want to make model continue chat on other device on previous topic. How can i achieve that?
*clientt is not typo