File size: 1,735 Bytes
d6aa39c |
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 |
import requests
import os
from pathlib import Path
def update_ollama_url(new_url):
"""Update the Ollama URL in environment and config files"""
# Update .env file
env_file = Path(".env")
if env_file.exists():
with open(env_file, "r") as f:
lines = f.readlines()
with open(env_file, "w") as f:
for line in lines:
if line.startswith("OLLAMA_HOST="):
f.write(f"OLLAMA_HOST={new_url}\n")
else:
f.write(line)
print(f"✅ Updated .env file with new URL: {new_url}")
else:
# Create .env file
with open(env_file, "w") as f:
f.write(f"OLLAMA_HOST={new_url}\n")
print(f"✅ Created .env file with URL: {new_url}")
def test_url(url):
"""Test if the URL is accessible"""
try:
headers = {
"ngrok-skip-browser-warning": "true",
"User-Agent": "AI-Life-Coach-URL-Tester"
}
response = requests.get(f"{url}/api/tags", headers=headers, timeout=10)
return response.status_code == 200
except:
return False
if __name__ == "__main__":
new_url = input("Enter your new ngrok URL (e.g., https://abcd1234.ngrok-free.app): ")
if new_url:
if test_url(new_url):
update_ollama_url(new_url)
print("✅ URL updated successfully!")
else:
print("❌ Warning: Could not verify the URL is accessible")
confirm = input("Do you want to update anyway? (y/n): ")
if confirm.lower() == 'y':
update_ollama_url(new_url)
print("✅ URL updated!")
else:
print("No URL provided.")
|