본문으로 건너뛰기
cccskills
무료GitHub에 공개

python-skills

Shared Python best practices for LlamaFarm. Covers patterns, async, typing, testing, error handling, and security.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(7)

  • SKILL.md4.8 KB
  • async.md9.6 KB
  • error-handling.md13.7 KB
  • patterns.md8.5 KB
  • security.md13.3 KB
  • testing.md12.1 KB
  • typing.md10.2 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Python Skills for LlamaFarm

Shared Python best practices and code review checklists for all Python components in the LlamaFarm monorepo.

Applicable Components

ComponentPathPythonKey Dependencies
Serverserver/3.12+FastAPI, Celery, Pydantic, structlog
RAGrag/3.11+LlamaIndex, ChromaDB, Celery
Universal Runtimeruntimes/universal/3.11+PyTorch, transformers, FastAPI
Configconfig/3.11+Pydantic, JSONSchema
Commoncommon/3.10+HuggingFace Hub

Quick Reference

TopicFileKey Points
Patternspatterns.mdDataclasses, Pydantic, comprehensions, imports
Asyncasync.mdasync/await, asyncio, concurrent execution
Typingtyping.mdType hints, generics, protocols, Pydantic
Testingtesting.mdPytest fixtures, mocking, async tests
Errorserror-handling.mdCustom exceptions, logging, context managers
Securitysecurity.mdPath traversal, injection, secrets, deserialization

Code Style

LlamaFarm uses ruff with shared configuration in ruff.toml:

line-length = 88
target-version = "py311"
select = ["E", "F", "I", "B", "UP", "SIM"]

Key rules:

  • E, F: Core pyflakes and pycodestyle
  • I: Import sorting (isort)
  • B: Bugbear (common pitfalls)
  • UP: Upgrade syntax to modern Python
  • SIM: Simplify code patterns

Architecture Patterns

Settings with pydantic-settings

from pydantic_settings import BaseSettings

class Settings(BaseSettings, env_file=".env"):
    LOG_LEVEL: str = "INFO"
    HOST: str = "0.0.0.0"
    PORT: int = 14345

settings = Settings()  # Singleton at module level

Structured Logging with structlog

from core.logging import FastAPIStructLogger  # Server
from core.logging import RAGStructLogger      # RAG
from core.logging import UniversalRuntimeLogger  # Runtime

logger = FastAPIStructLogger(__name__)
logger.info("Operation completed", extra={"count": 10, "duration_ms": 150})

Abstract Base Classes for Extensibility

from abc import ABC, abstractmethod

class Component(ABC):
    def __init__(self, name: str, config: dict[str, Any] | None = None):
        self.name = name or self.__class__.__name__
        self.config = config or {}

    @abstractmethod
    def process(self, documents: list[Document]) -> ProcessingResult:
        pass

Dataclasses for Internal Data

from dataclasses import dataclass, field

@dataclass
class Document:
    content: str
    metadata: dict[str, Any] = field(default_factory=dict)
    id: str = field(default_factory=lambda: str(uuid.uuid4()))

Pydantic Models for API Boundaries

from pydantic import BaseModel, Field, ConfigDict

class EmbeddingRequest(BaseModel):
    model: str
    input: str | list[str]
    encoding_format: Literal["float", "base64"] | None = "float"

    model_config = ConfigDict(str_strip_whitespace=True)

Directory Structure

Each Python component follows this structure:

component/
├── pyproject.toml     # UV-managed dependencies
├── core/              # Core functionality
│   ├── __init__.py
│   ├── settings.py    # Pydantic Settings
│   └── logging.py     # structlog setup
├── services/          # Business logic (server)
├── models/            # ML models (runtime)
├── tasks/             # Celery tasks (rag)
├── utils/             # Utility functions
└── tests/
    ├── conftest.py    # Shared fixtures
    └── test_*.py

Review Checklist Summary

When reviewing Python code in LlamaFarm:

  1. Patterns (Medium priority)

    • Modern Python syntax (3.10+ type hints)
    • Dataclass vs Pydantic used appropriately
    • No mutable default arguments
  2. Async (High priority)

    • No blocking calls in async functions
    • Proper asyncio.Lock usage
    • Cancellation handled correctly
  3. Typing (Medium priority)

    • Complete return type hints
    • Generic types parameterized
    • Pydantic v2 patterns
  4. Testing (Medium priority)

    • Fixtures properly scoped
    • Async tests use pytest-asyncio
    • Mocks cleaned up
  5. Errors (High priority)

    • Custom exceptions with context
    • Structured logging with extra dict
    • Proper exception chaining
  6. Security (Critical priority)

    • Path traversal prevention
    • Input sanitization
    • Safe deserialization

See individual topic files for detailed checklists with grep patterns.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

CLI best practices for LlamaFarm. Covers Cobra, Bubbletea, Lipgloss patterns for Go CLI development.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

Comprehensive code review for diffs. Analyzes changed code for security vulnerabilities, anti-patterns, and quality issues. Auto-detects domain (frontend/backend) from file paths.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

Commit changes, push to GitHub, and open a PR. Includes quality checks (security, patterns, simplification). Use --quick to skip checks.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

Best practices for the Common utilities package in LlamaFarm. Covers HuggingFace Hub integration, GGUF model management, and shared utilities.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

Configuration module patterns for LlamaFarm. Covers Pydantic v2 models, JSONSchema generation, YAML processing, and validation.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

Designer subsystem patterns for LlamaFarm. Covers React 18, TanStack Query, TailwindCSS, and Radix UI.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

llama-farm/llamafarm8372026년 6월 10일 업데이트

llama-farm의 스킬 모두 보기

이 스킬의 문제 신고