增加硅基流动的预设
This commit is contained in:
+3
-1
@@ -104,6 +104,7 @@ Key fields:
|
||||
- `providers`: list of configured model endpoints
|
||||
- `providers[].id`: stable id used by `/use <id>`
|
||||
- `providers[].preset`: provider preset name
|
||||
Built-in presets include `openai_chatgpt`, `zhipu_coding_plan`, `siliconflow`, and `custom_openai_compatible`
|
||||
- `providers[].api_key`: provider API key
|
||||
- `providers[].api_base`: optional compatible base URL
|
||||
- `providers[].model`: model name
|
||||
@@ -131,7 +132,8 @@ Each provider has a unique id, for example:
|
||||
"default_provider": "1",
|
||||
"providers": [
|
||||
{ "id": "1", "preset": "zhipu_coding_plan", "api_key": "...", "model": "glm-4.7" },
|
||||
{ "id": "2", "preset": "openai_chatgpt", "api_key": "...", "model": "gpt-4.1-mini" }
|
||||
{ "id": "2", "preset": "openai_chatgpt", "api_key": "...", "model": "gpt-4.1-mini" },
|
||||
{ "id": "3", "preset": "siliconflow", "api_key": "...", "model": "deepseek-ai/DeepSeek-V3" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
+3
-1
@@ -104,6 +104,7 @@ voidbot data dump --session-id main
|
||||
- `providers`:模型配置列表
|
||||
- `providers[].id`:稳定编号,用于 `/use <id>` 切换
|
||||
- `providers[].preset`:provider 预设名
|
||||
可用内置预设包括 `openai_chatgpt`、`zhipu_coding_plan`、`siliconflow`、`custom_openai_compatible`
|
||||
- `providers[].api_key`:模型 API Key
|
||||
- `providers[].api_base`:可选的兼容接口地址
|
||||
- `providers[].model`:模型名
|
||||
@@ -131,7 +132,8 @@ voidbot data dump --session-id main
|
||||
"default_provider": "1",
|
||||
"providers": [
|
||||
{ "id": "1", "preset": "zhipu_coding_plan", "api_key": "...", "model": "glm-4.7" },
|
||||
{ "id": "2", "preset": "openai_chatgpt", "api_key": "...", "model": "gpt-4.1-mini" }
|
||||
{ "id": "2", "preset": "openai_chatgpt", "api_key": "...", "model": "gpt-4.1-mini" },
|
||||
{ "id": "3", "preset": "siliconflow", "api_key": "...", "model": "deepseek-ai/DeepSeek-V3" }
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
@@ -15,6 +15,14 @@
|
||||
"preset": "openai_chatgpt",
|
||||
"api_key": "YOUR_OPENAI_API_KEY",
|
||||
"model": "gpt-4.1-mini"
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"label": "SiliconFlow",
|
||||
"preset": "siliconflow",
|
||||
"api_key": "YOUR_SILICONFLOW_API_KEY",
|
||||
"api_base": "https://api.siliconflow.cn/v1",
|
||||
"model": "deepseek-ai/DeepSeek-V3"
|
||||
}
|
||||
],
|
||||
"workspace": ".",
|
||||
|
||||
@@ -149,6 +149,14 @@ def build_example_config() -> dict[str, Any]:
|
||||
"api_key": "YOUR_OPENAI_API_KEY",
|
||||
"model": "gpt-4.1-mini",
|
||||
},
|
||||
{
|
||||
"id": "3",
|
||||
"label": "SiliconFlow",
|
||||
"preset": "siliconflow",
|
||||
"api_key": "YOUR_SILICONFLOW_API_KEY",
|
||||
"api_base": "https://api.siliconflow.cn/v1",
|
||||
"model": "deepseek-ai/DeepSeek-V3",
|
||||
},
|
||||
],
|
||||
"workspace": ".",
|
||||
"database_path": "~/.voidbot/voidbot.db",
|
||||
@@ -224,6 +232,63 @@ def sync_default_config() -> tuple[Path, bool, list[str]]:
|
||||
return config_path, created, added_paths
|
||||
|
||||
|
||||
def ensure_config_file(config_path: str | Path | None) -> Path:
|
||||
"""Return a writable config path, creating a template file when needed."""
|
||||
if config_path is None:
|
||||
path, _, _ = sync_default_config()
|
||||
return path
|
||||
|
||||
path = Path(config_path).expanduser().resolve()
|
||||
if path.exists():
|
||||
return path
|
||||
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_text(
|
||||
json.dumps(build_example_config(), ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
return path
|
||||
|
||||
|
||||
def load_config_payload(config_path: str | Path | None) -> tuple[Path, dict[str, Any]]:
|
||||
"""Load the raw JSON payload from a config file."""
|
||||
path = ensure_config_file(config_path)
|
||||
loaded = json.loads(path.read_text(encoding="utf-8"))
|
||||
if not isinstance(loaded, dict):
|
||||
raise ValueError("config must be a JSON object")
|
||||
return path, loaded
|
||||
|
||||
|
||||
def save_config_payload(path: Path, payload: dict[str, Any]) -> None:
|
||||
"""Persist a config payload to disk."""
|
||||
path.write_text(
|
||||
json.dumps(payload, ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def add_provider_config(
|
||||
config_path: str | Path | None,
|
||||
provider: ProviderConfig,
|
||||
*,
|
||||
set_default: bool = False,
|
||||
) -> tuple[Path, AppConfig]:
|
||||
"""Append one provider config to the config file and reload it."""
|
||||
path, payload = load_config_payload(config_path)
|
||||
providers = _extract_provider_payloads(payload)
|
||||
existing_ids = {str(item.get("id") or "").strip() for item in providers}
|
||||
if provider.id in existing_ids:
|
||||
raise ValueError(f"provider id '{provider.id}' already exists")
|
||||
|
||||
providers.append(_provider_to_mapping(provider))
|
||||
payload["providers"] = providers
|
||||
if set_default or len(providers) == 1:
|
||||
payload["default_provider"] = provider.id
|
||||
|
||||
save_config_payload(path, payload)
|
||||
return path, load_config(path, require_api_key=False)
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class AppConfig:
|
||||
"""Runtime configuration."""
|
||||
@@ -356,6 +421,34 @@ class AppConfig:
|
||||
return providers[0]
|
||||
|
||||
|
||||
def _provider_to_mapping(provider: ProviderConfig) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {
|
||||
"id": provider.id,
|
||||
"preset": provider.preset,
|
||||
"api_key": provider.api_key,
|
||||
}
|
||||
if provider.label:
|
||||
payload["label"] = provider.label
|
||||
if provider.api_base:
|
||||
payload["api_base"] = provider.api_base
|
||||
if provider.model:
|
||||
payload["model"] = provider.model
|
||||
return payload
|
||||
|
||||
|
||||
def _extract_provider_payloads(payload: dict[str, Any]) -> list[dict[str, Any]]:
|
||||
raw_providers = payload.get("providers")
|
||||
if isinstance(raw_providers, list):
|
||||
return [dict(item) for item in raw_providers if isinstance(item, dict)]
|
||||
|
||||
legacy_keys = ("provider", "api_key", "api_base", "model")
|
||||
if not any(payload.get(key) for key in legacy_keys):
|
||||
return []
|
||||
|
||||
config = AppConfig.from_mapping(payload)
|
||||
return [_provider_to_mapping(item) for item in config.list_provider_configs()]
|
||||
|
||||
|
||||
def load_config(
|
||||
config_path: str | Path | None,
|
||||
*,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import getpass
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
@@ -13,6 +14,9 @@ from voidbot.app import build_app
|
||||
from voidbot.channels.manager import ChannelManager
|
||||
from voidbot.config import (
|
||||
AppConfig,
|
||||
ProviderConfig,
|
||||
add_provider_config,
|
||||
ensure_config_file,
|
||||
get_default_config_path,
|
||||
get_voidbot_home,
|
||||
load_config,
|
||||
@@ -23,6 +27,7 @@ from voidbot.gateway.messages import InboundMessageContext
|
||||
from voidbot.gateway.server import GatewayApplication, run_gateway_server
|
||||
from voidbot.gateway.ui import render_single_turn, run_terminal_loop
|
||||
from voidbot.i18n import t
|
||||
from voidbot.providers.registry import get_provider_spec, list_provider_specs
|
||||
from voidbot.runtime_env import (
|
||||
resolve_entrypoint_path,
|
||||
resolve_launch_cwd,
|
||||
@@ -86,6 +91,45 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
"open",
|
||||
help=t("cli.help.config.open"),
|
||||
)
|
||||
add_model_parser = config_subparsers.add_parser(
|
||||
"add-model",
|
||||
help=t("cli.help.config.add_model"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--config",
|
||||
type=Path,
|
||||
help=_config_help_text(),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--provider",
|
||||
help=t("cli.help.config.add_model.provider"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--id",
|
||||
dest="provider_id",
|
||||
help=t("cli.help.config.add_model.id"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--label",
|
||||
help=t("cli.help.config.add_model.label"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--api-key",
|
||||
help=t("cli.help.config.add_model.api_key"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--model",
|
||||
help=t("cli.help.config.add_model.model"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--api-base",
|
||||
help=t("cli.help.config.add_model.api_base"),
|
||||
)
|
||||
add_model_parser.add_argument(
|
||||
"--set-default",
|
||||
action="store_true",
|
||||
help=t("cli.help.config.add_model.set_default"),
|
||||
)
|
||||
|
||||
data_parser = subparsers.add_parser(
|
||||
"data",
|
||||
@@ -148,6 +192,18 @@ def main() -> None:
|
||||
if args.config_command == "open":
|
||||
run_config_open_command()
|
||||
return
|
||||
if args.config_command == "add-model":
|
||||
run_config_add_model_command(
|
||||
config_path=args.config,
|
||||
provider=args.provider,
|
||||
provider_id=args.provider_id,
|
||||
label=args.label,
|
||||
api_key=args.api_key,
|
||||
model=args.model,
|
||||
api_base=args.api_base,
|
||||
set_default=args.set_default,
|
||||
)
|
||||
return
|
||||
if args.command == "data" and args.data_command == "dump":
|
||||
run_data_dump_command(
|
||||
config_path=args.config,
|
||||
@@ -276,6 +332,97 @@ def run_config_open_command() -> None:
|
||||
print(t("config.opened", path=config_path))
|
||||
|
||||
|
||||
def run_config_add_model_command(
|
||||
*,
|
||||
config_path: Path | None,
|
||||
provider: str | None,
|
||||
provider_id: str | None,
|
||||
label: str | None,
|
||||
api_key: str | None,
|
||||
model: str | None,
|
||||
api_base: str | None,
|
||||
set_default: bool,
|
||||
) -> None:
|
||||
"""Add one provider profile into the config file."""
|
||||
target_path = ensure_config_file(config_path)
|
||||
current_config = load_config(target_path, require_api_key=False)
|
||||
resolved_provider = provider or _prompt_provider_preset()
|
||||
spec = get_provider_spec(resolved_provider)
|
||||
resolved_api_key = api_key or _prompt_text(
|
||||
t("config.add_model.prompt.api_key"),
|
||||
secret=True,
|
||||
)
|
||||
resolved_model = model or _prompt_text(
|
||||
t("config.add_model.prompt.model"),
|
||||
default=spec.default_model,
|
||||
)
|
||||
existing_ids = {profile.id for profile in current_config.list_provider_configs()}
|
||||
suggested_id = _build_unique_provider_id(resolved_model, existing_ids)
|
||||
if spec.name == "custom_openai_compatible":
|
||||
resolved_id = provider_id or _prompt_text(
|
||||
t("config.add_model.prompt.id"),
|
||||
default=suggested_id,
|
||||
)
|
||||
resolved_label = label or _prompt_text(
|
||||
t("config.add_model.prompt.label"),
|
||||
default=resolved_id,
|
||||
)
|
||||
resolved_api_base = api_base or _prompt_text(
|
||||
t("config.add_model.prompt.api_base"),
|
||||
)
|
||||
else:
|
||||
resolved_id = provider_id or suggested_id
|
||||
resolved_label = label or spec.label
|
||||
resolved_api_base = api_base or spec.default_base_url
|
||||
resolved_set_default = set_default or _prompt_yes_no(
|
||||
t("config.add_model.prompt.set_default"),
|
||||
default=False,
|
||||
)
|
||||
|
||||
saved_path, updated_config = add_provider_config(
|
||||
target_path,
|
||||
ProviderConfig(
|
||||
id=resolved_id,
|
||||
preset=spec.name,
|
||||
api_key=resolved_api_key,
|
||||
api_base=resolved_api_base,
|
||||
model=resolved_model,
|
||||
label=resolved_label,
|
||||
),
|
||||
set_default=resolved_set_default,
|
||||
)
|
||||
|
||||
print(t("config.add_model.saved", path=saved_path))
|
||||
print(
|
||||
t(
|
||||
"config.add_model.summary",
|
||||
id=resolved_id,
|
||||
label=resolved_label,
|
||||
preset=spec.name,
|
||||
model=resolved_model,
|
||||
)
|
||||
)
|
||||
default_profile = updated_config.get_provider_config()
|
||||
print(
|
||||
t(
|
||||
"config.add_model.default",
|
||||
id=default_profile.id,
|
||||
label=default_profile.label or default_profile.preset,
|
||||
)
|
||||
)
|
||||
print(t("config.add_model.providers"))
|
||||
for profile in updated_config.list_provider_configs():
|
||||
print(
|
||||
t(
|
||||
"config.add_model.provider_item",
|
||||
id=profile.id,
|
||||
label=profile.label or profile.preset,
|
||||
preset=profile.preset,
|
||||
model=profile.model or "(default)",
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def run_data_dump_command(
|
||||
*,
|
||||
config_path: Path | None,
|
||||
@@ -300,6 +447,87 @@ def _open_path(path: Path) -> None:
|
||||
subprocess.Popen(["/usr/bin/xdg-open", str(path)])
|
||||
|
||||
|
||||
def _build_unique_provider_id(model_name: str, existing_ids: set[str]) -> str:
|
||||
candidate = model_name.strip() or "model"
|
||||
if candidate not in existing_ids:
|
||||
return candidate
|
||||
index = 2
|
||||
while f"{candidate}-{index}" in existing_ids:
|
||||
index += 1
|
||||
return f"{candidate}-{index}"
|
||||
|
||||
|
||||
def _prompt_provider_preset() -> str:
|
||||
specs = list_provider_specs()
|
||||
print(t("config.add_model.supported"))
|
||||
for index, spec in enumerate(specs, start=1):
|
||||
print(
|
||||
t(
|
||||
"config.add_model.supported_item",
|
||||
index=index,
|
||||
label=spec.label,
|
||||
preset=spec.name,
|
||||
api_base=spec.default_base_url,
|
||||
model=spec.default_model,
|
||||
)
|
||||
)
|
||||
allowed = {spec.name: spec.name for spec in specs}
|
||||
while True:
|
||||
raw = _prompt_text(
|
||||
t("config.add_model.prompt.provider"),
|
||||
default=specs[0].name,
|
||||
)
|
||||
if raw in allowed:
|
||||
return allowed[raw]
|
||||
if raw.isdigit():
|
||||
index = int(raw)
|
||||
if 1 <= index <= len(specs):
|
||||
return specs[index - 1].name
|
||||
print(t("config.add_model.invalid_provider", value=raw))
|
||||
|
||||
|
||||
def _prompt_text(
|
||||
label: str,
|
||||
*,
|
||||
default: str | None = None,
|
||||
secret: bool = False,
|
||||
) -> str:
|
||||
if not sys.stdin.isatty():
|
||||
if default is not None:
|
||||
return default
|
||||
raise ValueError(t("config.add_model.non_interactive", field=label))
|
||||
|
||||
while True:
|
||||
suffix = f" [{default}]" if default else ""
|
||||
prompt_text = f"{label}{suffix}: "
|
||||
value = (
|
||||
getpass.getpass(prompt_text)
|
||||
if secret
|
||||
else input(prompt_text)
|
||||
).strip()
|
||||
if value:
|
||||
return value
|
||||
if default is not None:
|
||||
return default
|
||||
print(t("config.add_model.required", field=label))
|
||||
|
||||
|
||||
def _prompt_yes_no(label: str, *, default: bool) -> bool:
|
||||
if not sys.stdin.isatty():
|
||||
return default
|
||||
|
||||
hint = "Y/n" if default else "y/N"
|
||||
while True:
|
||||
raw = input(f"{label} [{hint}]: ").strip().lower()
|
||||
if not raw:
|
||||
return default
|
||||
if raw in {"y", "yes"}:
|
||||
return True
|
||||
if raw in {"n", "no"}:
|
||||
return False
|
||||
print(t("config.add_model.invalid_yes_no"))
|
||||
|
||||
|
||||
def _run_one_turn(
|
||||
*,
|
||||
message: str,
|
||||
|
||||
@@ -19,6 +19,14 @@ TRANSLATIONS: dict[str, dict[str, str]] = {
|
||||
),
|
||||
"cli.help.config.path": "Print the default user-level config path",
|
||||
"cli.help.config.open": "Open the default config file with the system default application",
|
||||
"cli.help.config.add_model": "Add one provider/model profile into the config file",
|
||||
"cli.help.config.add_model.provider": "Built-in provider preset name",
|
||||
"cli.help.config.add_model.id": "Optional provider id override used by /use <id>",
|
||||
"cli.help.config.add_model.label": "Optional display label override",
|
||||
"cli.help.config.add_model.api_key": "Provider API key",
|
||||
"cli.help.config.add_model.model": "Provider model id",
|
||||
"cli.help.config.add_model.api_base": "Override API base URL",
|
||||
"cli.help.config.add_model.set_default": "Set the newly added provider as default",
|
||||
"cli.help.config.path_flag": "Print the target config path after syncing",
|
||||
"cli.help.data.dump": "Print stored sessions and messages from the SQLite database",
|
||||
"cli.help.data.session_id": "Optional session id filter",
|
||||
@@ -36,6 +44,35 @@ TRANSLATIONS: dict[str, dict[str, str]] = {
|
||||
"config.sync.no_changes": "No missing fields were added.",
|
||||
"config.sync.home": "VoidBot home: {path}",
|
||||
"config.opened": "Opened {path}",
|
||||
"config.add_model.supported": "Supported provider presets:",
|
||||
"config.add_model.supported_item": (
|
||||
" {index}. {label} ({preset}) "
|
||||
"[api_base={api_base}, model={model}]"
|
||||
),
|
||||
"config.add_model.prompt.provider": "Choose provider preset",
|
||||
"config.add_model.prompt.id": "Provider id",
|
||||
"config.add_model.prompt.label": "Display label",
|
||||
"config.add_model.prompt.api_key": "API key",
|
||||
"config.add_model.prompt.model": "Model id",
|
||||
"config.add_model.prompt.api_base": "API base URL",
|
||||
"config.add_model.prompt.set_default": "Set this provider as default?",
|
||||
"config.add_model.invalid_provider": "Unknown provider preset: {value}",
|
||||
"config.add_model.invalid_yes_no": "Please answer yes or no.",
|
||||
"config.add_model.required": "{field} is required.",
|
||||
"config.add_model.non_interactive": (
|
||||
"missing required interactive field: {field}. "
|
||||
"Pass it explicitly with command flags."
|
||||
),
|
||||
"config.add_model.saved": "Saved provider config to {path}",
|
||||
"config.add_model.summary": (
|
||||
"Added provider {id}: {label} "
|
||||
"[preset={preset}, model={model}]"
|
||||
),
|
||||
"config.add_model.default": "Current default provider: {id} / {label}",
|
||||
"config.add_model.providers": "Configured providers:",
|
||||
"config.add_model.provider_item": (
|
||||
" - {id}. {label} [preset={preset}, model={model}]"
|
||||
),
|
||||
"gateway.listening": "VoidBot gateway listening on http://{host}:{port}",
|
||||
"ui.title": "terminal agent",
|
||||
"ui.session": "Session",
|
||||
@@ -80,6 +117,14 @@ TRANSLATIONS: dict[str, dict[str, str]] = {
|
||||
"cli.help.config.sync": "根据示例模板创建或增量更新 ~/.voidbot/config.json",
|
||||
"cli.help.config.path": "输出默认用户级配置文件路径",
|
||||
"cli.help.config.open": "用系统默认程序打开配置文件",
|
||||
"cli.help.config.add_model": "向配置文件中新增一个 provider/model 配置",
|
||||
"cli.help.config.add_model.provider": "内置 provider 预设名",
|
||||
"cli.help.config.add_model.id": "可选,覆盖自动生成的 provider id(用于 /use <id>)",
|
||||
"cli.help.config.add_model.label": "可选,覆盖默认显示名称",
|
||||
"cli.help.config.add_model.api_key": "Provider API Key",
|
||||
"cli.help.config.add_model.model": "模型 ID",
|
||||
"cli.help.config.add_model.api_base": "覆盖 API 基础地址",
|
||||
"cli.help.config.add_model.set_default": "将新加的 provider 设为默认值",
|
||||
"cli.help.config.path_flag": "同步后额外输出目标配置路径",
|
||||
"cli.help.data.dump": "输出 SQLite 数据库中的会话与消息",
|
||||
"cli.help.data.session_id": "可选的 session_id 过滤条件",
|
||||
@@ -97,6 +142,35 @@ TRANSLATIONS: dict[str, dict[str, str]] = {
|
||||
"config.sync.no_changes": "没有新增任何缺失字段。",
|
||||
"config.sync.home": "VoidBot 主目录:{path}",
|
||||
"config.opened": "已打开 {path}",
|
||||
"config.add_model.supported": "系统支持的 provider 预设:",
|
||||
"config.add_model.supported_item": (
|
||||
" {index}. {label} ({preset}) "
|
||||
"[api_base={api_base}, model={model}]"
|
||||
),
|
||||
"config.add_model.prompt.provider": "选择 provider 预设",
|
||||
"config.add_model.prompt.id": "Provider 编号",
|
||||
"config.add_model.prompt.label": "显示名称",
|
||||
"config.add_model.prompt.api_key": "API Key",
|
||||
"config.add_model.prompt.model": "模型 ID",
|
||||
"config.add_model.prompt.api_base": "API 基础地址",
|
||||
"config.add_model.prompt.set_default": "是否将该 provider 设为默认值?",
|
||||
"config.add_model.invalid_provider": "未知 provider 预设:{value}",
|
||||
"config.add_model.invalid_yes_no": "请输入 yes/no。",
|
||||
"config.add_model.required": "{field} 不能为空。",
|
||||
"config.add_model.non_interactive": (
|
||||
"缺少必填交互字段:{field}。"
|
||||
"请通过命令参数显式传入。"
|
||||
),
|
||||
"config.add_model.saved": "已将 provider 配置写入 {path}",
|
||||
"config.add_model.summary": (
|
||||
"已新增 provider {id}:{label} "
|
||||
"[preset={preset}, model={model}]"
|
||||
),
|
||||
"config.add_model.default": "当前默认 provider:{id} / {label}",
|
||||
"config.add_model.providers": "当前 provider 列表:",
|
||||
"config.add_model.provider_item": (
|
||||
" - {id}. {label} [preset={preset}, model={model}]"
|
||||
),
|
||||
"gateway.listening": "VoidBot gateway 正在监听 http://{host}:{port}",
|
||||
"ui.title": "终端智能体",
|
||||
"ui.session": "会话",
|
||||
|
||||
@@ -18,6 +18,12 @@ PROVIDERS: dict[str, ProviderSpec] = {
|
||||
default_base_url="https://open.bigmodel.cn/api/coding/paas/v4",
|
||||
default_model="glm-4.7",
|
||||
),
|
||||
"siliconflow": ProviderSpec(
|
||||
name="siliconflow",
|
||||
label="SiliconFlow",
|
||||
default_base_url="https://api.siliconflow.cn/v1",
|
||||
default_model="deepseek-ai/DeepSeek-V3",
|
||||
),
|
||||
"custom_openai_compatible": ProviderSpec(
|
||||
name="custom_openai_compatible",
|
||||
label="Custom OpenAI-Compatible",
|
||||
@@ -27,6 +33,11 @@ PROVIDERS: dict[str, ProviderSpec] = {
|
||||
}
|
||||
|
||||
|
||||
def list_provider_specs() -> list[ProviderSpec]:
|
||||
"""Return all built-in provider presets."""
|
||||
return list(PROVIDERS.values())
|
||||
|
||||
|
||||
def get_provider_spec(name: str) -> ProviderSpec:
|
||||
"""Return a provider preset by name."""
|
||||
try:
|
||||
|
||||
@@ -8,6 +8,7 @@ from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from voidbot.config import (
|
||||
build_example_config,
|
||||
get_default_config_path,
|
||||
get_default_database_path,
|
||||
load_config,
|
||||
@@ -190,6 +191,16 @@ class ConfigLoadingTests(unittest.TestCase):
|
||||
self.assertTrue(merged["channels"]["feishu"]["enabled"])
|
||||
self.assertTrue(merged["custom_field"]["keep_me"])
|
||||
|
||||
def test_example_config_includes_siliconflow_provider(self) -> None:
|
||||
example = build_example_config()
|
||||
providers = example["providers"]
|
||||
siliconflow = next(
|
||||
provider for provider in providers if provider["preset"] == "siliconflow"
|
||||
)
|
||||
|
||||
self.assertEqual(siliconflow["api_base"], "https://api.siliconflow.cn/v1")
|
||||
self.assertEqual(siliconflow["model"], "deepseek-ai/DeepSeek-V3")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -12,6 +12,7 @@ from voidbot.config import AppConfig
|
||||
from voidbot.gateway.cli import (
|
||||
_run_one_turn,
|
||||
build_parser,
|
||||
run_config_add_model_command,
|
||||
run_config_open_command,
|
||||
run_config_path_command,
|
||||
run_config_sync_command,
|
||||
@@ -162,11 +163,26 @@ class GatewayTests(unittest.TestCase):
|
||||
sync_args = parser.parse_args(["config", "sync"])
|
||||
path_args = parser.parse_args(["config", "path"])
|
||||
open_args = parser.parse_args(["config", "open"])
|
||||
add_model_args = parser.parse_args(
|
||||
[
|
||||
"config",
|
||||
"add-model",
|
||||
"--provider",
|
||||
"siliconflow",
|
||||
"--id",
|
||||
"3",
|
||||
"--api-key",
|
||||
"key",
|
||||
"--model",
|
||||
"deepseek-ai/DeepSeek-V3",
|
||||
]
|
||||
)
|
||||
dump_args = parser.parse_args(["data", "dump"])
|
||||
|
||||
self.assertEqual(sync_args.config_command, "sync")
|
||||
self.assertEqual(path_args.config_command, "path")
|
||||
self.assertEqual(open_args.config_command, "open")
|
||||
self.assertEqual(add_model_args.config_command, "add-model")
|
||||
self.assertEqual(dump_args.data_command, "dump")
|
||||
|
||||
def test_config_sync_command_prints_added_fields(self) -> None:
|
||||
@@ -199,6 +215,88 @@ class GatewayTests(unittest.TestCase):
|
||||
|
||||
self.assertIn(".voidbot/config.json", buffer.getvalue())
|
||||
|
||||
def test_config_add_model_command_auto_generates_id_for_builtin_provider(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
config_path = Path(temp_dir) / "config.json"
|
||||
config_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"default_provider": "1",
|
||||
"providers": [
|
||||
{
|
||||
"id": "1",
|
||||
"preset": "openai_chatgpt",
|
||||
"api_key": "openai-key",
|
||||
"model": "gpt-4.1-mini",
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
buffer = io.StringIO()
|
||||
|
||||
with patch("sys.stdout", buffer):
|
||||
run_config_add_model_command(
|
||||
config_path=config_path,
|
||||
provider="siliconflow",
|
||||
provider_id=None,
|
||||
label=None,
|
||||
api_key="sf-key",
|
||||
model="deepseek-ai/DeepSeek-V3",
|
||||
api_base=None,
|
||||
set_default=True,
|
||||
)
|
||||
|
||||
updated = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
|
||||
self.assertEqual(updated["default_provider"], "deepseek-ai/DeepSeek-V3")
|
||||
self.assertEqual(updated["providers"][-1]["id"], "deepseek-ai/DeepSeek-V3")
|
||||
self.assertEqual(updated["providers"][-1]["preset"], "siliconflow")
|
||||
self.assertEqual(
|
||||
updated["providers"][-1]["api_base"],
|
||||
"https://api.siliconflow.cn/v1",
|
||||
)
|
||||
self.assertEqual(updated["providers"][-1]["label"], "SiliconFlow")
|
||||
self.assertIn("deepseek-ai/DeepSeek-V3", buffer.getvalue())
|
||||
|
||||
def test_config_add_model_command_deduplicates_auto_generated_id(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as temp_dir:
|
||||
config_path = Path(temp_dir) / "config.json"
|
||||
config_path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"default_provider": "deepseek-ai/DeepSeek-V3",
|
||||
"providers": [
|
||||
{
|
||||
"id": "deepseek-ai/DeepSeek-V3",
|
||||
"preset": "siliconflow",
|
||||
"api_key": "sf-key-1",
|
||||
"model": "deepseek-ai/DeepSeek-V3",
|
||||
}
|
||||
],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
buffer = io.StringIO()
|
||||
|
||||
with patch("sys.stdout", buffer):
|
||||
run_config_add_model_command(
|
||||
config_path=config_path,
|
||||
provider="siliconflow",
|
||||
provider_id=None,
|
||||
label=None,
|
||||
api_key="sf-key-2",
|
||||
model="deepseek-ai/DeepSeek-V3",
|
||||
api_base=None,
|
||||
set_default=False,
|
||||
)
|
||||
|
||||
updated = json.loads(config_path.read_text(encoding="utf-8"))
|
||||
|
||||
self.assertEqual(updated["providers"][-1]["id"], "deepseek-ai/DeepSeek-V3-2")
|
||||
|
||||
def test_config_open_command_opens_synced_path(self) -> None:
|
||||
buffer = io.StringIO()
|
||||
with patch(
|
||||
|
||||
@@ -13,6 +13,11 @@ class ProviderRegistryTests(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(spec.default_model, "glm-4.7")
|
||||
|
||||
def test_siliconflow_preset_exists(self) -> None:
|
||||
spec = get_provider_spec("siliconflow")
|
||||
self.assertEqual(spec.default_base_url, "https://api.siliconflow.cn/v1")
|
||||
self.assertEqual(spec.default_model, "deepseek-ai/DeepSeek-V3")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user