This commit is contained in:
2026-04-05 00:43:23 +05:30
commit 8be37d3e92
425 changed files with 101853 additions and 0 deletions

44
thirdeye/test_ollama.py Normal file
View File

@@ -0,0 +1,44 @@
"""Quick smoke-test for Ollama before wiring it into the main bot."""
import asyncio
import httpx
async def test_ollama():
print("1. Checking if Ollama is reachable at http://localhost:11434 ...")
try:
async with httpx.AsyncClient(timeout=5) as c:
r = await c.get("http://localhost:11434/api/tags")
if r.status_code == 200:
models = [m["name"] for m in r.json().get("models", [])]
print(f" OK — models available: {models or '(none pulled yet)'}")
if not any("llama3" in m for m in models):
print("\n WARNING: llama3:8b not pulled yet.")
print(" Run in a separate terminal: ollama pull llama3:8b")
return
else:
print(f" FAIL — unexpected status {r.status_code}")
return
except Exception as e:
print(f" FAIL — cannot reach Ollama: {e}")
print("\n Fix: open a new terminal and run: ollama serve")
return
print("\n2. Testing chat completion (OpenAI-compat endpoint) ...")
try:
from openai import AsyncOpenAI
client = AsyncOpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
resp = await client.chat.completions.create(
model="llama3:8b",
messages=[{"role": "user", "content": "Reply with exactly: ollama ok"}],
max_tokens=20,
temperature=0,
)
reply = resp.choices[0].message.content.strip()
print(f" Model reply: {reply}")
print("\n PASS — Ollama is working. Safe to restart the bot.")
except Exception as e:
print(f" FAIL — {e}")
asyncio.run(test_ollama())