fix: Provider.meta() error (#3647)

fixes: #3643
This commit is contained in:
Soulter
2025-11-15 18:01:51 +08:00
committed by Soulter
parent 08ec787491
commit 824af5eeea
3 changed files with 29 additions and 12 deletions

View File

@@ -30,21 +30,31 @@ class ProviderType(enum.Enum):
@dataclass
class ProviderMetaData:
class ProviderMeta:
"""The basic metadata of a provider instance."""
id: str
"""提供商适配器 ID"""
"""the unique id of the provider instance that user configured"""
model: str | None
"""the model name of the provider instance currently used"""
type: str
"""提供商适配器名称,如 openai, ollama"""
desc: str = ""
"""提供商适配器描述"""
"""the name of the provider adapter, such as openai, ollama"""
provider_type: ProviderType = ProviderType.CHAT_COMPLETION
"""提供商类型"""
"""the capability type of the provider adapter"""
@dataclass
class ProviderMetaData(ProviderMeta):
"""The metadata of a provider adapter for registration."""
desc: str = ""
"""the short description of the provider adapter"""
cls_type: Any = None
"""提供商适配器类类型"""
"""the class type of the provider adapter"""
default_config_tmpl: dict | None = None
"""平台的默认配置模板"""
"""the default configuration template of the provider adapter"""
provider_display_name: str | None = None
"""显示在 WebUI 配置页中的提供商名称,如空则是 type"""
"""the display name of the provider shown in the WebUI configuration page; if empty, the type is used"""
@dataclass

View File

@@ -7,7 +7,7 @@ from astrbot.core.agent.tool import ToolSet
from astrbot.core.db.po import Personality
from astrbot.core.provider.entities import (
LLMResponse,
ProviderMetaData,
ProviderMeta,
RerankResult,
ToolCallsResult,
)
@@ -30,13 +30,19 @@ class AbstractProvider(abc.ABC):
"""Get the current model name"""
return self.model_name
def meta(self) -> ProviderMetaData:
def meta(self) -> ProviderMeta:
"""Get the provider metadata"""
provider_type_name = self.provider_config["type"]
meta_data = provider_cls_map.get(provider_type_name)
if not meta_data:
raise ValueError(f"Provider type {provider_type_name} not registered")
return meta_data
meta = ProviderMeta(
id=self.provider_config.get("id", "default"),
model=self.get_model(),
type=provider_type_name,
provider_type=meta_data.provider_type,
)
return meta
class Provider(AbstractProvider):

View File

@@ -37,6 +37,7 @@ def register_provider_adapter(
pm = ProviderMetaData(
id="default", # will be replaced when instantiated
model=None,
type=provider_type_name,
desc=desc,
provider_type=provider_type,