Update models.py
Browse files
models.py
CHANGED
|
@@ -1,17 +1,27 @@
|
|
| 1 |
# models.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
from dataclasses import dataclass
|
| 3 |
from typing import List, Optional
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
class ModelInfo:
|
| 7 |
"""
|
| 8 |
-
|
| 9 |
|
| 10 |
-
Attributes
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
"""
|
| 16 |
name: str
|
| 17 |
id: str
|
|
@@ -19,86 +29,102 @@ class ModelInfo:
|
|
| 19 |
default_provider: str = "auto"
|
| 20 |
|
| 21 |
|
| 22 |
-
#
|
|
|
|
|
|
|
| 23 |
AVAILABLE_MODELS: List[ModelInfo] = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
ModelInfo(
|
| 25 |
-
name="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
id="moonshotai/Kimi-K2-Instruct",
|
| 27 |
-
description="Moonshot
|
| 28 |
-
default_provider="groq"
|
| 29 |
),
|
|
|
|
| 30 |
ModelInfo(
|
| 31 |
-
name="DeepSeek
|
| 32 |
id="deepseek-ai/DeepSeek-V3-0324",
|
| 33 |
-
description="DeepSeek
|
| 34 |
),
|
| 35 |
ModelInfo(
|
| 36 |
-
name="DeepSeek
|
| 37 |
id="deepseek-ai/DeepSeek-R1-0528",
|
| 38 |
-
description="DeepSeek
|
| 39 |
),
|
|
|
|
| 40 |
ModelInfo(
|
| 41 |
-
name="ERNIE
|
| 42 |
id="baidu/ERNIE-4.5-VL-424B-A47B-Base-PT",
|
| 43 |
-
description="ERNIE
|
| 44 |
),
|
| 45 |
ModelInfo(
|
| 46 |
-
name="
|
| 47 |
-
id="
|
| 48 |
-
description="
|
| 49 |
-
),
|
| 50 |
-
ModelInfo(
|
| 51 |
-
name="Qwen3-235B-A22B",
|
| 52 |
-
id="Qwen/Qwen3-235B-A22B",
|
| 53 |
-
description="Qwen3-235B-A22B model for code generation and general tasks",
|
| 54 |
),
|
|
|
|
| 55 |
ModelInfo(
|
| 56 |
-
name="SmolLM3
|
| 57 |
id="HuggingFaceTB/SmolLM3-3B",
|
| 58 |
-
description="SmolLM3
|
| 59 |
),
|
| 60 |
ModelInfo(
|
| 61 |
-
name="
|
| 62 |
-
id="
|
| 63 |
-
description="
|
| 64 |
),
|
|
|
|
| 65 |
ModelInfo(
|
| 66 |
-
name="OpenAI
|
| 67 |
id="openai/gpt-4",
|
| 68 |
-
description="OpenAI
|
| 69 |
-
default_provider="openai"
|
| 70 |
),
|
| 71 |
ModelInfo(
|
| 72 |
-
name="Gemini
|
| 73 |
id="gemini/pro",
|
| 74 |
-
description="Google
|
| 75 |
-
default_provider="gemini"
|
| 76 |
),
|
| 77 |
ModelInfo(
|
| 78 |
-
name="Fireworks
|
| 79 |
id="fireworks-ai/fireworks-v1",
|
| 80 |
-
description="Fireworks
|
| 81 |
-
default_provider="fireworks"
|
| 82 |
-
),
|
| 83 |
-
ModelInfo(
|
| 84 |
-
name="Qwen3-32B",
|
| 85 |
-
id="Qwen/Qwen3-32B",
|
| 86 |
-
description="Qwen3-32B model for high-capacity code and text generation",
|
| 87 |
),
|
| 88 |
]
|
| 89 |
|
| 90 |
|
|
|
|
|
|
|
|
|
|
| 91 |
def find_model(identifier: str) -> Optional[ModelInfo]:
|
| 92 |
"""
|
| 93 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
The matching ModelInfo or None if not found.
|
| 99 |
"""
|
| 100 |
key = identifier.lower()
|
| 101 |
for m in AVAILABLE_MODELS:
|
| 102 |
if m.id == identifier or m.name.lower() == key:
|
| 103 |
return m
|
| 104 |
-
return None
|
|
|
|
| 1 |
# models.py
|
| 2 |
+
# ------------------------------------------------------------------
|
| 3 |
+
# Central registry of all AI models AnyCoder can route to.
|
| 4 |
+
# ------------------------------------------------------------------
|
| 5 |
+
from __future__ import annotations
|
| 6 |
+
|
| 7 |
from dataclasses import dataclass
|
| 8 |
from typing import List, Optional
|
| 9 |
|
| 10 |
+
|
| 11 |
+
@dataclass(slots=True, frozen=True)
|
| 12 |
class ModelInfo:
|
| 13 |
"""
|
| 14 |
+
Metadata for a single model entry.
|
| 15 |
|
| 16 |
+
Attributes
|
| 17 |
+
----------
|
| 18 |
+
name : Human‑readable label shown in the UI.
|
| 19 |
+
id : Fully‑qualified model path, e.g. "openai/gpt‑4".
|
| 20 |
+
description : Short capability blurb.
|
| 21 |
+
default_provider: Which provider to send inference requests to if the
|
| 22 |
+
caller does **not** override it. Supported values:
|
| 23 |
+
"auto" | "groq" | "openai" | "gemini" | "fireworks".
|
| 24 |
+
The special value "auto" lets HF Inference decide.
|
| 25 |
"""
|
| 26 |
name: str
|
| 27 |
id: str
|
|
|
|
| 29 |
default_provider: str = "auto"
|
| 30 |
|
| 31 |
|
| 32 |
+
# ------------------------------------------------------------------
|
| 33 |
+
# Editable list of models exposed to both back‑end & front‑end
|
| 34 |
+
# ------------------------------------------------------------------
|
| 35 |
AVAILABLE_MODELS: List[ModelInfo] = [
|
| 36 |
+
# High‑capacity HF models
|
| 37 |
+
ModelInfo(
|
| 38 |
+
name="Qwen/Qwen3‑32B",
|
| 39 |
+
id="Qwen/Qwen3-32B",
|
| 40 |
+
description="Qwen3‑32B model for high‑capacity code and text generation",
|
| 41 |
+
),
|
| 42 |
ModelInfo(
|
| 43 |
+
name="Qwen3‑235B‑A22B",
|
| 44 |
+
id="Qwen/Qwen3-235B-A22B",
|
| 45 |
+
description="Qwen3‑235B‑A22B model for code generation and general tasks",
|
| 46 |
+
),
|
| 47 |
+
# Moonshot (Groq hardware by default)
|
| 48 |
+
ModelInfo(
|
| 49 |
+
name="Moonshot Kimi‑K2",
|
| 50 |
id="moonshotai/Kimi-K2-Instruct",
|
| 51 |
+
description="Moonshot AI Kimi‑K2‑Instruct (code, chat)",
|
| 52 |
+
default_provider="groq",
|
| 53 |
),
|
| 54 |
+
# DeepSeek
|
| 55 |
ModelInfo(
|
| 56 |
+
name="DeepSeek V3",
|
| 57 |
id="deepseek-ai/DeepSeek-V3-0324",
|
| 58 |
+
description="DeepSeek V3 model for code generation",
|
| 59 |
),
|
| 60 |
ModelInfo(
|
| 61 |
+
name="DeepSeek R1",
|
| 62 |
id="deepseek-ai/DeepSeek-R1-0528",
|
| 63 |
+
description="DeepSeek R1 model for code generation",
|
| 64 |
),
|
| 65 |
+
# Multimodal Chinese / English models
|
| 66 |
ModelInfo(
|
| 67 |
+
name="ERNIE‑4.5‑VL",
|
| 68 |
id="baidu/ERNIE-4.5-VL-424B-A47B-Base-PT",
|
| 69 |
+
description="ERNIE‑4.5‑VL multimodal model (image + text)",
|
| 70 |
),
|
| 71 |
ModelInfo(
|
| 72 |
+
name="GLM‑4.1V‑9B‑Thinking",
|
| 73 |
+
id="THUDM/GLM-4.1V-9B-Thinking",
|
| 74 |
+
description="GLM‑4.1V‑9B multimodal reasoning model",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
),
|
| 76 |
+
# Lightweight general‑purpose models
|
| 77 |
ModelInfo(
|
| 78 |
+
name="SmolLM3‑3B",
|
| 79 |
id="HuggingFaceTB/SmolLM3-3B",
|
| 80 |
+
description="SmolLM3‑3B fast, low‑latency model",
|
| 81 |
),
|
| 82 |
ModelInfo(
|
| 83 |
+
name="MiniMax M1",
|
| 84 |
+
id="MiniMaxAI/MiniMax-M1-80k",
|
| 85 |
+
description="MiniMax M1 80k‑context general model",
|
| 86 |
),
|
| 87 |
+
# External providers via HF Inference Providers
|
| 88 |
ModelInfo(
|
| 89 |
+
name="OpenAI GPT‑4",
|
| 90 |
id="openai/gpt-4",
|
| 91 |
+
description="OpenAI GPT‑4 accessed through HF Inference Providers",
|
| 92 |
+
default_provider="openai",
|
| 93 |
),
|
| 94 |
ModelInfo(
|
| 95 |
+
name="Gemini Pro",
|
| 96 |
id="gemini/pro",
|
| 97 |
+
description="Google Gemini Pro via HF Inference Providers",
|
| 98 |
+
default_provider="gemini",
|
| 99 |
),
|
| 100 |
ModelInfo(
|
| 101 |
+
name="Fireworks V1",
|
| 102 |
id="fireworks-ai/fireworks-v1",
|
| 103 |
+
description="Fireworks AI flagship model",
|
| 104 |
+
default_provider="fireworks",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
),
|
| 106 |
]
|
| 107 |
|
| 108 |
|
| 109 |
+
# ------------------------------------------------------------------
|
| 110 |
+
# Helper look‑ups
|
| 111 |
+
# ------------------------------------------------------------------
|
| 112 |
def find_model(identifier: str) -> Optional[ModelInfo]:
|
| 113 |
"""
|
| 114 |
+
Retrieve a `ModelInfo` either by `.id` or by case‑insensitive `.name`.
|
| 115 |
+
|
| 116 |
+
Parameters
|
| 117 |
+
----------
|
| 118 |
+
identifier : str
|
| 119 |
+
- `"openai/gpt-4"` – exact id
|
| 120 |
+
- `"OpenAI GPT-4"` – human label
|
| 121 |
|
| 122 |
+
Returns
|
| 123 |
+
-------
|
| 124 |
+
Optional[ModelInfo]
|
|
|
|
| 125 |
"""
|
| 126 |
key = identifier.lower()
|
| 127 |
for m in AVAILABLE_MODELS:
|
| 128 |
if m.id == identifier or m.name.lower() == key:
|
| 129 |
return m
|
| 130 |
+
return None
|