Aniruddha7/QueryLens-Text2SQL_DocVQA-V2
0
1import os, time, json, sys2from llama_index.llms.ollama import Ollama3 4BASE_URL = os.environ.get("OLLAMA_BASE_URL", "http://localhost:11434")5MODEL = os.environ.get("FINETUNED_MODEL_NAME") or os.environ.get("OLLAMA_MODEL_NAME", "gemma3:1b")6 7print(f"Checking Ollama LLM connectivity: base_url={BASE_URL} model={MODEL}")8 9# Lightweight client check without llama_index first (raw HTTP) to see if daemon responds10try:11 import requests12 r = requests.get(f"{BASE_URL.rstrip('/')}/api/tags", timeout=5)13 print(f"/api/tags status: {r.status_code}")14 if r.ok:15 tags = r.json().get('models', [])16 names = [m.get('name') for m in tags]17 print(f"Available models: {names}")18 if MODEL not in names:19 print(f"Model '{MODEL}' not yet pulled. Run: ollama pull {MODEL}")20 else:21 print("Non-200 response from Ollama daemon")22except Exception as e:23 print(f"Raw HTTP check failed: {e}")24 25# LlamaIndex call26try:27 llm = Ollama(model=MODEL, base_url=BASE_URL, temperature=0.1, request_timeout=30)28 t0 = time.time()29 resp = llm.complete(prompt="SELECT 1;")30 dt = time.time() - t031 print(f"LLM call success in {dt:.2f}s. Raw text: {resp.text[:120]!r}")32except Exception as e:33 print(f"LLM complete() failed: {type(e).__name__}: {e}")34 sys.exit(1)35 36print("Health check finished.")37 