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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script to check which models are currently being used on Hugging Face Space.
|
| 4 |
+
"""
|
| 5 |
+
import os
|
| 6 |
+
import sys
|
| 7 |
+
|
| 8 |
+
# Add backend to path
|
| 9 |
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
|
| 10 |
+
|
| 11 |
+
def check_embedding_model():
|
| 12 |
+
"""Check embedding model configuration."""
|
| 13 |
+
from hue_portal.core.embeddings import (
|
| 14 |
+
DEFAULT_MODEL_NAME,
|
| 15 |
+
FALLBACK_MODEL_NAME,
|
| 16 |
+
AVAILABLE_MODELS,
|
| 17 |
+
get_embedding_model
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
print("=" * 60)
|
| 21 |
+
print("🔍 EMBEDDING MODEL CONFIGURATION")
|
| 22 |
+
print("=" * 60)
|
| 23 |
+
|
| 24 |
+
# Check environment variable
|
| 25 |
+
env_model = os.environ.get("EMBEDDING_MODEL")
|
| 26 |
+
if env_model:
|
| 27 |
+
print(f"📌 EMBEDDING_MODEL env var: {env_model}")
|
| 28 |
+
else:
|
| 29 |
+
print(f"📌 EMBEDDING_MODEL env var: Not set (using default)")
|
| 30 |
+
|
| 31 |
+
print(f"📌 Default model: {DEFAULT_MODEL_NAME}")
|
| 32 |
+
print(f"📌 Fallback model: {FALLBACK_MODEL_NAME}")
|
| 33 |
+
|
| 34 |
+
# Try to load model
|
| 35 |
+
print("\n🔄 Attempting to load embedding model...")
|
| 36 |
+
try:
|
| 37 |
+
model = get_embedding_model()
|
| 38 |
+
if model:
|
| 39 |
+
# Get dimension
|
| 40 |
+
test_embedding = model.encode("test", show_progress_bar=False)
|
| 41 |
+
dim = len(test_embedding)
|
| 42 |
+
print(f"✅ Model loaded successfully!")
|
| 43 |
+
print(f" Model name: {DEFAULT_MODEL_NAME}")
|
| 44 |
+
print(f" Dimension: {dim}")
|
| 45 |
+
print(f" Status: ✅ GOOD")
|
| 46 |
+
|
| 47 |
+
# Evaluate
|
| 48 |
+
if dim >= 768:
|
| 49 |
+
print(f" Quality: ⭐⭐⭐⭐ High quality (768+ dim)")
|
| 50 |
+
elif dim >= 384:
|
| 51 |
+
print(f" Quality: ⭐⭐⭐ Good quality (384 dim)")
|
| 52 |
+
else:
|
| 53 |
+
print(f" Quality: ⭐⭐ Basic quality")
|
| 54 |
+
else:
|
| 55 |
+
print("❌ Failed to load model")
|
| 56 |
+
except Exception as e:
|
| 57 |
+
print(f"❌ Error: {e}")
|
| 58 |
+
|
| 59 |
+
print("\n📊 Available models:")
|
| 60 |
+
for key, value in AVAILABLE_MODELS.items():
|
| 61 |
+
marker = "⭐" if value == DEFAULT_MODEL_NAME else " "
|
| 62 |
+
print(f" {marker} {key}: {value}")
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def check_llm_model():
|
| 66 |
+
"""Check LLM model configuration."""
|
| 67 |
+
from hue_portal.chatbot.llm_integration import (
|
| 68 |
+
LLM_PROVIDER,
|
| 69 |
+
LLM_PROVIDER_NONE,
|
| 70 |
+
LLM_PROVIDER_OPENAI,
|
| 71 |
+
LLM_PROVIDER_ANTHROPIC,
|
| 72 |
+
LLM_PROVIDER_OLLAMA,
|
| 73 |
+
LLM_PROVIDER_HUGGINGFACE,
|
| 74 |
+
LLM_PROVIDER_LOCAL,
|
| 75 |
+
get_llm_generator
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
print("\n" + "=" * 60)
|
| 79 |
+
print("🔍 LLM MODEL CONFIGURATION")
|
| 80 |
+
print("=" * 60)
|
| 81 |
+
|
| 82 |
+
print(f"📌 LLM_PROVIDER: {LLM_PROVIDER}")
|
| 83 |
+
|
| 84 |
+
if LLM_PROVIDER == LLM_PROVIDER_NONE:
|
| 85 |
+
print("⚠️ No LLM provider configured!")
|
| 86 |
+
print(" Status: ❌ NOT USING LLM (template-based only)")
|
| 87 |
+
print(" Quality: ⭐⭐ Basic (no LLM generation)")
|
| 88 |
+
print("\n💡 To enable LLM, set LLM_PROVIDER to one of:")
|
| 89 |
+
print(" - ollama (for local Qwen)")
|
| 90 |
+
print(" - openai (for GPT)")
|
| 91 |
+
print(" - anthropic (for Claude)")
|
| 92 |
+
print(" - huggingface (for HF Inference API)")
|
| 93 |
+
print(" - local (for local Transformers)")
|
| 94 |
+
elif LLM_PROVIDER == LLM_PROVIDER_OPENAI:
|
| 95 |
+
model = os.environ.get("OPENAI_MODEL", "gpt-3.5-turbo")
|
| 96 |
+
print(f"✅ Using OpenAI")
|
| 97 |
+
print(f" Model: {model}")
|
| 98 |
+
print(f" Status: ✅ GOOD")
|
| 99 |
+
print(f" Quality: ⭐⭐⭐⭐⭐ Excellent")
|
| 100 |
+
elif LLM_PROVIDER == LLM_PROVIDER_ANTHROPIC:
|
| 101 |
+
model = os.environ.get("ANTHROPIC_MODEL", "claude-3-5-sonnet-20241022")
|
| 102 |
+
print(f"✅ Using Anthropic Claude")
|
| 103 |
+
print(f" Model: {model}")
|
| 104 |
+
print(f" Status: ✅ EXCELLENT")
|
| 105 |
+
print(f" Quality: ⭐⭐⭐⭐⭐ Best for Vietnamese")
|
| 106 |
+
elif LLM_PROVIDER == LLM_PROVIDER_OLLAMA:
|
| 107 |
+
model = os.environ.get("OLLAMA_MODEL", "qwen2.5:7b")
|
| 108 |
+
base_url = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434")
|
| 109 |
+
print(f"✅ Using Ollama (local)")
|
| 110 |
+
print(f" Model: {model}")
|
| 111 |
+
print(f" Base URL: {base_url}")
|
| 112 |
+
print(f" Status: ✅ GOOD (if Ollama running)")
|
| 113 |
+
print(f" Quality: ⭐⭐⭐⭐ Very good for Vietnamese")
|
| 114 |
+
elif LLM_PROVIDER == LLM_PROVIDER_HUGGINGFACE:
|
| 115 |
+
model = os.environ.get("HF_MODEL", "Qwen/Qwen2.5-7B-Instruct")
|
| 116 |
+
print(f"✅ Using Hugging Face Inference API")
|
| 117 |
+
print(f" Model: {model}")
|
| 118 |
+
print(f" Status: ✅ GOOD")
|
| 119 |
+
print(f" Quality: ⭐⭐⭐⭐ Good for Vietnamese")
|
| 120 |
+
elif LLM_PROVIDER == LLM_PROVIDER_LOCAL:
|
| 121 |
+
model = os.environ.get("LOCAL_MODEL_PATH", "Qwen/Qwen2.5-1.5B-Instruct")
|
| 122 |
+
device = os.environ.get("LOCAL_MODEL_DEVICE", "auto")
|
| 123 |
+
print(f"✅ Using Local Transformers")
|
| 124 |
+
print(f" Model: {model}")
|
| 125 |
+
print(f" Device: {device}")
|
| 126 |
+
print(f" Status: ✅ GOOD (if model loaded)")
|
| 127 |
+
print(f" Quality: ⭐⭐⭐⭐ Good for Vietnamese")
|
| 128 |
+
|
| 129 |
+
# Try to get LLM generator
|
| 130 |
+
print("\n🔄 Checking LLM availability...")
|
| 131 |
+
try:
|
| 132 |
+
llm = get_llm_generator()
|
| 133 |
+
if llm and llm.is_available():
|
| 134 |
+
print("✅ LLM is available and ready!")
|
| 135 |
+
else:
|
| 136 |
+
print("⚠️ LLM is not available")
|
| 137 |
+
except Exception as e:
|
| 138 |
+
print(f"❌ Error checking LLM: {e}")
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def main():
|
| 142 |
+
"""Main function."""
|
| 143 |
+
print("\n" + "=" * 60)
|
| 144 |
+
print("📊 MODEL STATUS CHECK")
|
| 145 |
+
print("=" * 60)
|
| 146 |
+
print()
|
| 147 |
+
|
| 148 |
+
check_embedding_model()
|
| 149 |
+
check_llm_model()
|
| 150 |
+
|
| 151 |
+
print("\n" + "=" * 60)
|
| 152 |
+
print("📋 SUMMARY")
|
| 153 |
+
print("=" * 60)
|
| 154 |
+
|
| 155 |
+
# Embedding summary
|
| 156 |
+
from hue_portal.core.embeddings import DEFAULT_MODEL_NAME
|
| 157 |
+
embedding_model = os.environ.get("EMBEDDING_MODEL", DEFAULT_MODEL_NAME)
|
| 158 |
+
print(f"Embedding: {embedding_model}")
|
| 159 |
+
|
| 160 |
+
# LLM summary
|
| 161 |
+
from hue_portal.chatbot.llm_integration import LLM_PROVIDER, LLM_PROVIDER_NONE
|
| 162 |
+
if LLM_PROVIDER == LLM_PROVIDER_NONE:
|
| 163 |
+
print("LLM: None (template-based only)")
|
| 164 |
+
else:
|
| 165 |
+
print(f"LLM: {LLM_PROVIDER}")
|
| 166 |
+
|
| 167 |
+
print("\n💡 Recommendations:")
|
| 168 |
+
print(" - Embedding: multilingual-mpnet (current) is good ✅")
|
| 169 |
+
print(" - LLM: Consider adding Qwen 2.5 for better answers")
|
| 170 |
+
print()
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
if __name__ == "__main__":
|
| 174 |
+
main()
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
|