Files
APAW/scripts/test_ollama_minimal.py
Deploy Bot 4071551476 feat(scripts): add real-fit evaluation engine and supporting test scripts
- real-fit-engine.py: refactored to support --from-report, improved Ollama v1/chat/completions compatibility, agent name normalization
- run-focused-eval.py: run evaluations for specific agent/model pairs from CLI
- test_ollama_minimal.py/test_real_api.py: Ollama API connectivity tests
- real-fit-architecture.md: architecture overview document
- tests/scripts/: E2E landing test, analytics capture, evolution heatmap verification
- Remove real-fit-recalc.py (superseded by --from-report flag)
2026-05-28 11:57:46 +01:00

60 lines
2.0 KiB
Python

#!/usr/bin/env python3
import urllib.request, json, os, time
def call_ollama_real(model_short, system_prompt, user_prompt):
key = os.environ.get("OLLAMA_KEY", "")
host = "https://ollama.com/v1"
payload = json.dumps({
"model": model_short,
"messages": [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
"temperature": 0.3,
"max_tokens": 2048
}).encode()
req = urllib.request.Request(
f"{host}/chat/completions",
data=payload,
headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {key}" if key else "Bearer",
"User-Agent": "Mozilla/5.0"
},
method="POST"
)
start = time.time()
try:
with urllib.request.urlopen(req, timeout=120) as resp:
data = json.loads(resp.read().decode())
text = data.get("choices", [{}])[0].get("message", {}).get("content", "")
usage = data.get("usage", {})
elapsed = int((time.time() - start) * 1000)
print(f"Status: {resp.status}")
print(f"Latency: {elapsed}ms")
print(f"Tokens: prompt={usage.get('prompt_tokens')}, completion={usage.get('completion_tokens')}")
return text
except urllib.error.HTTPError as e:
body = e.read().decode()[:200]
print(f"HTTP Error: {e.code} {e.reason}")
print(f"Body: {body}")
return ""
except Exception as e:
print(f"Error: {e}")
return ""
if __name__ == "__main__":
print("=== Test real Ollama API ===")
text = call_ollama_real(
"kimi-k2.6",
"You are a code reviewer. Find bugs.",
"Review: def f(x): return x+1"
)
print(f"\nResponse (first 300 chars):\n{text[:300]}")
print(f"\nTotal length: {len(text)} chars")
print(f"Keyword 'naming' in response: {'naming' in text.lower()}")
print(f"Keyword 'return' in response: {'return' in text.lower()}")