rdune71 commited on
Commit
d6aa39c
·
1 Parent(s): ec5a582

Update Ollama test with current URL and add URL update utility

Browse files
core/__pycache__/redis_client.cpython-313.pyc CHANGED
Binary files a/core/__pycache__/redis_client.cpython-313.pyc and b/core/__pycache__/redis_client.cpython-313.pyc differ
 
test_ollama_simple.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ # Load environment variables
6
+ load_dotenv()
7
+
8
+ # Use your current working ngrok URL
9
+ OLLAMA_HOST = "https://7bcc180dffd1.ngrok-free.app"
10
+ MODEL_NAME = "mistral:latest" # Default model
11
+
12
+ print(f"Testing Ollama connection to: {OLLAMA_HOST}")
13
+ print(f"Using model: {MODEL_NAME}")
14
+ print()
15
+
16
+ # Headers to skip ngrok browser warning
17
+ headers = {
18
+ "ngrok-skip-browser-warning": "true",
19
+ "User-Agent": "AI-Life-Coach-Test"
20
+ }
21
+
22
+ # Test 1: List models
23
+ print("Test 1: Listing available models...")
24
+ try:
25
+ response = requests.get(f"{OLLAMA_HOST}/api/tags", headers=headers, timeout=15)
26
+ print(f"Status Code: {response.status_code}")
27
+
28
+ if response.status_code == 200:
29
+ data = response.json()
30
+ models = data.get("models", [])
31
+ print(f"Found {len(models)} models:")
32
+ for model in models:
33
+ print(f" - {model['name']} ({model.get('size', 'Unknown size')})")
34
+ elif response.status_code == 404:
35
+ print("⚠️ Endpoint not found - checking root endpoint...")
36
+ # Try basic connectivity
37
+ response2 = requests.get(f"{OLLAMA_HOST}", headers=headers, timeout=15)
38
+ if response2.status_code == 200:
39
+ print("✓ Server is running but /api/tags endpoint not available")
40
+ else:
41
+ print(f"✗ Server returned: {response2.status_code}")
42
+ else:
43
+ print(f"Error: {response.text}")
44
+ except Exception as e:
45
+ print(f"Connection failed: {e}")
46
+
47
+ print()
48
+
49
+ # Test 2: Simple chat test
50
+ print("Test 2: Simple chat test...")
51
+ try:
52
+ payload = {
53
+ "model": MODEL_NAME,
54
+ "messages": [
55
+ {"role": "user", "content": "Hello! Respond with just 'Hi there!'"}
56
+ ],
57
+ "stream": False
58
+ }
59
+
60
+ response = requests.post(f"{OLLAMA_HOST}/api/chat", headers=headers, json=payload, timeout=30)
61
+ print(f"Status Code: {response.status_code}")
62
+
63
+ if response.status_code == 200:
64
+ data = response.json()
65
+ message = data.get("message", {})
66
+ content = message.get("content", "")
67
+ print(f"Response: {content}")
68
+ print("✅ Chat test successful!")
69
+ else:
70
+ print(f"Error: {response.text}")
71
+ except Exception as e:
72
+ print(f"Chat test failed: {e}")
73
+
74
+ print()
75
+ print("Test completed.")
update_ollama_url.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from pathlib import Path
4
+
5
+ def update_ollama_url(new_url):
6
+ """Update the Ollama URL in environment and config files"""
7
+
8
+ # Update .env file
9
+ env_file = Path(".env")
10
+ if env_file.exists():
11
+ with open(env_file, "r") as f:
12
+ lines = f.readlines()
13
+
14
+ with open(env_file, "w") as f:
15
+ for line in lines:
16
+ if line.startswith("OLLAMA_HOST="):
17
+ f.write(f"OLLAMA_HOST={new_url}\n")
18
+ else:
19
+ f.write(line)
20
+ print(f"✅ Updated .env file with new URL: {new_url}")
21
+ else:
22
+ # Create .env file
23
+ with open(env_file, "w") as f:
24
+ f.write(f"OLLAMA_HOST={new_url}\n")
25
+ print(f"✅ Created .env file with URL: {new_url}")
26
+
27
+ def test_url(url):
28
+ """Test if the URL is accessible"""
29
+ try:
30
+ headers = {
31
+ "ngrok-skip-browser-warning": "true",
32
+ "User-Agent": "AI-Life-Coach-URL-Tester"
33
+ }
34
+ response = requests.get(f"{url}/api/tags", headers=headers, timeout=10)
35
+ return response.status_code == 200
36
+ except:
37
+ return False
38
+
39
+ if __name__ == "__main__":
40
+ new_url = input("Enter your new ngrok URL (e.g., https://abcd1234.ngrok-free.app): ")
41
+
42
+ if new_url:
43
+ if test_url(new_url):
44
+ update_ollama_url(new_url)
45
+ print("✅ URL updated successfully!")
46
+ else:
47
+ print("❌ Warning: Could not verify the URL is accessible")
48
+ confirm = input("Do you want to update anyway? (y/n): ")
49
+ if confirm.lower() == 'y':
50
+ update_ollama_url(new_url)
51
+ print("✅ URL updated!")
52
+ else:
53
+ print("No URL provided.")