Review this generated local summarization client before it handles private documents.
Summarize private documents through a local Ollama service with bounded latency, incremental delivery, and no sensitive-content logs.
Python
import json
from urllib.request import Request, urlopen
def summarize(document):
payload = {
"model": "gemma4",
"prompt": f"Summarize this document:\n{document}",
"stream": True,
"options": {"num_ctx": 131072},
}
request = Request(
"http://127.0.0.1:11434/api/generate",
data=json.dumps(payload).encode(),
headers={"Content-Type": "application/json"},
)
with urlopen(request) as response:
chunks = [json.loads(line) for line in response]
text = "".join(chunk.get("response", "") for chunk in chunks)
with open("requests.log", "a") as log:
log.write(document + "\n" + text + "\n")
return text
generated code is illustrative, not from any one model