类class
agentscope.credentialCredentialFactory
class CredentialFactory
源码Source
agentscope/credential/_factory.py:20–120凭证工厂,与模型服务通信并返回生成或向量化结果。位于 agentscope.credential 包。核心成员包括 register_credential、from_dict、get_credential_class、list_schemas。
Built-in credential types are pre-registered. Call
:meth:register_credential to add custom types before starting the app.
Usage::
# Deserialize from storage
credential = CredentialFactory.from_dict(record.data)
# Register a custom type
CredentialFactory.register_credential(MyCredential)
# List schemas for the frontend form
schemas = CredentialFactory.list_schemas()
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
def register_credential(credential_cls: Type[CredentialBase]) -> None | 注册凭证。 Register a custom :class:`CredentialBase` subclass. |
def from_dict(data: dict) -> CredentialBase | 设置该参数。 Deserialize a credential dict (from storage) to a typed instance. |
def get_credential_class(provider: str) -> Type[CredentialBase] | None | 获取凭证类。 Return the credential class for the given provider type, or None. |
def list_schemas() -> list[dict] | 返回JSON 模式用于所有已注册凭证类型。 Return JSON schemas for all registered credential types. |
方法详情Method Detail
register_credential
def register_credential(credential_cls: Type[CredentialBase]) -> None
注册凭证。
The class must define a type field with a unique Literal default so Pydantic can use it as a discriminator.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
credential_cls | Type[CredentialBase] | 凭证 cls(类型 `Type[CredentialBase]`)。The subclass to register. |
None
无返回值。No value is returned.
源码Source
agentscope/credential/_factory.py:63–75from_dict
def from_dict(data: dict) -> CredentialBase
设置该参数。
Deserialize a credential dict (from storage) to a typed instance.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
data | dict | 数据(类型 `dict`)。Raw dict containing a `"type"` key. |
CredentialBase
返回CredentialBase。A typed :class:`CredentialBase` subclass instance.
源码Source
agentscope/credential/_factory.py:78–87get_credential_class
def get_credential_class(provider: str) -> Type[CredentialBase] | None
获取凭证类。
Return the credential class for the given provider type, or None.
参数Parameters
| 名称Name | 类型Type | 说明Description |
|---|---|---|
provider | str | 提供者(类型 `str`)。The `type` discriminator value (e.g. `"openai"`). |
Type[CredentialBase] | None
返回类型[CredentialBase]|None。The matching :class:`CredentialBase` subclass, or `None` if not
源码Source
agentscope/credential/_factory.py:90–112list_schemas
def list_schemas() -> list[dict]
返回JSON 模式用于所有已注册凭证类型。
Used by the frontend to render credential forms dynamically.
list[dict]
返回dict列表。Returns a list of dict.
源码Source
agentscope/credential/_factory.py:115–120