Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 90 additions & 2 deletions pixelle_video/llm_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,70 @@
"base_url": "https://dashscope.aliyuncs.com/compatible-mode/v1",
"model": "qwen-max",
"api_key_url": "https://bailian.console.aliyun.com/?tab=model#/api-key",
# Connection test and model discovery fields
"supports_connection_test": True,
"models_url": "https://dashscope.aliyuncs.com/compatible-mode/v1/models",
"models_response_path": "data",
"model_id_field": "id",
"requires_api_key": True,
},
{
"name": "OpenAI",
"base_url": "https://api.openai.com/v1",
"model": "gpt-4o",
"api_key_url": "https://platform.openai.com/api-keys",
# Connection test and model discovery fields
"supports_connection_test": True,
"models_url": "https://api.openai.com/v1/models",
"models_response_path": "data",
"model_id_field": "id",
"requires_api_key": True,
},
{
"name": "Claude",
"base_url": "https://api.anthropic.com/v1/",
"model": "claude-sonnet-4-5",
"api_key_url": "https://console.anthropic.com/settings/keys",
# Claude uses Anthropic's native API which is not OpenAI-compatible
# Connection test and model discovery are NOT supported
"supports_connection_test": False,
"requires_api_key": True,
},
{
"name": "DeepSeek",
"base_url": "https://api.deepseek.com",
"model": "deepseek-chat",
"api_key_url": "https://platform.deepseek.com/api_keys",
# Connection test and model discovery fields
"supports_connection_test": True,
"models_url": "https://api.deepseek.com/models",
"models_response_path": "data",
"model_id_field": "id",
"requires_api_key": True,
},
{
"name": "Ollama",
"base_url": "http://localhost:11434/v1",
"model": "llama3.2",
"api_key_url": "https://ollama.com/download",
"default_api_key": "ollama", # Required by OpenAI SDK but ignored by Ollama
# Ollama uses native API for model listing (not OpenAI-compatible endpoint)
"supports_connection_test": True,
"models_url": "http://localhost:11434/api/tags",
"models_response_path": "models",
"model_id_field": "name",
"requires_api_key": False, # Ollama doesn't need API key
},
{
"name": "Moonshot",
"base_url": "https://api.moonshot.cn/v1",
"model": "moonshot-v1-8k",
"api_key_url": "https://platform.moonshot.cn/console/api-keys",
# Connection test and model discovery fields
"supports_connection_test": True,
"models_url": "https://api.moonshot.cn/v1/models",
"models_response_path": "data",
"model_id_field": "id",
"requires_api_key": True,
},
]

Expand All @@ -76,7 +109,7 @@ def get_preset(name: str) -> Dict[str, Any]:
def find_preset_by_base_url_and_model(base_url: str, model: str) -> str | None:
"""
Find preset name by base_url and model

Returns:
Preset name if found, None otherwise
"""
Expand All @@ -85,3 +118,58 @@ def find_preset_by_base_url_and_model(base_url: str, model: str) -> str | None:
return preset["name"]
return None


def get_models_config(preset_name: str) -> Dict[str, Any]:
"""
Get model listing endpoint configuration for a preset.

Args:
preset_name: Name of the LLM preset

Returns:
Dict with keys: models_url, models_response_path, model_id_field
Falls back to standard OpenAI format for unknown presets
"""
preset = get_preset(preset_name)
if preset and preset.get("supports_connection_test"):
return {
"models_url": preset.get("models_url"),
"models_response_path": preset.get("models_response_path", "data"),
"model_id_field": preset.get("model_id_field", "id"),
}
# Default OpenAI-compatible format for unknown presets
return {
"models_url": None,
"models_response_path": "data",
"model_id_field": "id",
}


def supports_connection_test(preset_name: str) -> bool:
"""
Check if a preset supports connection testing.

Args:
preset_name: Name of the LLM preset

Returns:
True if connection test is supported, False otherwise
"""
preset = get_preset(preset_name)
return preset.get("supports_connection_test", False) if preset else False


def requires_api_key(preset_name: str) -> bool:
"""
Check if a preset requires an API key.

Args:
preset_name: Name of the LLM preset

Returns:
True if API key is required, False otherwise (e.g., Ollama)
"""
preset = get_preset(preset_name)
# Default to True if not specified (most providers need API key)
return preset.get("requires_api_key", True) if preset else True

Loading