mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-05-20 16:42:25 +00:00
feat(providers): add APIFree support
Add APIFree as a built-in OpenAI-compatible provider. APIFree offers agent-optimised models such as skywork-ai/skyclaw-v1 through an OpenAI-compatible API at https://api.apifree.ai/agent/v1. Changes: - Register apifree provider in the provider registry - Add config schema field - Add documentation with configuration example - Add provider tests, websocket channel tests, and webui tests - Add provider icon in settings UI
This commit is contained in:
parent
3eebe08dba
commit
61ae869610
@ -154,6 +154,7 @@ ANTHROPIC_API_KEY="$(bw get password api/anthropic)" nanobot agent
|
||||
| `mimo` | LLM (MiMo) | [platform.xiaomimimo.com](https://platform.xiaomimimo.com) |
|
||||
| `longcat` | LLM (LongCat) | [longcat.chat](https://longcat.chat/platform/docs/zh/) |
|
||||
| `ant_ling` | LLM (Ant Ling / 蚂蚁百灵) | [developer.ant-ling.com](https://developer.ant-ling.com/en/docs/api-reference/openai/) |
|
||||
| `apifree` | LLM (APIFree) | [apifree.ai](https://www.apifree.ai) |
|
||||
| `ollama` | LLM (local, Ollama) | — |
|
||||
| `lm_studio` | LLM (local, LM Studio) | — |
|
||||
| `atomic_chat` | LLM (local, [Atomic Chat](https://atomic.chat/)) | — |
|
||||
@ -504,6 +505,33 @@ Official OpenAI-compatible model names include `Ling-2.6-1T`,
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>APIFree (OpenAI-compatible)</b></summary>
|
||||
|
||||
APIFree is available through nanobot's built-in OpenAI-compatible provider flow.
|
||||
The default API base points to `https://api.apifree.ai/agent/v1`, so you usually
|
||||
only need to set `apiKey`.
|
||||
|
||||
```json
|
||||
{
|
||||
"providers": {
|
||||
"apifree": {
|
||||
"apiKey": "${APIFREE_API_KEY}"
|
||||
}
|
||||
},
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"provider": "apifree",
|
||||
"model": "skywork-ai/skyclaw-v1"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Available models include `skywork-ai/skyclaw-v1`.
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
<summary><b>Custom Provider (Any OpenAI-compatible API)</b></summary>
|
||||
|
||||
|
||||
@ -209,6 +209,7 @@ class ProvidersConfig(Base):
|
||||
xiaomi_mimo: ProviderConfig = Field(default_factory=ProviderConfig) # Xiaomi MIMO (小米)
|
||||
longcat: ProviderConfig = Field(default_factory=ProviderConfig) # LongCat
|
||||
ant_ling: ProviderConfig = Field(default_factory=ProviderConfig) # Ant Ling
|
||||
apifree: ProviderConfig = Field(default_factory=ProviderConfig) # APIFree
|
||||
aihubmix: ProviderConfig = Field(default_factory=ProviderConfig) # AiHubMix API gateway
|
||||
siliconflow: ProviderConfig = Field(default_factory=ProviderConfig) # SiliconFlow (硅基流动)
|
||||
volcengine: ProviderConfig = Field(default_factory=ProviderConfig) # VolcEngine (火山引擎)
|
||||
|
||||
@ -412,6 +412,16 @@ PROVIDERS: tuple[ProviderSpec, ...] = (
|
||||
detect_by_base_keyword="ant-ling.com",
|
||||
default_api_base="https://api.ant-ling.com/v1",
|
||||
),
|
||||
# APIFree: OpenAI-compatible API gateway with agent-optimised models.
|
||||
ProviderSpec(
|
||||
name="apifree",
|
||||
keywords=("apifree", "api-free", "skyclaw"),
|
||||
env_key="APIFREE_API_KEY",
|
||||
display_name="APIFree",
|
||||
backend="openai_compat",
|
||||
detect_by_base_keyword="apifree.ai",
|
||||
default_api_base="https://api.apifree.ai/agent/v1",
|
||||
),
|
||||
# === Local deployment (matched by config key, NOT by api_base) =========
|
||||
# vLLM / any OpenAI-compatible local server
|
||||
ProviderSpec(
|
||||
|
||||
@ -1034,6 +1034,8 @@ async def test_settings_api_returns_safe_subset_and_updates_whitelist(
|
||||
assert providers["skywork"]["default_api_base"] == "https://api.apifree.ai/v1"
|
||||
assert providers["ant_ling"]["label"] == "Ant Ling"
|
||||
assert providers["ant_ling"]["default_api_base"] == "https://api.ant-ling.com/v1"
|
||||
assert providers["apifree"]["label"] == "APIFree"
|
||||
assert providers["apifree"]["default_api_base"] == "https://api.apifree.ai/agent/v1"
|
||||
assert providers["atomic_chat"]["configured"] is False
|
||||
assert providers["atomic_chat"]["api_key_required"] is False
|
||||
assert providers["atomic_chat"]["default_api_base"] == "http://localhost:1337/v1"
|
||||
|
||||
71
tests/providers/test_apifree_provider.py
Normal file
71
tests/providers/test_apifree_provider.py
Normal file
@ -0,0 +1,71 @@
|
||||
"""Tests for the APIFree provider registration."""
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from nanobot.config.schema import Config, ProvidersConfig
|
||||
from nanobot.providers.openai_compat_provider import OpenAICompatProvider
|
||||
from nanobot.providers.registry import PROVIDERS, find_by_name
|
||||
|
||||
|
||||
def test_apifree_config_field_exists() -> None:
|
||||
config = ProvidersConfig()
|
||||
assert hasattr(config, "apifree")
|
||||
|
||||
|
||||
def test_apifree_provider_in_registry() -> None:
|
||||
specs = {spec.name: spec for spec in PROVIDERS}
|
||||
assert "apifree" in specs
|
||||
|
||||
apifree = specs["apifree"]
|
||||
assert apifree.backend == "openai_compat"
|
||||
assert apifree.env_key == "APIFREE_API_KEY"
|
||||
assert apifree.display_name == "APIFree"
|
||||
assert apifree.default_api_base == "https://api.apifree.ai/agent/v1"
|
||||
|
||||
|
||||
def test_find_by_name_accepts_apifree_spellings() -> None:
|
||||
spec = find_by_name("apifree")
|
||||
assert spec is not None
|
||||
|
||||
|
||||
def test_apifree_model_auto_matches_with_default_api_base() -> None:
|
||||
config = Config.model_validate(
|
||||
{
|
||||
"providers": {
|
||||
"apifree": {
|
||||
"apiKey": "apifree-key",
|
||||
},
|
||||
},
|
||||
"agents": {
|
||||
"defaults": {
|
||||
"model": "skywork-ai/skyclaw-v1",
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
assert config.get_provider_name("skywork-ai/skyclaw-v1") == "apifree"
|
||||
assert config.get_api_key("skywork-ai/skyclaw-v1") == "apifree-key"
|
||||
assert config.get_api_base("skywork-ai/skyclaw-v1") == "https://api.apifree.ai/agent/v1"
|
||||
|
||||
|
||||
def test_apifree_preserves_official_model_name() -> None:
|
||||
spec = find_by_name("apifree")
|
||||
with patch("nanobot.providers.openai_compat_provider.AsyncOpenAI"):
|
||||
provider = OpenAICompatProvider(
|
||||
api_key="apifree-key",
|
||||
default_model="skywork-ai/skyclaw-v1",
|
||||
spec=spec,
|
||||
)
|
||||
|
||||
kwargs = provider._build_kwargs(
|
||||
messages=[{"role": "user", "content": "hi"}],
|
||||
tools=None,
|
||||
model="skywork-ai/skyclaw-v1",
|
||||
max_tokens=1024,
|
||||
temperature=0.7,
|
||||
reasoning_effort=None,
|
||||
tool_choice=None,
|
||||
)
|
||||
|
||||
assert kwargs["model"] == "skywork-ai/skyclaw-v1"
|
||||
@ -2150,6 +2150,7 @@ const PROVIDER_ICONS: Record<string, LucideIcon> = {
|
||||
byteplus_coding_plan: Cloud,
|
||||
qianfan: Database,
|
||||
ant_ling: Sparkles,
|
||||
apifree: Sparkles,
|
||||
azure_openai: Cloud,
|
||||
bedrock: Database,
|
||||
vllm: Cpu,
|
||||
|
||||
@ -580,6 +580,13 @@ describe("App layout", () => {
|
||||
api_key_required: true,
|
||||
default_api_base: "https://api.ant-ling.com/v1",
|
||||
},
|
||||
{
|
||||
name: "apifree",
|
||||
label: "APIFree",
|
||||
configured: false,
|
||||
api_key_required: true,
|
||||
default_api_base: "https://api.apifree.ai/agent/v1",
|
||||
},
|
||||
{
|
||||
name: "azure_openai",
|
||||
label: "Azure OpenAI",
|
||||
@ -739,6 +746,7 @@ describe("App layout", () => {
|
||||
fireEvent.click(within(settingsNav).getByRole("button", { name: "Providers" }));
|
||||
expect(screen.getByText("OpenRouter")).toBeInTheDocument();
|
||||
expect(screen.getByText("Ant Ling")).toBeInTheDocument();
|
||||
expect(screen.getByText("APIFree")).toBeInTheDocument();
|
||||
expect(screen.getAllByText("Not configured").length).toBeGreaterThan(0);
|
||||
fireEvent.click(screen.getByText("OpenAI"));
|
||||
fireEvent.click(screen.getByRole("button", { name: "Edit" }));
|
||||
@ -751,6 +759,8 @@ describe("App layout", () => {
|
||||
expect(screen.queryByDisplayValue("unsaved-openai-key")).not.toBeInTheDocument();
|
||||
fireEvent.click(screen.getByText("Ant Ling"));
|
||||
expect(screen.getByDisplayValue("https://api.ant-ling.com/v1")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByText("APIFree"));
|
||||
expect(screen.getByDisplayValue("https://api.apifree.ai/agent/v1")).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByText("Atomic Chat"));
|
||||
expect(screen.getByDisplayValue("http://localhost:1337/v1")).toBeInTheDocument();
|
||||
expect(screen.getByRole("button", { name: "Save" })).toBeEnabled();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user