Spaces:
Sleeping
Sleeping
File size: 3,241 Bytes
1220b7a 8f5ac7b 1220b7a 8f5ac7b 1220b7a 8f5ac7b 1220b7a 8f5ac7b 1220b7a 8f5ac7b 1220b7a | 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 | import httpx
import sys
URL = "http://localhost:8000/whatsapp/test-chat"
MODELS = [
"xiaomi/mimo-v2-flash",
"minimax/minimax-m2.7",
"deepseek/deepseek-v3.2",
"qwen/qwen3.5-flash-02-23",
"google/gemini-3.1-flash-lite-preview",
"z-ai/glm-4.7-flash",
"openai/gpt-5.4-nano",
]
def select_model():
print("\n[ Select LLM Model for Testing ]")
for i, model in enumerate(MODELS, 1):
print(f" {i}. {model}")
print(f" 0. (Default) Gunakan OPENROUTER_CHATBOT_MODEL dari .env")
while True:
try:
choice = input("\nPilih angka model (0-7): ").strip()
if not choice:
return None
idx = int(choice)
if idx == 0:
return None
if 1 <= idx <= len(MODELS):
return MODELS[idx - 1]
print("Pilihan tidak valid.")
except ValueError:
print("Masukkan angka.")
def main():
print("========================================")
print("FitMate Bot CLI Tester")
print("========================================")
selected_model = select_model()
model_display = selected_model if selected_model else "Default Config (.env)"
print("\n========================================")
print(f"[Active Model] {model_display}")
print("Ketik pesan dan tekan Enter.")
print("Ketik 'quit' atau 'exit' untuk berhenti.")
print("Pastikan server FastAPI berjalan di terminal lain!")
print("========================================\n")
sender = "cli_test_user_v2"
while True:
try:
user_msg = input("\n[Kamu]: ")
if user_msg.lower() in ("quit", "exit"):
break
if not user_msg.strip():
continue
print(f"[Evaluasi] Menggunakan {model_display}...")
payload = {"sender": sender, "message": user_msg}
if selected_model:
payload["model"] = selected_model
response = httpx.post(
URL,
json=payload,
timeout=45.0
)
if response.status_code == 200:
data = response.json()
reply = data.get("reply", "")
welcome = data.get("welcome_message", "")
if welcome:
print(f"\n[FitMate]:\n{welcome}\n")
print(f"[FitMate]: {reply}")
ext = data.get('ingredient_extracted')
ingredient_display = ext if ext else "None"
print(f"\n (Debug: Intent='{data.get('intent')}' | Ingredient='{ingredient_display}')")
else:
print(f"\n[Error]: Server respond with status code {response.status_code}")
print(response.text)
except httpx.RequestError as e:
print(f"\n[Error]: Cannot connect to backend.")
print("Make sure your FastAPI server is running! (e.g. 'uvicorn main:app --reload')")
except KeyboardInterrupt:
print("\nBot tester closed. Goodbye.")
break
if __name__ == "__main__":
main()
|