__init__.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """DeepInfra video generation backend.
  2. DeepInfra serves video over the OpenAI-compatible ``/v1/openai/videos`` endpoint (``create`` → poll →
  3. ``download_content``), so all SDK plumbing lives in :class:`agent.video_gen_provider.OpenAICompatibleVideoGenProvider`.
  4. This plugin only declares identity, credentials, and live model discovery — no hardcoded model ids, so retired
  5. models drop out without a patch. Mirrors ``plugins/image_gen/deepinfra``.
  6. """
  7. from __future__ import annotations
  8. import logging
  9. from typing import Any, Dict, List
  10. from agent.video_gen_provider import OpenAICompatibleVideoGenProvider
  11. logger = logging.getLogger(__name__)
  12. class DeepInfraVideoGenProvider(OpenAICompatibleVideoGenProvider):
  13. """Text-to-video and image-to-video via DeepInfra's OpenAI-compatible API."""
  14. name = "deepinfra"
  15. display_name = "DeepInfra"
  16. _env_key = "DEEPINFRA_API_KEY"
  17. _default_base_url = "https://api.deepinfra.com/v1/openai"
  18. def list_models(self) -> list[dict[str, Any]]:
  19. """``video-gen``-tagged models from the live catalog; empty when unreachable (nothing beats a retired model)."""
  20. try:
  21. from hermes_cli.models import _fetch_deepinfra_models_by_tag
  22. except Exception as exc:
  23. logger.debug("Cannot import _fetch_deepinfra_models_by_tag: %s", exc)
  24. return []
  25. return [{"id": item["id"], "display": item["id"].split("/")[-1],
  26. "strengths": ((item.get("metadata", {}) or {}).get("description") or "")[:80]}
  27. for item in (_fetch_deepinfra_models_by_tag("video-gen") or []) if item.get("id")]
  28. def capabilities(self) -> dict[str, Any]:
  29. return {"modalities": ["text", "image"], "aspect_ratios": ["16:9", "9:16", "1:1"], "resolutions": ["480p", "720p", "1080p"],
  30. "max_duration": 10, "min_duration": 1, "supports_audio": False, "supports_negative_prompt": True,
  31. "supports_seed": True, "supports_upscale": False, "max_reference_images": 0}
  32. def get_setup_schema(self) -> dict[str, Any]:
  33. return {"name": "DeepInfra", "badge": "paid",
  34. "tag": "Wan, p-video, … — live catalog from api.deepinfra.com; text-to-video & image-to-video",
  35. "env_vars": [{"key": "DEEPINFRA_API_KEY", "prompt": "DeepInfra API key", "url": "https://deepinfra.com/dash/api_keys"}]}
  36. def register(ctx) -> None:
  37. """Plugin entry point — wire ``DeepInfraVideoGenProvider`` into the registry."""
  38. ctx.register_video_gen_provider(DeepInfraVideoGenProvider())