Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

feat(material): support optional OFox upstream vendor pinning

celeste1900c6c7af6fb11c
diff --git a/README-en.md b/README-en.md
index 31c56267..29f9ff3d 100644
--- a/README-en.md
+++ b/README-en.md
@@ -496,7 +496,7 @@ ofox_text_to_video_model = "bytedance/seedance-2.0-fast"
ofox_base_url = "https://api.ofox.ai/v1"
```
-When the dedicated config value is empty, the `OFOX_API_KEY` environment variable is used. Select **OFox AI Video** as the video source and explicitly confirm paid generation before starting. CLI users must add `--confirm-ofox-charge`. The model can be any text-to-video model from the OFox catalog (`GET /v1/models`), e.g. `alibaba/wan-2.7`; each model has its own supported duration range and resolutions, and out-of-range values are rejected by the API with a clear error before any task is created.
+When the dedicated config value is empty, the `OFOX_API_KEY` environment variable is used. Select **OFox AI Video** as the video source and explicitly confirm paid generation before starting. CLI users must add `--confirm-ofox-charge`. For predictable routing, `ofox_provider` pins the upstream vendor (for example the Seedance series is served by both `"volcengine"` and `"byteplus"`, each with its own content policies and regional availability; when unset, OFox load-balances across vendors). The model can be any text-to-video model from the OFox catalog (`GET /v1/models`), e.g. `alibaba/wan-2.7`; each model has its own supported duration range and resolutions, and out-of-range values are rejected by the API with a clear error before any task is created.
The first version supports text-to-video only. Each clip creates one asynchronous paid task; the program only polls the same task id, stops submitting new tasks whenever a paid task state is unknown, and generates just enough footage to cover the voiceover duration.
diff --git a/README-ja.md b/README-ja.md
index 5a0fd873..3e4b0f70 100644
--- a/README-ja.md
+++ b/README-ja.md
@@ -474,7 +474,7 @@ ofox_text_to_video_model = "bytedance/seedance-2.0-fast"
ofox_base_url = "https://api.ofox.ai/v1"
```
-専用設定が空の場合は、`OFOX_API_KEY` 環境変数を使用します。動画ソースで **OFox AI Video** を選び、生成前に有料タスクを明示的に確認してください。CLI では `--confirm-ofox-charge` も必要です。モデルは OFox カタログ(`GET /v1/models`)の任意のテキスト動画モデル(例:`alibaba/wan-2.7`)に変更できます。モデルごとに対応する動画長と解像度が異なり、範囲外の値はタスク作成前に API が明確なエラーで拒否します。
+専用設定が空の場合は、`OFOX_API_KEY` 環境変数を使用します。動画ソースで **OFox AI Video** を選び、生成前に有料タスクを明示的に確認してください。CLI では `--confirm-ofox-charge` も必要です。ルーティングを固定したい場合は `ofox_provider` で上流ベンダーを指定できます(例:Seedance シリーズは `"volcengine"` と `"byteplus"` から選択可能で、ベンダーごとにコンテンツポリシーと提供地域が異なります。未指定の場合はゲートウェイが重みに基づいて分散します)。モデルは OFox カタログ(`GET /v1/models`)の任意のテキスト動画モデル(例:`alibaba/wan-2.7`)に変更できます。モデルごとに対応する動画長と解像度が異なり、範囲外の値はタスク作成前に API が明確なエラーで拒否します。
初版はテキスト動画のみ対応です。各クリップは非同期の有料タスクを 1 つ作成します。プログラムは同じタスク ID のみをポーリングし、状態が不明な場合は新規タスクの送信を停止し、ナレーションの長さを満たす分だけ生成します。
diff --git a/README.md b/README.md
index 91097bd7..eb66017f 100644
--- a/README.md
+++ b/README.md
@@ -491,7 +491,7 @@ ofox_text_to_video_model = "bytedance/seedance-2.0-fast"
ofox_base_url = "https://api.ofox.ai/v1"
```
-专用配置为空时,会使用 `OFOX_API_KEY` 环境变量。在视频源中选择"OFox AI 视频",并在生成前明确确认付费任务;CLI 还需要传入 `--confirm-ofox-charge`。模型可换成 OFox 目录(`GET /v1/models`)中任意文生视频模型(如 `alibaba/wan-2.7`),不同模型支持的时长区间与分辨率不同,超出范围会在创建任务前被 API 明确拒绝。
+专用配置为空时,会使用 `OFOX_API_KEY` 环境变量。在视频源中选择"OFox AI 视频",并在生成前明确确认付费任务;CLI 还需要传入 `--confirm-ofox-charge`。需要可预期的路由时,可用 `ofox_provider` 钉定上游厂商(如 Seedance 系列可选 `"volcengine"` 或 `"byteplus"`,各厂商内容政策与区域可用性不同;不填则由网关按权重分发)。模型可换成 OFox 目录(`GET /v1/models`)中任意文生视频模型(如 `alibaba/wan-2.7`),不同模型支持的时长区间与分辨率不同,超出范围会在创建任务前被 API 明确拒绝。
首版仅支持文生视频。每个片段都会创建一个异步付费任务;程序只轮询同一个任务 ID,状态不明时停止继续下单,并仅生成足够覆盖配音时长的素材。
diff --git a/app/services/ofox.py b/app/services/ofox.py
index 3b0a2397..d18cf5c3 100644
--- a/app/services/ofox.py
+++ b/app/services/ofox.py
@@ -98,6 +98,19 @@ def _resolution() -> str:
return value or DEFAULT_RESOLUTION
+def _provider_type() -> str:
+ """
+ 读取可选的上游厂商钉定(provider routing)。
+
+ OFox 的部分模型由多个上游厂商供货(如 Seedance 系列的 volcengine 与
+ byteplus),不指定时由网关按权重分发。各厂商有各自的内容政策与区域
+ 可用性,钉定厂商可以让路由变得可预期。非法厂商名会被 API 以专属的
+ 400 ``invalid_provider_type`` 拒绝且不创建付费任务,因此本地不维护
+ 厂商白名单。
+ """
+ return str(config.app.get("ofox_provider", "") or "").strip()
+
+
def _config_bool(key: str, default: bool) -> bool:
value = config.app.get(key, default)
if isinstance(value, str):
@@ -221,6 +234,9 @@ def generate_videos(
"resolution": _resolution(),
"aspect_ratio": aspect.value,
}
+ provider_type = _provider_type()
+ if provider_type:
+ payload["provider"] = {"type": provider_type}
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
diff --git a/config.example.toml b/config.example.toml
index de0a5bb8..34891f3e 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -140,6 +140,13 @@ ofox_resolution = "720p"
# submission (extra footage is trimmed by the editing pipeline).
ofox_min_duration = 4
ofox_max_duration = 15
+# Optional upstream vendor pinning. Some models are served by multiple
+# upstream vendors (for example the Seedance series is available from both
+# "volcengine" and "byteplus"); when unset, OFox load-balances across the
+# available vendors. Vendors apply their own content policies and regional
+# availability, so pinning one makes routing predictable. Unknown vendor
+# names are rejected by the API before any task is created.
+# ofox_provider = "byteplus"
ofox_poll_interval = 5
ofox_run_timeout = 1800
diff --git a/test/services/test_ofox.py b/test/services/test_ofox.py
index 57ab65cf..db5f1418 100644
--- a/test/services/test_ofox.py
+++ b/test/services/test_ofox.py
@@ -148,6 +148,45 @@ class TestOFoxService(unittest.TestCase):
config.app["ofox_resolution"] = " 480p "
self.assertEqual(ofox._resolution(), "480p")
+ def test_provider_pinning_is_optional_and_passed_through(self):
+ # 未配置时不携带 provider 字段,让网关按权重自动分发。
+ submit = self._response({"id": "vid-route", "status": "queued"}, 202)
+ completed = self._response(
+ {
+ "id": "vid-route",
+ "status": "completed",
+ "unsigned_urls": ["https://cdn.example.com/route.mp4"],
+ }
+ )
+ with (
+ patch.object(ofox.requests, "post", return_value=submit) as post,
+ patch.object(ofox.requests, "get", return_value=completed),
+ ):
+ ofox.generate_videos("sunrise", 5)
+ self.assertNotIn("provider", post.call_args.kwargs["json"])
+
+ for blank in ("", " ", None):
+ with self.subTest(blank=blank):
+ config.app["ofox_provider"] = blank
+ with (
+ patch.object(ofox.requests, "post", return_value=submit) as post,
+ patch.object(ofox.requests, "get", return_value=completed),
+ ):
+ ofox.generate_videos("sunrise", 5)
+ self.assertNotIn("provider", post.call_args.kwargs["json"])
+
+ # 配置后钉定上游厂商,形如 {"type": "byteplus"};非法厂商名由服务端
+ # 以 400 invalid_provider_type 拒绝(不创建付费任务),走常规 4xx 路径。
+ config.app["ofox_provider"] = " byteplus "
+ with (
+ patch.object(ofox.requests, "post", return_value=submit) as post,
+ patch.object(ofox.requests, "get", return_value=completed),
+ ):
+ ofox.generate_videos("sunrise", 5)
+ self.assertEqual(
+ post.call_args.kwargs["json"]["provider"], {"type": "byteplus"}
+ )
+
def test_server_rejected_resolution_raises_clear_error_without_polling(self):
config.app["ofox_resolution"] = "1080p"
rejected = self._response(