Spaces:
Runtime error
Runtime error
Download test_intent.py from UNIQ-Project-AI/uniq-backendd: direct link, hf CLI and curl.
- Browser
- Download file 2.79 kB
-
https://huggingface.co/spaces/UNIQ-Project-AI/uniq-backendd/resolve/main/test_intent.py
- Command line
-
hf download hf://spaces/UNIQ-Project-AI/uniq-backendd/test_intent.py
-
curl -L -o test_intent.py https://huggingface.co/spaces/UNIQ-Project-AI/uniq-backendd/resolve/main/test_intent.py
2.79 kB
| import asyncio | |
| import os | |
| from dotenv import load_dotenv | |
| from services.intent_service import IntentService | |
| from services.llm_service import LLMService | |
| # ========================= | |
| # 🚀 LOAD ENV FIRST | |
| # ========================= | |
| load_dotenv() | |
| print("\n==============================") | |
| print("🧪 INTENT SERVICE REAL LLM TEST") | |
| print("==============================\n") | |
| print("🔑 GROQ_API_KEY LOADED:", bool(os.getenv("GROQ_API_KEY"))) | |
| print("---------------------------------\n") | |
| async def run_test(): | |
| # ========================= | |
| # 1. INIT REAL LLM SERVICE | |
| # ========================= | |
| try: | |
| llm_service = LLMService( | |
| model_name="llama-3.3-70b-versatile", | |
| temperature=0.4 | |
| ) | |
| print("✅ LLMService loaded successfully") | |
| except Exception as e: | |
| print(f"❌ LLMService error: {e}") | |
| return | |
| # ========================= | |
| # 2. INIT INTENT SERVICE | |
| # ========================= | |
| try: | |
| intent_service = IntentService( | |
| model_path="./models/intent_model", | |
| label_map_path="./models/intent_model/label_map.json", | |
| llm_model=llm_service.llm, | |
| llm_validator=llm_service.llm_validate_intent, | |
| intents=[ | |
| "gpa_calc", | |
| "gpa_plan", | |
| "course_rec", | |
| "general_query" | |
| ] | |
| ) | |
| print("✅ IntentService loaded successfully") | |
| except Exception as e: | |
| print(f"❌ IntentService error: {e}") | |
| return | |
| # ========================= | |
| # 3. TEST CASES | |
| # ========================= | |
| queries = [ | |
| "ايه ال gpa بتاعبببب", | |
| "بتاعي ال gpa", | |
| "عايز احسب التقدير", | |
| "what is my gps", | |
| "how can i reach 3.5", | |
| "ايه متطلبات مادة داتا", | |
| "اسجل انهي داتا بيز ولا داتا استراكتشر", | |
| "كلمني عن الكلية", | |
| "عايزه اجحب ال gpa", | |
| "عايزه اجسسب ال gpa", | |
| "اوصل لامتياج ازاي وانا دلوقتي جييييد" | |
| ] | |
| # ========================= | |
| # 4. RUN TEST LOOP | |
| # ========================= | |
| for q in queries: | |
| print("\n" + "=" * 80) | |
| print(f"📥 RAW QUERY: {q}") | |
| print("=" * 80) | |
| try: | |
| label, conf = intent_service.classify_intent( | |
| q, | |
| threshold=0.85 | |
| ) | |
| print("\n🎯 FINAL RESULT:") | |
| print(f"➡️ Label: {label}") | |
| print(f"➡️ Confidence: {conf:.4f}") | |
| except Exception as e: | |
| print(f"❌ Error: {e}") | |
| print("-" * 80) | |
| if __name__ == "__main__": | |
| asyncio.run(run_test()) |