mohammadSaber26 commited on
Commit
e9a9bff
·
verified ·
1 Parent(s): 4516809

Upload components/ChatMessage.jsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. components/ChatMessage.jsx +49 -0
components/ChatMessage.jsx ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import React from 'react';
2
+
3
+ const ChatMessage = ({ type, content, products, clarification, debug }) => {
4
+ return (
5
+ <div className={`msg mb-4 p-3 rounded-lg shadow-sm ${type === 'user' ? 'bg-blue-50 border-l-4 border-blue-500' : 'bg-green-50 border-r-4 border-green-500'}`}>
6
+ {type === 'user' && <div className="user font-bold text-blue-700 mb-1">👤 شما:</div>}
7
+ {type === 'bot' && <div className="bot font-bold text-green-700 mb-1">🤖 پاسخ:</div>}
8
+
9
+ {type === 'text' && <p className="text-gray-800 whitespace-pre-wrap">{content}</p>}
10
+
11
+ {type === 'product_list' && (
12
+ <div>
13
+ <p className="font-bold text-gray-700 mb-2"><b>نتیجه:</b> {content}</p>
14
+ <p className="text-sm text-gray-600 mb-3">تعداد: {products?.length || 0}</p>
15
+
16
+ <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
17
+ {products?.map((product, index) => (
18
+ <div key={index} className="product bg-white border border-gray-200 p-4 rounded-md shadow-sm hover:shadow-md transition-shadow">
19
+ <div className="font-bold text-lg text-gray-800 mb-1">{product.name}</div>
20
+ <div className="text-sm text-gray-600 mb-2">قیمت: {product.formatted_price} تومان</div>
21
+ <div className="text-sm text-gray-500 mb-2">وضعیت: {product.stock ? '✅ موجود' : '❌ ناموجود'}</div>
22
+ <div className="text-sm text-gray-500">
23
+ برند: {product.brand || '-'} | شهر: {product.city || '-'}
24
+ </div>
25
+ </div>
26
+ ))}
27
+ </div>
28
+ </div>
29
+ )}
30
+
31
+ {clarification && (
32
+ <div className="clarification mt-4 p-3 bg-red-50 border border-red-200 rounded text-red-700 font-bold">
33
+ ❗ ابهام تشخیص داده شد: {clarification}
34
+ </div>
35
+ )}
36
+
37
+ {debug && (
38
+ <div className="debug-box mt-6 bg-gray-900 text-green-400 p-4 rounded-lg overflow-x-auto">
39
+ <details>
40
+ <summary className="cursor-pointer font-bold hover:text-green-300">🧪 فیلترهای استخراج‌شده توسط LLM (JSON)</summary>
41
+ <pre className="text-xs mt-2 whitespace-pre-wrap">{JSON.stringify(debug, null, 2)}</pre>
42
+ </details>
43
+ </div>
44
+ )}
45
+ </div>
46
+ );
47
+ };
48
+
49
+ export default ChatMessage;