// تحميل سجل المحادثة من Local Storage
function loadConversationHistory() {
const history = localStorage.getItem('conversationHistory');
if (history) {
conversationHistory = JSON.parse(history);
displayConversationHistory();
}
}
// حفظ سجل المحادثة إلى Local Storage
function saveConversationHistory() {
localStorage.setItem('conversationHistory', JSON.stringify(conversationHistory));
}
// عرض سجل المحادثة
function displayConversationHistory() {
historyContainer.innerHTML = '';
conversationHistory.forEach(item => {
const messageDiv = document.createElement('div');
messageDiv.className = 'mb-4';
code
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
// إرسال الرسالة إلى الخادم والحصول على الرد
async function sendMessage(message) {
try {
const response = await fetch('/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: message })
});
code
const result = await response.json();
addMessageToHistory('ai', result.response);
// تشغيل الرد باستخدام تحويل النص إلى كلام
await playAudio(result.response);
} catch (error) {
console.error('خطأ في إرسال الرسالة:', error);
}
}
// إضافة الرسائل إلى السجل
function addMessageToHistory(sender, message) {
if (sender === 'user') {
conversationHistory.push({ user: message, ai: '' });
} else if (sender === 'ai') {
conversationHistory[conversationHistory.length - 1].ai = message;
}
displayConversationHistory();
saveConversationHistory();
}
// تحويل النص إلى كلام وتشغيله
async function playAudio(text) {
try {
const response = await fetch('/text-to-speech', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: text })
});
// تحميل سجل المحادثة عند تحميل الصفحة
loadConversationHistory();
improve this code make it more modern and remove circle visualizer visualize with audio more modern, add book have eyes and mouth and have emotions get current emotion from chat api make it move with animations :
emotions :
happy
peaceful
sad
thinking
trust
add chat show with button slide button under the website and also use daisyui
use
Sure! Below is an improved version of your chatbot application that incorporates modern design practices, replaces the circular visualizer with an animated book that reflects emotions, and adds a sliding chat panel using DaisyUI and Tailwind CSS.
Key Enhancements:
Modern Design: Utilizes the latest Tailwind CSS and DaisyUI for responsive and modern UI components.
Animated Book Visualizer: Replaces the circular visualizer with a book that has animated eyes and mouth, reflecting emotions like happy, peaceful, sad, thinking, and trust.
Sliding Chat Panel: Adds a chat panel that slides in and out from the bottom of the screen, enhancing user interaction.
Emotion Handling: Integrates emotion data from the chat API to animate the book accordingly.
Added DaisyUI for enhanced UI components and styling.
Animated Book Visualizer:
Replaced the circular visualizer with a #bookContainer that contains a stylized book (.book).
The book has eyes (.eyes .eye) and a mouth (.mouth) that change based on the current emotion.
Defined CSS classes for different emotions (happy, peaceful, sad, thinking, trust) that alter the mouth's appearance.
Sliding Chat Panel:
Added a #chatPanel that slides in from the bottom when the chat is active.
Included a toggle button (#toggleChatButton) to open and close the chat panel.
Utilized DaisyUI's btn classes for consistent button styling.
JavaScript Enhancements:
Emotion Handling: Modified the sendMessage function to handle an emotion property returned from the chat API. The updateBookEmotion function applies the corresponding CSS class to the book based on the emotion.
Chat Panel Management: Toggled the chat panel's visibility by adding/removing the open class, which changes its bottom position via CSS transitions.
Message Display: Separated conversation history into both the main container and the sliding chat panel for better user experience.
Error Handling: Added alerts and console error messages for better debugging and user feedback.
Accessibility and User Experience:
Ensured that the chat panel is easily accessible and does not obstruct the main content.
Provided clear visual feedback through the animated book, enhancing the interactive experience.
Additional Notes:
Backend Adjustments: Ensure that your backend API (/chat endpoint) returns an emotion field alongside the response. For example:
json
{
"response": "مرحبا! كيف يمكنني مساعدتك اليوم؟",
"emotion": "happy"
}
Emotion Animations: You can further enhance the book's animations by adding more CSS transitions or JavaScript-controlled animations based on the emotion states.
Responsive Design: Tailwind CSS ensures that the application is responsive. However, you can further tweak the styles to optimize the layout for different screen sizes.
Security Considerations: Always validate and sanitize inputs on the server side to prevent potential security vulnerabilities.
Final Thoughts
This improved version provides a more engaging and modern user interface, enhancing the overall user experience. The animated book adds a dynamic visual element that responds to the conversation's emotional context, making interactions feel more natural and intuitive.
Feel free to further customize the styles and animations to better fit your application's theme and functionality!