跳到正文
DEV Community· Heramb Inamke·· 3 小時前AI 評分56

slothsort 用 llama3.2:3b 自動整理 Downloads 資料夾

🦥 slothsort: my Downloads folder now cleans itself while I sleep.

AI 導讀

Heramb Inamke 開發 slothsort,使用 Ollama 本機運行的 llama3.2:3b 為 Downloads 資料夾內的檔案分類、產生易讀檔名並移入子資料夾。工具預設以 dry run 預覽,加入 `--apply` 才會移動檔案,並可用 `undo` 還原;作者表示工具可離線運作,檔案不會離開電腦。作者在配備 RTX 4050 的筆電上處理 16 個檔案,約需 39 s。

正文

Cover image for 🦥 slothsort: my Downloads folder now cleans itself while I sleep.

Heramb Inamke

Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady Submission 🦥

Title: 🦥 slothsort: my Downloads folder now cleans itself while I sleep
Tags: devchallenge, hf26challenge, ai, python


This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady

https://github.com/HerambInamke/Hacktoberfest-Open-Source-AI-Challenge-Week-3

What I Built

My Downloads folder had become a graveyard: download (3).txt, IMG_20240712_183455.jpg, script_final_FINAL.py, Resume_v7_really_final.pdf. Sorting it was always a "tomorrow" job.

slothsort does it for me. It's a single Python file. A small open-weight model (llama3.2:3b) running locally in Ollama reads each file's name, plus the first 500 characters of text files, and picks a category and a readable name. Then it moves the files into folders like Receipts, Code, Installers and Archives.

It runs as a dry run by default. --apply moves the files, and undo puts every file back exactly where it was. One schtasks line runs it at 3 AM every night, so the person who gets to be lazier is me: I never sort Downloads by hand again.

Demo

Real output from python slothsort.py demo (llama3.2:3b on a laptop RTX 4050, 16 files in about 39 s):

download (3).txt                ->  Receipts\Invoice 4821.txt
export_20260912.csv             ->  Documents\Export Scores.csv
logs-sept.tar.gz                ->  Archives\System Logs.tar.gz
notes(1).md                     ->  Documents\Meeting Notes.md
order_confirmation.txt          ->  Receipts\Order Confirmed.txt
script_final_FINAL.py           ->  Code\Final Fibonacci Function.py
untitled.txt                    ->  Documents\Grocery List.txt
VSCodeUserSetup-x64-1.94.2.exe  ->  Installers\Visual Studio Code Setup.exe

Try it yourself:

winget install Ollama.Ollama
ollama pull llama3.2:3b
python slothsort.py demo           # see the plan
python slothsort.py demo --apply   # sort
python slothsort.py demo undo      # regret nothing

Code

🦥 slothsort

A lazy, offline folder tidier. Point it at your messy Downloads folder and a local open-weight LLM picks a category and a readable name for every file, then moves them into neat subfolders. It works without internet, needs no API key, costs nothing to run, and your files never leave your machine.

Real output from python slothsort.py demo (llama3.2:3b on a laptop RTX 4050, 16 files in about 39 s):

download (3).txt                ->  Receipts\Invoice 4821.txt
export_20260912.csv             ->  Documents\Export Scores.csv
logs-sept.tar.gz                ->  Archives\System Logs.tar.gz
notes(1).md                     ->  Documents\Meeting Notes.md
order_confirmation.txt          ->  Receipts\Order Confirmed.txt
script_final_FINAL.py           ->  Code\Final Fibonacci Function.py
untitled.txt                    ->  Documents\Grocery List.txt
VSCodeUserSetup-x64-1.94.2.exe  ->  Installers\Visual Studio Code Setup.exe

Images and binaries are named from the filename only, so those names are best guesses.

Built for the Hacktoberfest Open Source AI Challenge, Week 3: Slow and Steady 🦥 (International Sloth Day, Oct 20).

How it works

  • One Python file, standard library…

How I Built It

  • Model: llama3.2:3b, an open-weight model, running locally through Ollama. Any other Ollama model works with --model qwen2.5:3b.
  • Harness: one Python file, standard library only. It calls Ollama's HTTP API on localhost:11434 with format: "json". No SDK, nothing to pip install.
  • The model is a coworker, not an admin, so its output is never trusted:
    • The category must come from a fixed list. Anything else becomes Other.
    • Names are stripped to safe characters, Windows reserved names (CON, NUL…) are rejected, and the original extension is always kept, including .tar.gz.
    • It never overwrites anything. Name collisions get (2).
    • Every move is logged right away to .slothsort-log.json, so even a crash halfway through can be undone.
  • Tests: 11 unit tests run with a fake model, so they don't need Ollama. A live check confirmed that apply followed by undo leaves the demo folder byte-for-byte unchanged (git status clean).
  • Prompt tuning: my first prompt used "Beach Trip 2024" as its example JSON, and suddenly every photo was a "Beach Vacation". Archives and order confirmations were also landing in Installers. I fixed it with a neutral example, a one-line hint per category, and "never invent dates, places or events".

Why Does Open Innovation Matter?

  • My files never leave my laptop. Downloads holds invoices, resumes, bank statements and screenshots of who knows what. Sending previews of all of that to a cloud API every night is exactly what I don't want. With Ollama on localhost, nothing goes over the network. No closed API would have let me do this without second thoughts.
  • It works offline. It's a 3 AM job, and the laptop may not even be online then. A local model doesn't care.
  • $0 forever. No API key, no usage bill and no rate limit. That also meant I could re-run the whole folder over and over while tuning the prompt, at zero cost.
  • Swap the brain with one flag. If a better small model comes out next month, I change one word.

My Agent Session

The Lazy Payoff

Set it up once:

schtasks /create /tn slothsort /sc daily /st 03:00 /tr "python `"$PWD\slothsort.py`" `"$env:USERPROFILE\Downloads`" --apply"

From then on, Downloads sorts itself every night while I sleep. About 2 s per file once the model is loaded, and if it ever gets something wrong, undo puts everything back. Peak sloth. 🦥

Prize Categories

來源:DEV Community · dev.to