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

SlothSort:一款按需整理檔案的工具,平時會「打盹」

SlothSort: a file tidier that naps until you need it

AI 導讀

SlothSort 使用本機 Gemma 模型讀取檔案名稱、大小及開首數百個文字字元,產生檔案分類和描述性名稱,並列出整理計劃。工具預設為試運行,套用變更會記錄復原資料,亦可撤銷;檔案內容不會離開 localhost,並可離線使用。

正文

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