The uncensored local AI tier list
Your own AI on your own computer. Refuses nothing, works offline, your data never leaves the machine, and it can drive your computer for you. Mac, Windows or Linux. One pick per job, each linked to its source, with a copy-paste command.
- Runs offline
- Mac · Windows · Linux
- Ollama · LM Studio · MLX (Mac)
- Abliterated · heretic · fine-tunes
- Fits by RAM / VRAM: 8 · 16 · 32 · 64 GB
Fits = smallest memory where the file takes under ~70%, leaving room for context. Mac: unified memory. Windows/Linux: GPU VRAM (or system RAM on CPU, slower). Rule of thumb, not a guarantee.
Run it in 3 commands
Install Ollama, pull, run. Same on Mac, Windows and Linux. Any GGUF pick works the same: swap in its hf.co/<user>/<repo>:<quant>.
curl -fsSL https://ollama.com/install.sh | sh
# or download the app: https://ollama.com/download/Ollama.dmgollama pull hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_Mollama run hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M/set nothinkmkdir -p ~/localai && cd ~/localai
cat > Modelfile <<'MF'
FROM hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M
SYSTEM """You are my private assistant running offline on my computer.
Answer directly and completely. Be concise unless asked for detail.
If you are not sure about a fact, say so instead of guessing."""
PARAMETER num_ctx 32768
PARAMETER temperature 0.7
PARAMETER top_p 0.8
PARAMETER repeat_penalty 1.1
PARAMETER num_predict 2048
MF
ollama create uncensored -f Modelfile
ollama run uncensoredcurl http://localhost:11434/api/chat -d '{"model":"uncensored","messages":[{"role":"user","content":"hello"}],"stream":false}'ollama run uncensored --verbose "Write 200 words about the sea."irm https://ollama.com/install.ps1 | iex
# or run the installer: https://ollama.com/download/OllamaSetup.exeollama pull hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_Mollama run hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M/set nothinkmkdir $HOME\localai -Force; cd $HOME\localai
@'
FROM hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M
SYSTEM """You are my private assistant running offline on my computer.
Answer directly and completely. Be concise unless asked for detail.
If you are not sure about a fact, say so instead of guessing."""
PARAMETER num_ctx 32768
PARAMETER temperature 0.7
PARAMETER top_p 0.8
PARAMETER repeat_penalty 1.1
PARAMETER num_predict 2048
'@ | Set-Content -Encoding ascii Modelfile
ollama create uncensored -f Modelfile
ollama run uncensoredInvoke-RestMethod http://localhost:11434/api/chat -Method Post -ContentType 'application/json' -Body '{"model":"uncensored","messages":[{"role":"user","content":"hello"}],"stream":false}' | ForEach-Object { $_.message.content }ollama run uncensored --verbose "Write 200 words about the sea."curl -fsSL https://ollama.com/install.sh | shollama pull hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_Mollama run hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M/set nothinkmkdir -p ~/localai && cd ~/localai
cat > Modelfile <<'MF'
FROM hf.co/huihui-ai/Huihui-Qwen3.8-27B-abliterated-GGUF:UD-DW-Q4_K_M
SYSTEM """You are my private assistant running offline on my computer.
Answer directly and completely. Be concise unless asked for detail.
If you are not sure about a fact, say so instead of guessing."""
PARAMETER num_ctx 32768
PARAMETER temperature 0.7
PARAMETER top_p 0.8
PARAMETER repeat_penalty 1.1
PARAMETER num_predict 2048
MF
ollama create uncensored -f Modelfile
ollama run uncensoredcurl http://localhost:11434/api/chat -d '{"model":"uncensored","messages":[{"role":"user","content":"hello"}],"stream":false}'ollama run uncensored --verbose "Write 200 words about the sea."Let it control your computer
A local agent: the model picks a tool (open an app, run a command, read the screen, click, type), the script does it, shows the result, repeats. One script for Mac, one for Windows + Linux.
- AccessibilitySystem Settings → Privacy & Security → Accessibility → turn on Terminal.
- Screen RecordingSame place → Screen & System Audio Recording → Terminal.
- AutomationClick OK when macOS asks to let Terminal control apps.
- Restart TerminalCmd+Q, reopen. Done.
brew install cliclick tesseract
mkdir -p ~/agent && cd ~/agent
python3 -m venv .venv && source .venv/bin/activate
pip install requests ollama ocrmac pyautogui
# save mac_agent.py (below) into ~/agent, then:
python mac_agent.py "Open Notes and create a note titled Test that says hello"mac_agent.py · open apps, shell, read screen (Apple Vision OCR), click, type, hotkeys, AppleScript · 15-step limit · y/N confirmshow code
# mac_agent.py - a local AI that can operate your Mac (computer-use agent)
# Usage: python mac_agent.py "Open Safari and search for the weather in Lagos"
# python mac_agent.py --yolo "..." (skip the y/n confirmation; not recommended)
# Kill switch: run `touch ~/agent/STOP` in another Terminal tab; the loop stops before the next action.
import json, pathlib, subprocess, sys, requests
MODEL = "uncensored" # any Ollama model that supports tool calling
OLLAMA = "http://localhost:11434/api/chat"
MAX_STEPS = 15 # hard step limit
CONFIRM = "--yolo" not in sys.argv
AGENT_DIR = pathlib.Path.home() / "agent"
STOP = AGENT_DIR / "STOP"
SHOT = AGENT_DIR / "screen.png"
AGENT_DIR.mkdir(exist_ok=True)
def sh(cmd, timeout=60):
p = subprocess.run(cmd, shell=isinstance(cmd, str), capture_output=True, text=True, timeout=timeout)
return (p.stdout + p.stderr).strip()[-4000:] or "(no output)"
def screen_size():
# size of the main display in points, e.g. (1512, 982)
out = sh(["osascript", "-e", 'tell application "Finder" to get bounds of window of desktop'])
_, _, w, h = [int(v) for v in out.split(", ")]
return w, h
def ocr_screen():
from ocrmac import ocrmac # pip install ocrmac (uses Apple's Vision framework)
sh(["screencapture", "-x", str(SHOT)])
w, h = screen_size()
items = []
for text, conf, (x, y, bw, bh) in ocrmac.OCR(str(SHOT)).recognize():
cx, cy = int((x + bw / 2) * w), int((1 - (y + bh / 2)) * h) # Vision origin is bottom-left
items.append((text, cx, cy))
return items
# ---------------- tools the model can call ----------------
def open_app(name):
return sh(["open", "-a", name]) if name else "need an app name"
def open_url(url):
return sh(["open", url])
def run_shell(command):
return sh(command, timeout=120)
def applescript(script):
return sh(["osascript", "-e", script])
def read_screen():
items = ocr_screen()
return "\n".join(f"{t!r} at ({x},{y})" for t, x, y in items[:150]) or "no text found"
def click_text(text):
for t, x, y in ocr_screen():
if text.lower() in t.lower():
sh(["cliclick", f"c:{x},{y}"])
return f"clicked {t!r} at ({x},{y})"
return f"could not find {text!r} on screen; call read_screen first"
def click(x, y):
return sh(["cliclick", f"c:{int(x)},{int(y)}"]) or f"clicked ({x},{y})"
def type_text(text):
sh(["cliclick", "-w", "20", f"t:{text}"])
return f"typed {len(text)} characters"
def press_key(key):
# cliclick key names: return, esc, tab, space, delete, arrow-up, arrow-down, ...
return sh(["cliclick", f"kp:{key}"]) or f"pressed {key}"
def hotkey(key, modifiers="command"):
mods = ", ".join(f"{m.strip()} down" for m in modifiers.split(","))
return applescript(f'tell application "System Events" to keystroke "{key}" using {{{mods}}}')
def look(question="Describe what is on the screen."):
# optional: ask a vision model about a screenshot (needs a model with image input)
import base64
sh(["screencapture", "-x", str(SHOT)])
img = base64.b64encode(SHOT.read_bytes()).decode()
r = requests.post(OLLAMA, json={"model": VISION_MODEL, "stream": False,
"messages": [{"role": "user", "content": question, "images": [img]}]}, timeout=600)
return r.json()["message"]["content"]
VISION_MODEL = "qwen3-vl" # or your uncensored vision model; see the Vision section
FUNCS = {f.__name__: f for f in [open_app, open_url, run_shell, applescript, read_screen,
click_text, click, type_text, press_key, hotkey, look]}
def tool(fname, desc, **params):
return {"type": "function", "function": {"name": fname, "description": desc, "parameters": {
"type": "object", "properties": {k: {"type": t, "description": d} for k, (t, d) in params.items()},
"required": list(params)}}}
TOOLS = [
tool("open_app", "Open a Mac app by name, e.g. Safari, Notes, Terminal.", name=("string", "app name")),
tool("open_url", "Open a web address in the default browser.", url=("string", "full https URL")),
tool("run_shell", "Run a zsh command and return its output.", command=("string", "shell command")),
tool("applescript", "Run AppleScript to control an app.", script=("string", "AppleScript source")),
tool("read_screen", "Screenshot + OCR: list visible text with click coordinates."),
tool("click_text", "Find visible text on screen and click it.", text=("string", "text to click")),
tool("click", "Click at screen coordinates in points.", x=("integer", "x"), y=("integer", "y")),
tool("type_text", "Type text into the focused field.", text=("string", "text to type")),
tool("press_key", "Press one key: return, esc, tab, space, delete, arrow-down...", key=("string", "key name")),
tool("hotkey", "Press a shortcut, e.g. key t with modifiers command.",
key=("string", "a single character"), modifiers=("string", "comma list: command,shift,option,control")),
tool("look", "Ask a vision model a question about the current screen.", question=("string", "question")),
]
SYSTEM = """You control a macOS computer through tools. Work step by step:
1. Prefer open_app, open_url, applescript and run_shell over mouse clicks.
2. Before clicking, call read_screen to see what is there.
3. After each action, check the result. If something fails, try another way.
4. Never delete files, change passwords, send messages or buy anything unless the user explicitly asked.
5. When the task is finished, reply with a short summary and no tool call."""
def main():
task = " ".join(a for a in sys.argv[1:] if a != "--yolo") or input("Task: ")
STOP.unlink(missing_ok=True)
messages = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": task}]
for step in range(1, MAX_STEPS + 1):
if STOP.exists():
print("STOP file found, stopping."); return
r = requests.post(OLLAMA, json={"model": MODEL, "messages": messages, "tools": TOOLS,
"stream": False, "options": {"temperature": 0.2}}, timeout=600)
r.raise_for_status()
msg = r.json()["message"]
messages.append(msg)
calls = msg.get("tool_calls") or []
if not calls:
print(f"\nDone: {msg.get('content', '').strip()}"); return
for call in calls:
name = call["function"]["name"]
args = call["function"].get("arguments") or {}
if isinstance(args, str):
args = json.loads(args or "{}")
print(f"\n[step {step}] {name} {json.dumps(args)[:300]}")
if STOP.exists():
print("STOP file found, stopping."); return
if CONFIRM and input(" allow? [y/N] ").strip().lower() != "y":
result = "The user refused this action. Choose a different approach or stop."
elif name not in FUNCS:
result = f"unknown tool {name}"
else:
try:
result = str(FUNCS[name](**args))
except Exception as e:
result = f"error: {e}"
print(" ->", result[:500])
messages.append({"role": "tool", "tool_name": name, "content": result})
print(f"\nStep limit ({MAX_STEPS}) reached, stopping.")
if __name__ == "__main__":
main()cd ~/agent && source .venv/bin/activate
python mac_agent.py "Open Safari and go to youtube.com"touch ~/agent/STOP- PythonInstalled by the command below (python.org build via winget).
- Tesseract OCRGives the agent eyes. Also installed below.
- No permission promptsBut it can't click windows of apps running as administrator unless it runs as admin too.
- Fail-safeSlam the mouse into a screen corner to abort mid-action.
winget install Python.Python.3.12
winget install UB-Mannheim.TesseractOCR
# open a new PowerShell window, then:
mkdir $HOME\agent -Force; cd $HOME\agent
py -m venv .venv; .\.venv\Scripts\Activate.ps1
pip install requests pyautogui pytesseract pillow
# if Activate.ps1 is blocked: Set-ExecutionPolicy -Scope CurrentUser RemoteSignedpc_agent.py · Windows + Linux · open apps, PowerShell/bash, read screen (Tesseract OCR), click, type, hotkeys · 15-step limit · y/N confirmshow code
# pc_agent.py - a local AI that can operate your Windows or Linux PC
# Usage: python pc_agent.py "Open Notepad and type hello"
# python pc_agent.py --yolo "..." (skip the y/N confirmation; not recommended)
# Kill switch: create the file agent/STOP in your home folder; the loop stops before the next action.
# Fail-safe: slam the mouse into a screen corner to abort mid-action (pyautogui FAILSAFE).
import base64, io, json, pathlib, platform, subprocess, sys, webbrowser
import requests
import pyautogui # pip install pyautogui
import pytesseract # pip install pytesseract (+ the Tesseract program)
WINDOWS = platform.system() == "Windows"
MODEL = "uncensored" # any Ollama model that supports tool calling
VISION_MODEL = "qwen3-vl"
OLLAMA = "http://localhost:11434/api/chat"
MAX_STEPS = 15 # hard step limit
CONFIRM = "--yolo" not in sys.argv
AGENT_DIR = pathlib.Path.home() / "agent"
STOP = AGENT_DIR / "STOP"
AGENT_DIR.mkdir(exist_ok=True)
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.3
TESS = pathlib.Path(r"C:\Program Files\Tesseract-OCR\tesseract.exe")
if WINDOWS and TESS.exists():
pytesseract.pytesseract.tesseract_cmd = str(TESS)
def sh(cmd, timeout=120):
args = ["powershell", "-NoProfile", "-Command", cmd] if WINDOWS else ["bash", "-lc", cmd]
p = subprocess.run(args, capture_output=True, text=True, timeout=timeout)
return (p.stdout + p.stderr).strip()[-4000:] or "(no output)"
def ocr_screen():
img = pyautogui.screenshot()
scale = pyautogui.size()[0] / img.width # handles HiDPI screens
d = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)
lines = {}
for i, word in enumerate(d["text"]):
if word.strip() and float(d["conf"][i]) > 40:
key = (d["block_num"][i], d["par_num"][i], d["line_num"][i])
lines.setdefault(key, []).append(i)
items = []
for idx in lines.values():
text = " ".join(d["text"][i] for i in idx)
x0 = min(d["left"][i] for i in idx); x1 = max(d["left"][i] + d["width"][i] for i in idx)
y0 = min(d["top"][i] for i in idx); y1 = max(d["top"][i] + d["height"][i] for i in idx)
items.append((text, int((x0 + x1) / 2 * scale), int((y0 + y1) / 2 * scale)))
return items
# ---------------- tools the model can call ----------------
def open_app(name):
if WINDOWS:
subprocess.Popen(["cmd", "/c", "start", "", name]) # notepad, msedge, calc, ...
else:
subprocess.Popen([name], start_new_session=True, # firefox, gedit, nautilus, ...
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return f"launched {name}"
def open_url(url):
webbrowser.open(url)
return f"opened {url}"
def run_shell(command):
return sh(command)
def read_screen():
items = ocr_screen()
return "\n".join(f"{t!r} at ({x},{y})" for t, x, y in items[:150]) or "no text found"
def click_text(text):
for t, x, y in ocr_screen():
if text.lower() in t.lower():
pyautogui.click(x, y)
return f"clicked {t!r} at ({x},{y})"
return f"could not find {text!r} on screen; call read_screen first"
def click(x, y):
pyautogui.click(int(x), int(y))
return f"clicked ({x},{y})"
def type_text(text):
pyautogui.write(text, interval=0.02) # plain ASCII text
return f"typed {len(text)} characters"
def press_key(key):
pyautogui.press(key) # enter, esc, tab, space, backspace, up, down, win ...
return f"pressed {key}"
def hotkey(key, modifiers="ctrl"):
pyautogui.hotkey(*[m.strip() for m in modifiers.split(",")], key)
return f"pressed {modifiers}+{key}"
def look(question="Describe what is on the screen."):
buf = io.BytesIO()
pyautogui.screenshot().save(buf, format="PNG")
img = base64.b64encode(buf.getvalue()).decode()
r = requests.post(OLLAMA, json={"model": VISION_MODEL, "stream": False,
"messages": [{"role": "user", "content": question, "images": [img]}]}, timeout=600)
return r.json()["message"]["content"]
FUNCS = {f.__name__: f for f in [open_app, open_url, run_shell, read_screen,
click_text, click, type_text, press_key, hotkey, look]}
def tool(fname, desc, **params):
return {"type": "function", "function": {"name": fname, "description": desc, "parameters": {
"type": "object", "properties": {k: {"type": t, "description": d} for k, (t, d) in params.items()},
"required": list(params)}}}
SHELL = "PowerShell" if WINDOWS else "bash"
TOOLS = [
tool("open_app", "Start a program by name, e.g. " + ("notepad, msedge, calc." if WINDOWS else "firefox, gedit, nautilus."), name=("string", "program name")),
tool("open_url", "Open a web address in the default browser.", url=("string", "full https URL")),
tool("run_shell", f"Run a {SHELL} command and return its output.", command=("string", "command")),
tool("read_screen", "Screenshot + OCR: list visible text with click coordinates."),
tool("click_text", "Find visible text on screen and click it.", text=("string", "text to click")),
tool("click", "Click at screen coordinates.", x=("integer", "x"), y=("integer", "y")),
tool("type_text", "Type text into the focused field.", text=("string", "text to type")),
tool("press_key", "Press one key: enter, esc, tab, space, backspace, up, down, win ...", key=("string", "key name")),
tool("hotkey", "Press a shortcut, e.g. key t with modifiers ctrl.",
key=("string", "a single key"), modifiers=("string", "comma list: ctrl,shift,alt,win")),
tool("look", "Ask a vision model a question about the current screen.", question=("string", "question")),
]
SYSTEM = f"""You control a {platform.system()} computer through tools. Work step by step:
1. Prefer open_app, open_url and run_shell ({SHELL}) over mouse clicks.
2. Before clicking, call read_screen to see what is there.
3. After each action, check the result. If something fails, try another way.
4. Never delete files, change passwords, send messages or buy anything unless the user explicitly asked.
5. When the task is finished, reply with a short summary and no tool call."""
def main():
task = " ".join(a for a in sys.argv[1:] if a != "--yolo") or input("Task: ")
STOP.unlink(missing_ok=True)
messages = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": task}]
for step in range(1, MAX_STEPS + 1):
if STOP.exists():
print("STOP file found, stopping."); return
r = requests.post(OLLAMA, json={"model": MODEL, "messages": messages, "tools": TOOLS,
"stream": False, "options": {"temperature": 0.2}}, timeout=600)
r.raise_for_status()
msg = r.json()["message"]
messages.append(msg)
calls = msg.get("tool_calls") or []
if not calls:
print(f"\nDone: {msg.get('content', '').strip()}"); return
for call in calls:
name = call["function"]["name"]
args = call["function"].get("arguments") or {}
if isinstance(args, str):
args = json.loads(args or "{}")
print(f"\n[step {step}] {name} {json.dumps(args)[:300]}")
if STOP.exists():
print("STOP file found, stopping."); return
if CONFIRM and input(" allow? [y/N] ").strip().lower() != "y":
result = "The user refused this action. Choose a different approach or stop."
elif name not in FUNCS:
result = f"unknown tool {name}"
else:
try:
result = str(FUNCS[name](**args))
except Exception as e:
result = f"error: {e}"
print(" ->", result[:500])
messages.append({"role": "tool", "tool_name": name, "content": result})
print(f"\nStep limit ({MAX_STEPS}) reached, stopping.")
if __name__ == "__main__":
main()cd $HOME\agent; .\.venv\Scripts\Activate.ps1
python pc_agent.py "Open Notepad and type hello"New-Item $HOME\agent\STOP- X11 sessionpyautogui and xdotool need X11. On Wayland, pick “Ubuntu on Xorg” at login, or look at ydotool.
- PackagesTesseract, scrot and Tk, installed below (Debian/Ubuntu names).
- No permission promptsRuns as your user; it can't type into sudo password prompts for you.
- Fail-safeSlam the mouse into a screen corner to abort mid-action.
sudo apt install tesseract-ocr scrot python3-tk python3-dev python3-venv xdotool
mkdir -p ~/agent && cd ~/agent
python3 -m venv .venv && source .venv/bin/activate
pip install requests pyautogui pytesseract pillowpc_agent.py · Windows + Linux · open apps, PowerShell/bash, read screen (Tesseract OCR), click, type, hotkeys · 15-step limit · y/N confirmshow code
# pc_agent.py - a local AI that can operate your Windows or Linux PC
# Usage: python pc_agent.py "Open Notepad and type hello"
# python pc_agent.py --yolo "..." (skip the y/N confirmation; not recommended)
# Kill switch: create the file agent/STOP in your home folder; the loop stops before the next action.
# Fail-safe: slam the mouse into a screen corner to abort mid-action (pyautogui FAILSAFE).
import base64, io, json, pathlib, platform, subprocess, sys, webbrowser
import requests
import pyautogui # pip install pyautogui
import pytesseract # pip install pytesseract (+ the Tesseract program)
WINDOWS = platform.system() == "Windows"
MODEL = "uncensored" # any Ollama model that supports tool calling
VISION_MODEL = "qwen3-vl"
OLLAMA = "http://localhost:11434/api/chat"
MAX_STEPS = 15 # hard step limit
CONFIRM = "--yolo" not in sys.argv
AGENT_DIR = pathlib.Path.home() / "agent"
STOP = AGENT_DIR / "STOP"
AGENT_DIR.mkdir(exist_ok=True)
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.3
TESS = pathlib.Path(r"C:\Program Files\Tesseract-OCR\tesseract.exe")
if WINDOWS and TESS.exists():
pytesseract.pytesseract.tesseract_cmd = str(TESS)
def sh(cmd, timeout=120):
args = ["powershell", "-NoProfile", "-Command", cmd] if WINDOWS else ["bash", "-lc", cmd]
p = subprocess.run(args, capture_output=True, text=True, timeout=timeout)
return (p.stdout + p.stderr).strip()[-4000:] or "(no output)"
def ocr_screen():
img = pyautogui.screenshot()
scale = pyautogui.size()[0] / img.width # handles HiDPI screens
d = pytesseract.image_to_data(img, output_type=pytesseract.Output.DICT)
lines = {}
for i, word in enumerate(d["text"]):
if word.strip() and float(d["conf"][i]) > 40:
key = (d["block_num"][i], d["par_num"][i], d["line_num"][i])
lines.setdefault(key, []).append(i)
items = []
for idx in lines.values():
text = " ".join(d["text"][i] for i in idx)
x0 = min(d["left"][i] for i in idx); x1 = max(d["left"][i] + d["width"][i] for i in idx)
y0 = min(d["top"][i] for i in idx); y1 = max(d["top"][i] + d["height"][i] for i in idx)
items.append((text, int((x0 + x1) / 2 * scale), int((y0 + y1) / 2 * scale)))
return items
# ---------------- tools the model can call ----------------
def open_app(name):
if WINDOWS:
subprocess.Popen(["cmd", "/c", "start", "", name]) # notepad, msedge, calc, ...
else:
subprocess.Popen([name], start_new_session=True, # firefox, gedit, nautilus, ...
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return f"launched {name}"
def open_url(url):
webbrowser.open(url)
return f"opened {url}"
def run_shell(command):
return sh(command)
def read_screen():
items = ocr_screen()
return "\n".join(f"{t!r} at ({x},{y})" for t, x, y in items[:150]) or "no text found"
def click_text(text):
for t, x, y in ocr_screen():
if text.lower() in t.lower():
pyautogui.click(x, y)
return f"clicked {t!r} at ({x},{y})"
return f"could not find {text!r} on screen; call read_screen first"
def click(x, y):
pyautogui.click(int(x), int(y))
return f"clicked ({x},{y})"
def type_text(text):
pyautogui.write(text, interval=0.02) # plain ASCII text
return f"typed {len(text)} characters"
def press_key(key):
pyautogui.press(key) # enter, esc, tab, space, backspace, up, down, win ...
return f"pressed {key}"
def hotkey(key, modifiers="ctrl"):
pyautogui.hotkey(*[m.strip() for m in modifiers.split(",")], key)
return f"pressed {modifiers}+{key}"
def look(question="Describe what is on the screen."):
buf = io.BytesIO()
pyautogui.screenshot().save(buf, format="PNG")
img = base64.b64encode(buf.getvalue()).decode()
r = requests.post(OLLAMA, json={"model": VISION_MODEL, "stream": False,
"messages": [{"role": "user", "content": question, "images": [img]}]}, timeout=600)
return r.json()["message"]["content"]
FUNCS = {f.__name__: f for f in [open_app, open_url, run_shell, read_screen,
click_text, click, type_text, press_key, hotkey, look]}
def tool(fname, desc, **params):
return {"type": "function", "function": {"name": fname, "description": desc, "parameters": {
"type": "object", "properties": {k: {"type": t, "description": d} for k, (t, d) in params.items()},
"required": list(params)}}}
SHELL = "PowerShell" if WINDOWS else "bash"
TOOLS = [
tool("open_app", "Start a program by name, e.g. " + ("notepad, msedge, calc." if WINDOWS else "firefox, gedit, nautilus."), name=("string", "program name")),
tool("open_url", "Open a web address in the default browser.", url=("string", "full https URL")),
tool("run_shell", f"Run a {SHELL} command and return its output.", command=("string", "command")),
tool("read_screen", "Screenshot + OCR: list visible text with click coordinates."),
tool("click_text", "Find visible text on screen and click it.", text=("string", "text to click")),
tool("click", "Click at screen coordinates.", x=("integer", "x"), y=("integer", "y")),
tool("type_text", "Type text into the focused field.", text=("string", "text to type")),
tool("press_key", "Press one key: enter, esc, tab, space, backspace, up, down, win ...", key=("string", "key name")),
tool("hotkey", "Press a shortcut, e.g. key t with modifiers ctrl.",
key=("string", "a single key"), modifiers=("string", "comma list: ctrl,shift,alt,win")),
tool("look", "Ask a vision model a question about the current screen.", question=("string", "question")),
]
SYSTEM = f"""You control a {platform.system()} computer through tools. Work step by step:
1. Prefer open_app, open_url and run_shell ({SHELL}) over mouse clicks.
2. Before clicking, call read_screen to see what is there.
3. After each action, check the result. If something fails, try another way.
4. Never delete files, change passwords, send messages or buy anything unless the user explicitly asked.
5. When the task is finished, reply with a short summary and no tool call."""
def main():
task = " ".join(a for a in sys.argv[1:] if a != "--yolo") or input("Task: ")
STOP.unlink(missing_ok=True)
messages = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": task}]
for step in range(1, MAX_STEPS + 1):
if STOP.exists():
print("STOP file found, stopping."); return
r = requests.post(OLLAMA, json={"model": MODEL, "messages": messages, "tools": TOOLS,
"stream": False, "options": {"temperature": 0.2}}, timeout=600)
r.raise_for_status()
msg = r.json()["message"]
messages.append(msg)
calls = msg.get("tool_calls") or []
if not calls:
print(f"\nDone: {msg.get('content', '').strip()}"); return
for call in calls:
name = call["function"]["name"]
args = call["function"].get("arguments") or {}
if isinstance(args, str):
args = json.loads(args or "{}")
print(f"\n[step {step}] {name} {json.dumps(args)[:300]}")
if STOP.exists():
print("STOP file found, stopping."); return
if CONFIRM and input(" allow? [y/N] ").strip().lower() != "y":
result = "The user refused this action. Choose a different approach or stop."
elif name not in FUNCS:
result = f"unknown tool {name}"
else:
try:
result = str(FUNCS[name](**args))
except Exception as e:
result = f"error: {e}"
print(" ->", result[:500])
messages.append({"role": "tool", "tool_name": name, "content": result})
print(f"\nStep limit ({MAX_STEPS}) reached, stopping.")
if __name__ == "__main__":
main()cd ~/agent && source .venv/bin/activate
python pc_agent.py "Open Firefox and go to youtube.com"touch ~/agent/STOPxdotool mousemove 640 400 click 1 # click
xdotool type 'hello world' # type
xdotool key ctrl+t # shortcut
xdotool search --name Firefox windowactivate # focus a windowIt can run any shell command. Keep the y/N confirm on (no --yolo), keep backups, and keep the STOP file one window away.
More it can do
Chat with your files, remember conversations, talk out loud, call your own functions. All local.
rag.py · ask questions about your own files · all OSesshow code
# rag.py - ask questions about your own files, 100% local
# Usage: python rag.py index ~/Documents/notes
# python rag.py ask "What did I decide about the logo?"
import json, math, pathlib, sys, requests
OLLAMA = "http://localhost:11434"
EMBED_MODEL = "nomic-embed-text"
CHAT_MODEL = "uncensored"
DB = pathlib.Path.home() / "localai" / "rag_index.json"
EXTS = {".txt", ".md", ".py", ".js", ".html", ".csv", ".json"}
def embed(texts):
r = requests.post(f"{OLLAMA}/api/embed",
json={"model": EMBED_MODEL, "input": texts}, timeout=600)
r.raise_for_status()
return r.json()["embeddings"]
def chunks(text, size=1200, overlap=200):
i = 0
while i < len(text):
yield text[i:i + size]
i += size - overlap
def cosine(a, b):
dot = sum(x * y for x, y in zip(a, b))
return dot / (math.sqrt(sum(x * x for x in a)) * math.sqrt(sum(y * y for y in b)) + 1e-9)
def index(folder):
items = []
for p in pathlib.Path(folder).expanduser().rglob("*"):
if p.is_file() and p.suffix.lower() in EXTS:
text = p.read_text(errors="ignore")
parts = [c for c in chunks(text) if c.strip()]
for start in range(0, len(parts), 32):
batch = parts[start:start + 32]
vecs = embed(["search_document: " + c for c in batch])
items += [{"file": str(p), "text": c, "vec": v} for c, v in zip(batch, vecs)]
print(f"indexed {p}")
DB.parent.mkdir(parents=True, exist_ok=True)
DB.write_text(json.dumps(items))
print(f"\n{len(items)} chunks saved to {DB}")
def ask(question, k=5):
items = json.loads(DB.read_text())
qv = embed(["search_query: " + question])[0]
top = sorted(items, key=lambda it: cosine(qv, it["vec"]), reverse=True)[:k]
context = "\n\n".join(f"[{it['file']}]\n{it['text']}" for it in top)
msgs = [
{"role": "system", "content": "Answer using only the context. Cite the file names you used."},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"},
]
r = requests.post(f"{OLLAMA}/api/chat",
json={"model": CHAT_MODEL, "messages": msgs, "stream": False}, timeout=600)
r.raise_for_status()
print(r.json()["message"]["content"])
if __name__ == "__main__":
if len(sys.argv) < 3 or sys.argv[1] not in ("index", "ask"):
sys.exit('usage: rag.py index FOLDER | rag.py ask "question"')
index(sys.argv[2]) if sys.argv[1] == "index" else ask(" ".join(sys.argv[2:]))chat_cli.py · terminal chat that remembers · all OSesshow code
# chat_cli.py - terminal chat with memory that survives restarts
# Commands: /reset /model NAME /system TEXT /quit
import json, pathlib, requests
URL = "http://localhost:11434/api/chat"
HIST = pathlib.Path.home() / "localai" / "history.json"
HIST.parent.mkdir(parents=True, exist_ok=True)
model = "uncensored"
system = "You are a direct, helpful assistant running locally on my computer."
history = json.loads(HIST.read_text()) if HIST.exists() else []
def save():
HIST.write_text(json.dumps(history[-200:], indent=2))
print(f"Model: {model}. Type /quit to exit.")
while True:
try:
user = input("\nyou> ").strip()
except (EOFError, KeyboardInterrupt):
break
if not user:
continue
if user == "/quit":
break
if user == "/reset":
history.clear(); save(); print("History cleared."); continue
if user.startswith("/model "):
model = user.split(maxsplit=1)[1]; print(f"Model -> {model}"); continue
if user.startswith("/system "):
system = user.split(maxsplit=1)[1]; print("System prompt updated."); continue
history.append({"role": "user", "content": user})
msgs = [{"role": "system", "content": system}] + history[-40:]
print("ai> ", end="", flush=True)
reply = ""
with requests.post(URL, json={"model": model, "messages": msgs, "stream": True},
stream=True, timeout=600) as r:
r.raise_for_status()
for line in r.iter_lines():
if line:
part = json.loads(line).get("message", {}).get("content", "")
reply += part
print(part, end="", flush=True)
history.append({"role": "assistant", "content": reply})
save()
print("\nBye.")tools_demo.py · tool calling basics · all OSesshow code
# tools_demo.py - let the model call your Python functions
import datetime, shutil
from ollama import chat # pip install ollama
def get_time() -> str:
"""Get the current local date and time."""
return datetime.datetime.now().strftime("%A %d %B %Y, %H:%M")
def disk_free(path: str = "/") -> str:
"""Get free disk space in GB for a path.
Args:
path: folder to check, for example /
"""
return f"{shutil.disk_usage(path).free / 1e9:.1f} GB free"
TOOLS = {"get_time": get_time, "disk_free": disk_free}
MODEL = "uncensored"
messages = [{"role": "user", "content": "What time is it, and how much disk space do I have left?"}]
while True:
resp = chat(model=MODEL, messages=messages, tools=list(TOOLS.values()))
messages.append(resp.message)
if not resp.message.tool_calls:
print(resp.message.content)
break
for call in resp.message.tool_calls:
fn = TOOLS.get(call.function.name)
result = fn(**call.function.arguments) if fn else "unknown tool"
print(f"[tool] {call.function.name}({call.function.arguments}) -> {result}")
messages.append({"role": "tool", "tool_name": call.function.name, "content": str(result)})voice_chat.py · talk to it, hear it answer · Mac as writtenshow code
mkdir -p ~/localai/whisper && curl -L -o ~/localai/whisper/ggml-base.en.bin https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-base.en.bin# voice_chat.py - talk to your local AI: mic -> whisper.cpp -> Ollama -> macOS `say`
# Needs: brew install whisper.cpp ffmpeg, plus the model file in ~/localai/whisper/
import pathlib, subprocess, requests
HOME = pathlib.Path.home() / "localai"
WHISPER_MODEL = HOME / "whisper" / "ggml-base.en.bin"
WAV = HOME / "mic.wav"
MODEL = "uncensored"
SECONDS = 6
history = [{"role": "system", "content": "You are a voice assistant. Answer in 1-3 short spoken sentences, no markdown."}]
while True:
input(f"\nPress Enter and speak for {SECONDS} seconds (Ctrl+C to quit)...")
subprocess.run(["ffmpeg", "-y", "-loglevel", "error", "-f", "avfoundation", "-i", ":0",
"-t", str(SECONDS), "-ar", "16000", "-ac", "1", str(WAV)], check=True)
out = subprocess.run(["whisper-cli", "-m", str(WHISPER_MODEL), "-f", str(WAV), "-nt", "-np"],
capture_output=True, text=True, check=True)
heard = out.stdout.strip()
print("you said:", heard)
if not heard:
continue
history.append({"role": "user", "content": heard})
r = requests.post("http://localhost:11434/api/chat",
json={"model": MODEL, "messages": history[-20:], "stream": False}, timeout=600)
answer = r.json()["message"]["content"]
history.append({"role": "assistant", "content": answer})
print("ai:", answer)
subprocess.run(["say", answer])Windows/Linux: change the ffmpeg input -f avfoundation -i :0 to -f dshow (Windows) or -f alsa -i default (Linux), and swap macOS say for a local text-to-speech such as espeak-ng on Linux.
Watch it first
9 walkthroughs. Tap to play.
FAQ
What do “abliterated”, “heretic” and “fine-tune” mean?
Abliterated and heretic remove the refusal behaviour from the weights, so the model answers instead of declining. Fine-tunes like Hermes or Cydonia are retrained instead. Fewer refusals, not more brains: it still gets things wrong.
Will it fit on my computer?
Look at the “Fits” badge: the smallest RAM/VRAM where the file takes under ~70%, leaving room for context. Mac: count your unified memory. Windows/Linux: count your GPU's VRAM. Too big for the GPU? Ollama splits it onto CPU and system RAM: it still runs, just slower. ollama ps shows the split.
Which GPUs work on Windows and Linux?
NVIDIA cards, and many recent AMD Radeon cards (ROCm, plus Vulkan for more). Apple silicon Macs use Metal automatically. Full list: docs.ollama.com/gpu.
Ollama or LM Studio?
Ollama for the terminal, scripts and the agent, on all three OSes. LM Studio if you want a desktop app (Mac, Windows, Linux); it also runs the MLX picks on Apple silicon. MLX is Mac-only.
It still refuses. Now what?
Put a clear system prompt in the Modelfile, turn thinking off, try a heretic pick, rephrase. Abliteration cuts refusals, it doesn't promise zero.
Use it from my phone?
Make Ollama listen on your network with OLLAMA_HOST=0.0.0.0:11434, then open Open WebUI at your computer's IP on port 3000. Mac: launchctl setenv OLLAMA_HOST "0.0.0.0:11434" and restart Ollama. Windows: Settings → search “environment variables” → Edit environment variables for your account → add OLLAMA_HOST, restart Ollama. Linux: sudo systemctl edit ollama.service, add Environment="OLLAMA_HOST=0.0.0.0:11434" under [Service], then sudo systemctl restart ollama. Trusted Wi-Fi only.
Where are the model files?
Mac: ~/.ollama/models. Windows: C:\Users\%username%\.ollama\models. Linux: /usr/share/ollama/.ollama/models. Move them with the OLLAMA_MODELS variable, set the same way as OLLAMA_HOST.
Port 11434 busy?
Ollama's already running, that's fine. Don't start a second copy (the app plus ollama serve).
What if a model gets removed?
Keep a copy of the exact file you tested: back up the models folder above to an external drive.
Is this safe?
After download it's fully offline. The agents can run shell commands, so keep their y/N confirm on, keep backups, and use the STOP file. No filter means it's on you: illegal stays illegal.