""" Standard utils for this repository """ import requests import ollama from ollama import Client def connect_qumo_ollama(vm_name: str ='ollama-lite') -> Client: """Establish connection to Qumo Ollama instance vm_name: str ('ollama-lite' or 'hiperf-gpu') Name of the VM running the Ollama instance Returns: tuple(Client): Ollama client connected to the specified VM """ QUMO_OLLAMA_URL = f'http://{vm_name}.tail44fa00.ts.net:11434' try: requests.get(QUMO_OLLAMA_URL, timeout=5) client = Client( host=QUMO_OLLAMA_URL ) except requests.ConnectionError: print(f"Failed to reach {QUMO_OLLAMA_URL}. Check that the VM is running and Tailscale is up") print("Connection succesful.\nAvailable models:") for m in client.list().models: print(f" - '{m.model}' ") return client