common-skills
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCommon Skills for LlamaFarm
LlamaFarm的Common工具包实践指南
Best practices and code review checklists for the package - shared Python utilities used across all LlamaFarm services.
common/本内容为包的最佳实践与代码审查清单,该包是LlamaFarm所有服务共用的Python工具集。
common/Component Overview
组件概述
| Attribute | Value |
|---|---|
| Path | |
| Package | |
| Python | 3.10+ |
| Key Dependencies | huggingface_hub, hf-transfer |
| 属性 | 值 |
|---|---|
| 路径 | |
| 包名 | |
| Python版本 | 3.10+ |
| 核心依赖 | huggingface_hub, hf-transfer |
Purpose
用途
The package provides shared functionality that needs to be consistent across multiple Python services:
common/- Model file utilities (GGUF selection, quantization parsing)
- HuggingFace Hub integration (listing, downloading)
- Process management (PID files)
common/- 模型文件工具(GGUF选择、量化解析)
- HuggingFace Hub集成(列表展示、下载)
- 进程管理(PID文件)
Shared Python Skills
通用Python实践要点
This skill inherits all patterns from the shared Python skills:
| Topic | File | Relevance |
|---|---|---|
| Patterns | ../python-skills/patterns.md | Dataclasses, type hints, comprehensions |
| Typing | ../python-skills/typing.md | Type annotations, modern syntax |
| Testing | ../python-skills/testing.md | Pytest fixtures, mocking HuggingFace APIs |
| Errors | ../python-skills/error-handling.md | Custom exceptions, logging |
| Security | ../python-skills/security.md | Path validation, safe file handling |
本工具包遵循所有通用Python实践模式:
| 主题 | 文件 | 相关内容 |
|---|---|---|
| 设计模式 | ../python-skills/patterns.md | 数据类、类型提示、推导式 |
| 类型标注 | ../python-skills/typing.md | 类型注解、现代语法 |
| 测试 | ../python-skills/testing.md | Pytest夹具、HuggingFace API模拟 |
| 错误处理 | ../python-skills/error-handling.md | 自定义异常、日志记录 |
| 安全 | ../python-skills/security.md | 路径验证、安全文件处理 |
Framework-Specific Checklists
框架专属审查清单
| Topic | File | Key Points |
|---|---|---|
| HuggingFace | huggingface.md | Hub API, model download, caching, authentication |
| 主题 | 文件 | 核心要点 |
|---|---|---|
| HuggingFace | huggingface.md | Hub API、模型下载、缓存、身份验证 |
Module Structure
模块结构
common/
├── pyproject.toml # UV-managed dependencies
├── llamafarm_common/
│ ├── __init__.py # Public API exports
│ ├── model_utils.py # GGUF file utilities
│ └── pidfile.py # PID file management
└── tests/
└── test_model_utils.py # Unit tests with mockingcommon/
├── pyproject.toml # UV管理的依赖
├── llamafarm_common/
│ ├── __init__.py # 公开API导出
│ ├── model_utils.py # GGUF文件工具
│ └── pidfile.py # PID文件管理
└── tests/
└── test_model_utils.py # 带模拟的单元测试Public API
公开API
Model Utilities
模型工具
python
from llamafarm_common import (
# Parse model:quantization syntax
parse_model_with_quantization,
# Extract quantization from filename
parse_quantization_from_filename,
# Select best GGUF file from list
select_gguf_file,
select_gguf_file_with_logging,
# List GGUF files in HF repo
list_gguf_files,
# Download and get path to GGUF file
get_gguf_file_path,
# Default quantization preference order
GGUF_QUANTIZATION_PREFERENCE_ORDER,
)python
from llamafarm_common import (
# 解析model:quantization语法
parse_model_with_quantization,
# 从文件名提取量化信息
parse_quantization_from_filename,
# 从列表中选择最优GGUF文件
select_gguf_file,
select_gguf_file_with_logging,
# 列出HF仓库中的GGUF文件
list_gguf_files,
# 下载并获取GGUF文件路径
get_gguf_file_path,
# 默认量化偏好顺序
GGUF_QUANTIZATION_PREFERENCE_ORDER,
)PID File Management
PID文件管理
python
from llamafarm_common.pidfile import write_pid, get_pid_filepython
from llamafarm_common.pidfile import write_pid, get_pid_fileReview Checklist Summary
审查清单摘要
When reviewing code in :
common/-
HuggingFace Integration (High priority)
- Proper error handling for network failures
- Authentication token passed correctly
- High-speed transfer enabled appropriately
-
Model Selection (Medium priority)
- Quantization preference order maintained
- Case-insensitive matching
- Graceful fallback when preferred not available
-
Testing (High priority)
- HuggingFace API calls mocked
- Network isolation in tests
- Edge cases covered (empty lists, missing files)
-
Security (Medium priority)
- No token exposure in logs
- Safe file path handling
- Environment variable protection
See huggingface.md for detailed HuggingFace-specific checklists.
审查中的代码时,需关注以下几点:
common/-
HuggingFace集成(高优先级)
- 为网络故障设置适当的错误处理
- 正确传递身份验证令牌
- 合理启用高速传输
-
模型选择(中优先级)
- 维持量化偏好顺序
- 支持大小写不敏感匹配
- 当偏好模型不可用时优雅降级
-
测试(高优先级)
- 模拟HuggingFace API调用
- 测试中隔离网络依赖
- 覆盖边缘场景(空列表、文件缺失)
-
安全(中优先级)
- 日志中不暴露令牌信息
- 安全处理文件路径
- 保护环境变量
详细的HuggingFace专属审查清单请参考huggingface.md。