-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_llm.py
More file actions
75 lines (65 loc) · 2.17 KB
/
Copy pathtest_llm.py
File metadata and controls
75 lines (65 loc) · 2.17 KB
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
#!/usr/bin/env python3
"""
Simple test to verify LLM connection with existing llama3.2 model
"""
import requests
import json
from config import LLM_MODEL_NAME
def test_ollama_connection():
"""Test connection to Ollama API"""
try:
# Test if API is responsive
response = requests.get("http://localhost:11434/api/tags", timeout=5)
if response.status_code == 200:
models = response.json().get('models', [])
print("✅ Ollama API is running")
print("Available models:")
for model in models:
print(f" - {model['name']}")
return True
else:
print("❌ Ollama API returned error")
return False
except Exception as e:
print(f"❌ Cannot connect to Ollama: {e}")
return False
def test_simple_generation():
"""Test simple text generation"""
try:
url = "http://localhost:11434/api/generate"
payload = {
"model": LLM_MODEL_NAME,
"prompt": "What is 2+2?",
"stream": False,
"options": {
"temperature": 0.2,
"num_predict": 10
}
}
print("\nTesting text generation...")
response = requests.post(url, json=payload, timeout=60)
if response.status_code == 200:
result = response.json()
answer = result.get('response', '').strip()
print("✅ Generation successful!")
print(f"Question: What is React?")
print(f"Answer: {answer}")
return True
else:
print(f"❌ Generation failed: {response.status_code}")
print(response.text)
return False
except Exception as e:
print(f"❌ Generation error: {e}")
return False
def main():
print("=== Ollama Connection Test ===\n")
if test_ollama_connection():
if test_simple_generation():
print("\n🎉 All tests passed! LLM is ready.")
else:
print("\n⚠️ LLM test failed.")
else:
print("\n❌ Connection test failed.")
if __name__ == "__main__":
main()