Skip to content

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

feat: add Grok provider support

SmaRtToU65fd333a8cf8
diff --git a/app/services/llm.py b/app/services/llm.py
index 8906cda6..1699b991 100644
--- a/app/services/llm.py
+++ b/app/services/llm.py
@@ -128,6 +128,12 @@ def _generate_response(prompt: str) -> str:
f"gemini model '{model_name}' is deprecated, fallback to '{_DEFAULT_GEMINI_MODEL}'"
)
model_name = _DEFAULT_GEMINI_MODEL
+ elif llm_provider == "grok":
+ api_key = config.app.get("grok_api_key")
+ model_name = config.app.get("grok_model_name")
+ base_url = config.app.get("grok_base_url", "")
+ if not base_url:
+ base_url = "https://api.x.ai/v1"
elif llm_provider == "qwen":
api_key = config.app.get("qwen_api_key")
model_name = config.app.get("qwen_model_name")
diff --git a/config.example.toml b/config.example.toml
index 60ca7873..d47853b7 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -108,6 +108,11 @@ azure_api_version = "2024-02-15-preview"
gemini_api_key = ""
gemini_model_name = "gemini-2.5-flash"
+########## Grok API Key
+grok_api_key = ""
+grok_model_name = "grok-4.3"
+grok_base_url = "https://api.x.ai/v1"
+
########## Qwen API Key
# Visit https://dashscope.console.aliyun.com/apiKey to get your API key
# Visit below links to get more details
diff --git a/test/services/test_llm.py b/test/services/test_llm.py
index 0e1837ca..5662456c 100644
--- a/test/services/test_llm.py
+++ b/test/services/test_llm.py
@@ -105,6 +105,19 @@ class TestLiteLLMProvider(unittest.TestCase):
self.assertIn("api_key is not set", result)
self.assertNotIn("litellm", result.lower())
+ def test_grok_provider_still_uses_existing_path(self):
+ config.app["llm_provider"] = "grok"
+ config.app["grok_api_key"] = ""
+ config.app["grok_base_url"] = "https://api.x.ai/v1"
+ config.app["grok_model_name"] = "grok-4.3"
+
+ result = llm._generate_response("test")
+
+ self.assertIn("Error:", result)
+ self.assertIn("api_key is not set", result)
+ self.assertNotIn("litellm", result.lower())
+
+
def test_azure_provider_uses_azure_client_directly(self):
"""
Azure OpenAI 的鉴权、endpoint 和 api-version 都由 AzureOpenAI 客户端处理。
diff --git a/webui/Main.py b/webui/Main.py
index 2128aaed..14a241b6 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -245,6 +245,7 @@ if not config.app.get("hide_config", False):
"DeepSeek",
"ModelScope",
"Gemini",
+ "Grok",
"Ollama",
"G4f",
"OneAPI",
@@ -374,6 +375,20 @@ if not config.app.get("hide_config", False):
- **Model Name**: 比如 gemini-1.0-pro
"""
+ if llm_provider == "grok":
+ if not llm_model_name:
+ llm_model_name = "grok-4.3"
+ if not llm_base_url:
+ llm_base_url = "https://api.x.ai/v1"
+
+ with llm_helper:
+ tips = """
+ ##### Grok 配置说明
+ - **API Key**: 填写您的 GrokAPI 密钥
+ - **Base Url**: 填写 GrokAPI 的基础 URL
+ - **Model Name**: 比如 grok-4.3
+ """
+
if llm_provider == "deepseek":
if not llm_model_name:
llm_model_name = "deepseek-chat"