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.")