← Материалы разборы Yersham
разбор · статьятема-фронтир · H 1.58
3.0
из 10
смотреть не обязательно — забрать выжимку и пункты
оценка машинная и частично зависит от длины ролика — спорите, открывайте оригинал

Стандарты Python для promptfoo: ruff, type hints, unittest

Python Guidelines

Гайд по Python-коду для провайдеров и ассертов promptfoo: ruff, type hints, unittest, минимум зависимостей.

Гайд по Python-коду для провайдеров и ассертов promptfoo: ruff, type hints, unittest, минимум зависимостей.

что из этого моё

Гайд задаёт стандарты кода для Python-компонентов в promptfoo. Если оператор пишет кастомные провайдеры, промпты или ассерты на Python, эти правила помогут поддерживать качество и совместимость. Конкретно: использовать ruff для автоматической проверки, type hints для надёжности, unittest для тестов. Это ускорит разработку и уменьшит ошибки в оркестрации.

Что забрать
отметь, что берёшь в работу → или отбрось как не своёмоё →
настроить ruff с правилами Google Python Style Guide в проекте
переписать тесты на unittest вместо сторонних фреймворков
добавить type hints во все функции Python-компонентов
расшифровка ролика ↓

Title:

URL Source: https://raw.githubusercontent.com/promptfoo/promptfoo/main/docs/agents/python.md

Markdown Content: # Python Guidelines

For Python providers, prompts, assertions, and scripts.

## Requirements

- Python 3.8 or later - Follow [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html) - Use type hints for readability and error catching

## Linting & Formatting

Use `ruff` for both:

```bash ruff check --fix # Lint with auto-fix ruff check --select I --fix # Sort imports ruff format # Format code ```

## Testing

Use the built-in `unittest` module for new Python tests.

## Best Practices

- Keep dependencies minimal - avoid unnecessary external packages - When adding examples, update relevant `requirements.txt` files - Follow promptfoo API patterns for custom providers/prompts/assertions - Write unit tests for new Python functions

## Provider Pattern

```python def call_api(prompt: str, options: dict, context: dict) -> dict: """ Args: prompt: The prompt string options: Provider configuration context: Variables from the test case

Returns: dict with 'output' key (and optionally 'error') """ # Implementation return {"output": response_text} ```

## Assertion Pattern

```python def get_assert(output: str, context: dict) -> dict: """ Args: output: The provider's output context: Test context including vars

Returns: dict with 'pass' (bool) and optionally 'reason' """ return {"pass": True, "reason": "Validation passed"} ```

дальше в дело
Собрать это в маршрут
все маршруты →
не хочешь разбираться сам
Сделаю это под задачу
форматы и цены →
ещё разборы