Get LLM To Create Reports

This revision is from 2026/10/23 01:20. You can Restore it.

How to Run GLM Locally and Make It Write Polished Reports Like Z.ai

If you've watched Z.ai hand back a beautifully formatted PDF or Word document in seconds and wondered "can I do that on my own machine?" โ€” the answer is yes, but you have to understand that the magic isn't in the model alone. Polished reports come from model + agent loop + document libraries + style instructions working together. The model is just one ingredient.

This walkthrough covers the full stack: how to install a local GLM runtime, which quant to pick, how to wrap the model in an agent that can call tools, and the formatting rules that turn a wall of text into something you'd be proud to ship to a client. Let's build it piece by piece.

1. Pick your local runtime

There are four mainstream ways to run GLM locally. Which one you choose depends almost entirely on your hardware โ€” there's no "best" runtime, only the right one for your machine.

Runtime Best for Install
Ollama Easiest setup, good for 7Bโ€“70B quants, ships with an OpenAI-compatible server out of the box curl -fsSL https://ollama.com/install.sh | sh
vLLM Best throughput on NVIDIA GPUs, production-grade pip install vllm then vllm serve "zai-org/GLM-4.6"
llama.cpp CPU-only or mixed CPU/GPU, lowest memory footprint Build from source, use GGUF quants
MLX Apple Silicon (M-series Macs) pip install mlx-lm

For most people starting out, Ollama is the right call. It installs in one command, autodetects your GPU, and exposes an OpenAI-compatible endpoint that every agent framework on earth knows how to talk to. You can always graduate to vLLM later if you need higher throughput.

2. Pull the GLM model

GLM comes in a few sizes. The community-maintained Unsloth quants on Hugging Face are currently the most reliable GGUF files, and Ollama can pull them directly via the hf.co/ prefix:

# Smaller Air variant โ€” fits on 24โ€“48GB VRAM with quantization
ollama pull hf.co/unsloth/GLM-4.5-Air-GGUF:Q4_K_M

# Full GLM-4.6 (better quality, needs ~73GB for Q4)
ollama pull hf.co/unsloth/GLM-4.6-GGUF:TQ1_0

# Then run it
ollama run hf.co/unsloth/GLM-4.6-GGUF:TQ1_0

GLM-4.6 expanded the context window from 128K to 200K tokens, improved coding benchmarks, and โ€” most relevant for us โ€” refined its writing style to align more naturally with human preferences. If you have the VRAM, go straight to 4.6. If you're on a 24GB consumer card, the Air variant is a perfectly serviceable stand-in. Mac users should swap Ollama for MLX and call mlx_lm.load("zai-org/GLM-4.6") instead.

3. Expose it as an OpenAI-compatible API

Here's the underappreciated part: Ollama already exposes your local model on http://localhost:11434/v1 using the OpenAI chat completions schema. That means any agent framework built for OpenAI โ€” which is basically all of them โ€” will work with your local GLM for free, with zero code changes. Verify the endpoint works:

curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model":"hf.co/unsloth/GLM-4.6-GGUF:TQ1_0","messages":[{"role":"user","content":"hi"}]}'

If you get JSON back with a choices array, you're in business.

4. Wrap GLM in an agent loop with tools

This is the part most people skip, and it's the real secret to polished reports. Z.ai doesn't just ask the model for a report. It gives the model tools โ€” file-write access, web search, code execution โ€” and a skill system: Markdown instruction files that define exactly how each document type should be formatted. You can reproduce both halves locally.

Easy path โ€” use an existing agent UI

  • Open WebUI (pip install open-webui) โ€” connects to Ollama automatically, has a community marketplace of "tools" (Python functions the model can call), including write_docx, write_pdf, and friends.
  • Cline or Roo Code (VS Code extensions) โ€” point them at your local Ollama endpoint, hand them file-write and terminal tools. GLM-4.6 and 4.7 are explicitly tuned for these agent frameworks and the difference is visible.
  • Continue.dev โ€” similar pattern, good for inline workflows inside your editor.

Custom path โ€” write your own agent loop

  • OpenAI Agents SDK (pip install openai-agents) โ€” point base_url at Ollama, register tools as plain Python functions.
  • LangGraph or smolagents โ€” more control over multi-step reasoning and tool sequencing.

A minimal client looks like this:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:11434/v1",
    api_key="ollama",  # any non-empty string works
)

resp = client.chat.completions.create(
    model="hf.co/unsloth/GLM-4.6-GGUF:TQ1_0",
    messages=[{"role": "user", "content": "Write me a 3-section briefing on lithium supply chains."}],
)
print(resp.choices[0].message.content)

From here, the only limit is which tools you wire up.

5. Install the document libraries

The actual file production is done by Python libraries the model calls as tools, not by the model itself. The model decides what goes in the report; the libraries make it look good. Install the full stack:

pip install python-docx          # Word documents
pip install reportlab            # PDFs with full layout control
pip install openpyxl             # Excel spreadsheets
pip install python-pptx          # PowerPoint slides
pip install matplotlib seaborn   # charts and figures
pip install pandas               # data manipulation

# Optional but very useful:
pip install weasyprint           # HTML โ†’ PDF for prettier layouts
pip install jinja2               # templating for repeatable report structures

Once these are installed and exposed as tools the model can invoke, you've closed the gap between "the model produced text" and "the model produced a deliverable."

6. Mirror the "skills" pattern

The single biggest reason Z.ai's reports look polished is the skill files โ€” Markdown instructions that tell the model exactly how to format each document type. Cover page recipe, font choices, paragraph depth rules, page-break rules, character safety rules. Without these, the model produces generic Markdown and you get a mediocre PDF. With these, every report follows the same high bar.

You can build a minimal version on disk:

~/.glm-skills/
  โ”œโ”€โ”€ docx.md         # Word rules: fonts, TOC, no page breaks mid-section
  โ”œโ”€โ”€ pdf.md          # PDF rules: ReportLab, CJK font registration, character safety
  โ”œโ”€โ”€ xlsx.md         # Spreadsheet rules: header styling, freeze panes
  โ””โ”€โ”€ pptx.md         # Slide rules: one idea per slide, color palette

Each file is just Markdown the model reads as system context when asked to produce that document type. When the user says "make me a PDF," you load pdf.md into the system prompt, then let the model emit Python that calls ReportLab. You can harvest real skill files from open-source agent frameworks โ€” Z.ai has open-sourced model weights and several tools at github.com/zai-org, and the structural pattern is easy to adapt.

7. Add the "polish" rules

These are the actual differentiators. Steal them verbatim โ€” they're what separates a generic model output from a Z.ai-style deliverable:

  • Content depth. Every section โ‰ฅ150 words, every paragraph โ‰ฅ3 sentences. No bullet dumps masquerading as analysis.
  • Page breaks only between cover โ†” TOC and TOC โ†” body, never mid-section. Mid-section page breaks are the single most common formatting tell that something was generated by a model that didn't have rules.
  • Chinese and special characters. Register Noto Serif SC and Noto Sans SC fonts before generating PDFs, or you'll get tofu boxes (โ–กโ–กโ–ก) everywhere a CJK character should be.
  • Script persistence. Have the model write a .py file first, then you execute it. On failure, edit-and-rerun rather than regenerate the whole thing. This one rule cuts iteration cost 5โ€“10ร—.
  • Two-stage generation. First call an Outline step (just structure), then per-section generation calls. This is how you get long, coherent documents instead of shallow one-shot output where the model runs out of ideas halfway through.

8. A 30-second recipe to start today

If you want to be up and running by tonight, here's the shortest path:

# 1. Install Ollama + pull a GLM quant
curl -fsSL https://ollama.com/install.sh | sh
ollama pull hf.co/unsloth/GLM-4.6-GGUF:TQ1_0

# 2. Install Open WebUI for the agent surface
pip install open-webui
open-webui serve

# 3. Open http://localhost:8080
#    Settings โ†’ Connections โ†’ Ollama (auto-detected)
# 4. Install the "Document Tools" community pack
#    (docx / pdf / xlsx / pptx writers)
# 5. Add a custom system prompt containing the contents
#    of your skill files

From there, ask Open WebUI something like "Write me a 4-page briefing on grid-scale battery storage economics as a PDF." If the tools are wired up and the skill prompt is loaded, you'll get a real file back โ€” not just text in a chat window.

Wrapping up

The mental model to walk away with: the model is the brain, the agent loop is the hands, the Python libraries are the typewriter, and the skill files are the style guide. Skip any one of those four and the output drops a tier. Get all four right and you'll be producing Z.ai-quality deliverables on your own hardware, on your own data, with no API bill.

Start small: Ollama + one GLM quant + Open WebUI + the document tools pack. Get one clean PDF out of it. Then iterate on your skill files โ€” that's where most of the polish actually comes from, and it's the part you can keep improving forever.

  

๐Ÿ“ ๐Ÿ“œ โฑ๏ธ โฌ†๏ธ