mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-10-31 12:45:41 +08:00
- 依赖 httpx[socks] 换为 httpx2[socks]>=2.15,移除 httpx-socks / python-socks 及其 mypy 覆盖 - backend/src、ab_sdk、e2e 与单元测试统一使用 httpx2(异常类与 httpx 不通用) - request_url 与 LLM 客户端工厂合并为 proxy_url(),SOCKS5 走 httpx2 原生代理(主机名由代理解析) - 保留 #1104 过期连接池替换:httpcore2 2.15.1 的 start_tls 失败路径仍会泄漏隧道 - 日志同时压低 httpx2 与 httpx(google-genai、mcp 仍依赖旧 httpx) - openai 3.35.1 / anthropic 1.15.0 / google-genai 2.31.0;结构化解析改用 chat.completions.parse - ab_sdk 升到 0.6.0,客户端类型改为 httpx2.AsyncClient,同步插件文档
1.7 KiB
1.7 KiB
LLM Provider (llm_provider)
Adds an LLM parsing provider. @provider(points.LLM_PROVIDER, id=...) returns a subclass of ab_sdk.llm.LLMProviderAdapter. The id must equal its info.id. The user selects it in Settings → LLM → Provider. You cannot override the id of a built-in provider.
from ab_sdk import Plugin, points, provider
from ab_sdk.llm import AdapterContext, LLMProviderAdapter, ProviderInfo
class MyAdapter(LLMProviderAdapter):
info = ProviderInfo(
id="my-llm",
display_name="My LLM",
auth_kind="api_key",
needs_base_url=True,
default_model="my-model",
)
... # implement parse / list_models and the other abstract methods
class MyPlugin(Plugin):
@provider(points.LLM_PROVIDER, id="my-llm")
def adapter(self):
return MyAdapter
Notes
ProviderInfodrives the frontend form and the provider list.auth_kindisapi_key,oauthordevice_code.- An adapter gets the model name, key,
base_url, timeout and a proxy-aware httpx2 client factory throughAdapterContext. It does not read the global configuration. - The factory returns an
httpx2.AsyncClient(since SDK 0.6; before, it washttpx). To catch network errors, usehttpx2.HTTPErrorand related classes. Thehttpxexception classes do not catch its errors. - A subscription-type provider (
oauth/device_code) implements the auth flow hooks (AuthChallenge,TokenSet). When the credentials are no longer valid and the refresh fails, raiseAuthExpiredError. AB then trips the breaker for this provider and sends anllm_auth_failureevent. - Existing LLM plugins in the
plugin.jsonformat (released asllm-plugins) still work. New plugins useplugin.tomland this extension point.