跳到正文
DEV Community· Preeti Kumari·· 3 小時前AI 評分50

SlothSort 使用本地 Gemma 模型分類及整理檔案

SlothSort: a file tidier that naps until you need it

AI 導讀

Preeti Kumari 開發 SlothSort,工具會根據檔名、大小和文字開頭,請本地 Gemma 模型為檔案分類並建議描述性檔名及存放位置。工具預設只顯示整理計劃,可用 `--apply` 執行並以 `--undo` 還原;模型出錯時會改用副檔名規則,亦可透過 `--no-llm` 強制停用模型。

正文

Preeti Kumari

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

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

What I Built

My Downloads folder is a landfill: IMG_4471.png, final_v2_REAL.pdf, New Text Document (3).txt. I never tidy it because sorting means reading every file.

SlothSort does the reading. It looks at each file (name, size, first few hundred characters of text) and asks a local Gemma model for a category and a descriptive name. Then it prints the plan:

IMG_4471.png          ->  Screenshots\login-page-bug.png
final_v2_REAL.pdf     ->  Documents\q3-lease-agreement.pdf
New Text Document.txt ->  Notes\grocery-list-oct.txt

Review, add --apply, done. Changed your mind? --undo.

The lazy payoff: one command replaces an hour of "what is this file?"

Demo / Code

Repo: https://github.com/preetik92002-tech/hacktoberfest. A single Python file, stdlib only.

How I Built It

  • Model: gemma3:4b served by Ollama on localhost:11434, called with format: json and temperature: 0.
  • No SDK: one urllib request. Swap models with --model.
  • Don't trust the model: the category must be on a whitelist, names are slugified (so ../../passwd becomes passwd), extensions are preserved, nothing is overwritten.
  • Graceful degradation: if the model errors, that file falls back to extension rules. --no-llm forces this.
  • Reversible: every apply writes an undo log. Dry-run is the default.
  • Tested: unit tests inject a fake model, including a hostile one, and verify the apply/undo round trip.

Why Open Innovation Matters Here

A file tidier is the worst thing to hand to a cloud API. Filenames and contents (leases, invoices, medical PDFs) are exactly what you don't want on a server you don't control. With an open-weight model:

  • Privacy: contents never leave localhost.
  • Offline: it works on a plane.
  • Free forever: sorting 10,000 files costs electricity, not tokens.
  • Swappable: a 4B model is enough here; a bigger one is a flag away.

來源:DEV Community · dev.to