File size: 3,985 Bytes
dbcf08f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
"""
تطبيق بسيط لاختبار نظام RAG
"""
from simple_rag import SimpleRAG
import os
def interactive_search():
"""تطبيق تفاعلي للبحث"""
print("🤖 مرحباً بك في نظام RAG لشركة NBTEL")
print("=" * 50)
# تهيئة النظام
rag = SimpleRAG()
# تحميل البيانات
if not rag.load_index():
print("🔄 إنشاء فهرس جديد...")
file_path = "./data/nbtel_company_profile.md"
if os.path.exists(file_path):
documents = rag.load_markdown_file(file_path)
rag.add_documents(documents)
rag.build_index()
rag.save_index()
print("✅ تم إنشاء الفهرس بنجاح")
else:
print(f"❌ لم يتم العثور على ملف البيانات")
return
# عرض الإحصائيات
stats = rag.get_stats()
print(f"\n📊 الفهرس يحتوي على {stats['total_documents']} مستند")
print("\n💡 اكتب استفسارك أو 'exit' للخروج")
print("=" * 50)
while True:
try:
# الحصول على الاستعلام
query = input("\n🔍 استفسارك: ").strip()
if query.lower() in ['exit', 'خروج', 'quit']:
print("👋 شكراً لاستخدام النظام!")
break
if not query:
continue
# البحث
print("\n🔄 جاري البحث...")
context = rag.get_context_for_query(query, max_results=3)
print("\n📋 النتائج:")
print("-" * 30)
print(context)
print("-" * 30)
except KeyboardInterrupt:
print("\n👋 شكراً لاستخدام النظام!")
break
except Exception as e:
print(f"❌ حدث خطأ: {str(e)}")
def test_common_questions():
"""اختبار الأسئلة الشائعة"""
print("🧪 اختبار الأسئلة الشائعة")
print("=" * 50)
rag = SimpleRAG()
if not rag.load_index():
print("❌ لا يوجد فهرس محفوظ. قم بتشغيل النظام أولاً")
return
questions = [
"ما هي خدمات شركة NBTEL؟",
"كيف أتواصل مع الدعم الفني؟",
"ما هي أسعار باقات الإنترنت؟",
"عندي مشكلة الواي فاي ما يظهر",
"كيف أغير كلمة سر الراوتر؟",
"هل يمكن نقل الخدمة لعنوان جديد؟",
"وين مقر الشركة؟",
"شنو تاريخ الشركة؟",
"عندي انقطاعات بالإنترنت"
]
for i, question in enumerate(questions, 1):
print(f"\n❓ سؤال {i}: {question}")
context = rag.get_context_for_query(question, max_results=2)
# عرض أول 200 حرف من النتيجة
preview = context[:200] + "..." if len(context) > 200 else context
print(f"📋 النتيجة: {preview}")
print("-" * 40)
def main():
"""القائمة الرئيسية"""
while True:
print("\n🤖 نظام RAG لشركة NBTEL")
print("=" * 30)
print("1. البحث التفاعلي")
print("2. اختبار الأسئلة الشائعة")
print("3. الخروج")
choice = input("\nاختر خيار (1-3): ").strip()
if choice == "1":
interactive_search()
elif choice == "2":
test_common_questions()
elif choice == "3":
print("👋 وداعاً!")
break
else:
print("❌ خيار غير صحيح")
if __name__ == "__main__":
main() |