Skip to content

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

feat: add Groq LLM provider

Rafa Gómezed1dc678d5c0
diff --git a/app/services/llm.py b/app/services/llm.py
index a841116f..b2b654f6 100644
--- a/app/services/llm.py
+++ b/app/services/llm.py
@@ -209,6 +209,12 @@ def _generate_response(prompt: str) -> str:
base_url = config.app.get("grok_base_url", "")
if not base_url:
base_url = "https://api.x.ai/v1"
+ elif llm_provider == "groq":
+ api_key = config.app.get("groq_api_key")
+ model_name = config.app.get("groq_model_name")
+ base_url = config.app.get("groq_base_url", "")
+ if not base_url:
+ base_url = "https://api.groq.com/openai/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 5d0d2faf..63b96566 100644
--- a/config.example.toml
+++ b/config.example.toml
@@ -122,6 +122,14 @@ grok_api_key = ""
grok_model_name = "grok-4.3"
grok_base_url = "https://api.x.ai/v1"
+########## Groq API Key
+# Visit https://console.groq.com/keys to get your api keys
+# API documentation: https://console.groq.com/docs/api-reference
+# Available models: https://console.groq.com/docs/api-reference#models-list
+groq_api_key = ""
+groq_model_name = "llama-3.3-70b-versatile"
+groq_base_url = "https://api.groq.com/openai/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 1a1eb0c3..3795eceb 100644
--- a/test/services/test_llm.py
+++ b/test/services/test_llm.py
@@ -343,6 +343,49 @@ class TestLiteLLMProvider(unittest.TestCase):
self.assertIn("api_key is not set", result)
self.assertNotIn("litellm", result.lower())
+ def test_groq_provider_requires_api_key(self):
+ config.app["llm_provider"] = "groq"
+ config.app["groq_api_key"] = ""
+ config.app["groq_base_url"] = "https://api.groq.com/openai/v1"
+ config.app["groq_model_name"] = "llama-3.3-70b-versatile"
+
+ result = llm._generate_response("test")
+
+ self.assertIn("Error:", result)
+ self.assertIn("api_key is not set", result)
+ self.assertNotIn("litellm", result.lower())
+
+ def test_groq_provider_uses_default_base_url(self):
+ config.app["llm_provider"] = "groq"
+ config.app["groq_api_key"] = "groq-test-key"
+ config.app["groq_base_url"] = ""
+ config.app["groq_model_name"] = "llama-3.3-70b-versatile"
+
+ fake_response = types.SimpleNamespace(
+ choices=[
+ types.SimpleNamespace(
+ message=types.SimpleNamespace(content="hello\ngroq")
+ )
+ ]
+ )
+ fake_client = types.SimpleNamespace(
+ chat=types.SimpleNamespace(
+ completions=types.SimpleNamespace(create=lambda **kwargs: fake_response)
+ )
+ )
+
+ with (
+ patch.object(llm, "OpenAI", return_value=fake_client) as openai_client,
+ patch.object(llm, "ChatCompletion", types.SimpleNamespace),
+ ):
+ result = llm._generate_response("Say hello")
+
+ openai_client.assert_called_once_with(
+ api_key="groq-test-key",
+ base_url="https://api.groq.com/openai/v1",
+ )
+ self.assertEqual(result, "hellogroq")
+
def _use_ollama_provider(self, base_url=""):
config.app["llm_provider"] = "ollama"
config.app["ollama_api_key"] = ""
diff --git a/webui/Main.py b/webui/Main.py
index 96304377..76af5fbd 100644
--- a/webui/Main.py
+++ b/webui/Main.py
@@ -3,6 +3,7 @@ import sys
import webbrowser
from uuid import UUID, uuid4
+import requests
import streamlit as st
from loguru import logger
@@ -217,6 +218,35 @@ def tr(key):
loc = locales.get(st.session_state["ui_language"], {})
return loc.get("Translation", {}).get(key, key)
[email protected]_data(ttl=300, show_spinner=False)
+def get_groq_model_ids(api_key: str, base_url: str) -> list[str]:
+ if not api_key:
+ return []
+
+ normalized_base_url = (base_url or "https://api.groq.com/openai/v1").strip().rstrip("/")
+ models_url = f"{normalized_base_url}/models"
+
+ try:
+ response = requests.get(
+ models_url,
+ headers={"Authorization": f"Bearer {api_key}"},
+ timeout=10,
+ )
+ response.raise_for_status()
+ payload = response.json()
+ data = payload.get("data", [])
+
+ model_ids = []
+ for item in data:
+ if isinstance(item, dict):
+ model_id = item.get("id")
+ if isinstance(model_id, str) and model_id.strip():
+ model_ids.append(model_id.strip())
+
+ return sorted(set(model_ids))
+ except Exception as e:
+ logger.warning(f"failed to fetch groq models: {e}")
+ return []
# 创建基础设置折叠框
if not config.app.get("hide_config", False):
@@ -261,6 +291,7 @@ if not config.app.get("hide_config", False):
("ModelScope", "modelscope"),
("Gemini", "gemini"),
("Grok", "grok"),
+ ("Groq", "groq"),
("Ollama", "ollama"),
("G4f", "g4f"),
("OneAPI", "oneapi"),
@@ -432,6 +463,20 @@ if not config.app.get("hide_config", False):
- **Model Name**: 比如 grok-4.3
"""
+ if llm_provider == "groq":
+ if not llm_model_name:
+ llm_model_name = "llama-3.3-70b-versatile"
+ if not llm_base_url:
+ llm_base_url = "https://api.groq.com/openai/v1"
+
+ with llm_helper:
+ tips = """
+ ##### Groq 配置说明
+ - **API Key**: [点击到官网申请](https://console.groq.com/keys)
+ - **Base Url**: 固定为 https://api.groq.com/openai/v1
+ - **Model Name**: 比如 llama-3.3-70b-versatile
+ """
+
if llm_provider == "deepseek":
if not llm_model_name:
llm_model_name = "deepseek-chat"
@@ -518,11 +563,45 @@ if not config.app.get("hide_config", False):
st_llm_base_url = st.text_input(tr("Base Url"), value=llm_base_url)
st_llm_model_name = ""
if llm_provider != "ernie":
- st_llm_model_name = st.text_input(
- tr("Model Name"),
- value=llm_model_name,
- key=f"{llm_provider}_model_name_input",
- )
+ if llm_provider == "groq":
+ effective_api_key = st_llm_api_key or llm_api_key
+ effective_base_url = st_llm_base_url or llm_base_url
+ groq_models = get_groq_model_ids(
+ api_key=effective_api_key,
+ base_url=effective_base_url,
+ )
+
+ if groq_models:
+ selected_index = 0
+ if llm_model_name in groq_models:
+ selected_index = groq_models.index(llm_model_name)
+
+ st_llm_model_name = st.selectbox(
+ tr("Model Name"),
+ options=groq_models,
+ index=selected_index,
+ key="groq_model_name_select",
+ )
+ else:
+ st_llm_model_name = st.text_input(
+ tr("Model Name"),
+ value=llm_model_name,
+ key="groq_model_name_input",
+ )
+ if effective_api_key:
+ st.caption(
+ "Unable to load Groq model list right now. You can still enter a model name manually."
+ )
+ else:
+ st.caption(
+ "Add a Groq API key to load available models automatically."
+ )
+ else:
+ st_llm_model_name = st.text_input(
+ tr("Model Name"),
+ value=llm_model_name,
+ key=f"{llm_provider}_model_name_input",
+ )
if st_llm_model_name:
config.app[f"{llm_provider}_model_name"] = st_llm_model_name
else: