Download api-example.py from AffixIO/affixio-ollama: direct link, hf CLI and curl.
- Browser
- Download file 959 Bytes
-
https://huggingface.co/AffixIO/affixio-ollama/resolve/main/api-example.py
- Command line
-
hf download hf://AffixIO/affixio-ollama/api-example.py
-
curl -L -o api-example.py https://huggingface.co/AffixIO/affixio-ollama/resolve/main/api-example.py
959 Bytes
| """API + MCP connection examples (offline-safe; MCP part is illustrative).""" | |
| from __future__ import annotations | |
| import json, urllib.request | |
| OLLAMA_HOST = "http://localhost:11434" | |
| MODEL = "qwen2.5:0.5b" | |
| # 1) Direct Ollama HTTP API, proof_id attached (never the credential): | |
| proof_id = "afx_demo1234" | |
| body = json.dumps({"model": MODEL, "prompt": "say hi\n[proof_id=%s]" % proof_id, | |
| "stream": False}).encode() | |
| req = urllib.request.Request(OLLAMA_HOST + "/api/generate", data=body, | |
| headers={"Content-Type": "application/json"}) | |
| print("POST /api/generate -> model=%s proof_id=%s" % (MODEL, proof_id)) | |
| # 2) MCP pre-check before the model call (pseudo-flow using gate.py): | |
| from gate import verify | |
| decision, reason = verify("email.search", {"query": "invoice"}) | |
| print("MCP gate_tool_call(email.search) ->", decision, "-", reason) | |
| assert decision == "allow" | |
| print("OK - call the model only when decision == allow.") | |