LlamaFS是一个自组织文件管理器。它可以基于文件内容和修改时间等属性自动重命名和组织您的文件。它能让你不把时间花在对文件的复制、粘贴、重命名、拷贝、排序等简单操作上。有幸在Github上看到LlamaFS这个repo,感慨万千。
技术简介
LlamaFS以批处理模式和监视模式两种模式运行。在批处理模式下,您可以向LlamaFS发送目录,它将返回建议的文件结构并组织您的文件。在监视模式下,LlamaFS启动一个监视目录的守护进程。它拦截所有文件系统操作,使用您最近的修改记录来重命名文件。
从源码上看,LlamaFS像一个Agent,通过prompt使LLM输出指定格式的json,再根据LLM生成的json进行文件处理操作。给的prompt像这样:
You will be provided with list of source files and a summary of their contents. For each file, propose a new path and filename, using a directory structure that optimally organizes the files using known conventions and best practices.
If the file is already named well or matches a known convention, set the destination path to the same as the source path.
Your response must be a JSON object with the following schema:
```json
{
"files": [
{
"src_path": "original file path",
"dst_path": "new file path under proposed directory structure with proposed file name"
}
]
}
比如移动文件的功能,是这样实现的,下面函数的request参数就是模型返回的json:
@app.post("/commit")
async def commit(request: CommitRequest):
src = os.path.join(request.base_path, request.src_path)
dst = os.path.join(request.base_path, request.dst_path)
if not os.path.exists(src):
raise HTTPException(
status_code=400, detail="Source path does not exist in filesystem"
)
# Ensure the destination directory exists
dst_directory = os.path.dirname(dst)
os.makedirs(dst_directory, exist_ok=True)
try:
# If src is a file and dst is a directory, move the file into dst with the original filename.
if os.path.isfile(src) and os.path.isdir(dst):
shutil.move(src, os.path.join(dst, os.path.basename(src)))
else:
shutil.move(src, dst)
except Exception as e:
raise HTTPException(
status_code=500,
detail=f"An error occurred while moving the resource: {e}"
)
return {"message": "Commit successful"}
感觉LlamaFS像一个“中间件”,只负责发HTTP Request给LLM server获取Respose并采取对应的行动
标签:文件,管理器,src,LlamaFS,dst,LLM,path From: https://www.cnblogs.com/xiangcaoacao/p/18199698