+40









lyzno1
GitHub
-LAN-
GuanMu
Davide Delbianco
NeatGuyCoding
kenwoodjw
Yongtao Huang
Yongtao Huang
Qiang Lee
李强04
autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Asuka Minato
Matri Qi
huayaoyue6
Bowen Liang
znn
crazywoola
crazywoola
Copilot
yihong
Muke Wang
wangmuke
Wu Tianwei
quicksand
非法操作
zxhlyh
Eric Guo
Zhedong Cen
jiangbo721
github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
hjlarry
lxsummer
湛露先生
Guangdong Liu
QuantumGhost
Claude
Yessenia-d
huangzhuo1949
huangzhuo
17hz
Amy
Joel
Nite Knite
Yeuoly
Petrus Han
iamjoel
Kalo Chin
Ujjwal Maurya
Maries
5bbf685035
Signed-off-by: -LAN- <[email protected]> Signed-off-by: kenwoodjw <[email protected]> Signed-off-by: Yongtao Huang <[email protected]> Signed-off-by: yihong0618 <[email protected]> Signed-off-by: zhanluxianshen <[email protected]> Co-authored-by: -LAN- <[email protected]> Co-authored-by: GuanMu <[email protected]> Co-authored-by: Davide Delbianco <[email protected]> Co-authored-by: NeatGuyCoding <[email protected]> Co-authored-by: kenwoodjw <[email protected]> Co-authored-by: Yongtao Huang <[email protected]> Co-authored-by: Yongtao Huang <[email protected]> Co-authored-by: Qiang Lee <[email protected]> Co-authored-by: 李强04 <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Asuka Minato <[email protected]> Co-authored-by: Matri Qi <[email protected]> Co-authored-by: huayaoyue6 <[email protected]> Co-authored-by: Bowen Liang <[email protected]> Co-authored-by: znn <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: crazywoola <[email protected]> Co-authored-by: Copilot <[email protected]> Co-authored-by: yihong <[email protected]> Co-authored-by: Muke Wang <[email protected]> Co-authored-by: wangmuke <[email protected]> Co-authored-by: Wu Tianwei <[email protected]> Co-authored-by: quicksand <[email protected]> Co-authored-by: 非法操作 <[email protected]> Co-authored-by: zxhlyh <[email protected]> Co-authored-by: Eric Guo <[email protected]> Co-authored-by: Zhedong Cen <[email protected]> Co-authored-by: jiangbo721 <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: hjlarry <[email protected]> Co-authored-by: lxsummer <[email protected]> Co-authored-by: 湛露先生 <[email protected]> Co-authored-by: Guangdong Liu <[email protected]> Co-authored-by: QuantumGhost <[email protected]> Co-authored-by: Claude <[email protected]> Co-authored-by: Yessenia-d <[email protected]> Co-authored-by: huangzhuo1949 <[email protected]> Co-authored-by: huangzhuo <[email protected]> Co-authored-by: 17hz <[email protected]> Co-authored-by: Amy <[email protected]> Co-authored-by: Joel <[email protected]> Co-authored-by: Nite Knite <[email protected]> Co-authored-by: Yeuoly <[email protected]> Co-authored-by: Petrus Han <[email protected]> Co-authored-by: iamjoel <[email protected]> Co-authored-by: Kalo Chin <[email protected]> Co-authored-by: Ujjwal Maurya <[email protected]> Co-authored-by: Maries <[email protected]>
179 lines
5.2 KiB
Python
179 lines
5.2 KiB
Python
from enum import Enum
|
|
from typing import Optional
|
|
|
|
from pydantic import BaseModel, ConfigDict
|
|
|
|
from configs import dify_config
|
|
from core.entities.model_entities import (
|
|
ModelWithProviderEntity,
|
|
ProviderModelWithStatusEntity,
|
|
)
|
|
from core.entities.provider_entities import (
|
|
CredentialConfiguration,
|
|
CustomModelConfiguration,
|
|
ProviderQuotaType,
|
|
QuotaConfiguration,
|
|
)
|
|
from core.model_runtime.entities.common_entities import I18nObject
|
|
from core.model_runtime.entities.model_entities import ModelType
|
|
from core.model_runtime.entities.provider_entities import (
|
|
ConfigurateMethod,
|
|
ModelCredentialSchema,
|
|
ProviderCredentialSchema,
|
|
ProviderHelpEntity,
|
|
SimpleProviderEntity,
|
|
)
|
|
from models.provider import ProviderType
|
|
|
|
|
|
class CustomConfigurationStatus(Enum):
|
|
"""
|
|
Enum class for custom configuration status.
|
|
"""
|
|
|
|
ACTIVE = "active"
|
|
NO_CONFIGURE = "no-configure"
|
|
|
|
|
|
class CustomConfigurationResponse(BaseModel):
|
|
"""
|
|
Model class for provider custom configuration response.
|
|
"""
|
|
|
|
status: CustomConfigurationStatus
|
|
current_credential_id: Optional[str] = None
|
|
current_credential_name: Optional[str] = None
|
|
available_credentials: Optional[list[CredentialConfiguration]] = None
|
|
custom_models: Optional[list[CustomModelConfiguration]] = None
|
|
|
|
|
|
class SystemConfigurationResponse(BaseModel):
|
|
"""
|
|
Model class for provider system configuration response.
|
|
"""
|
|
|
|
enabled: bool
|
|
current_quota_type: Optional[ProviderQuotaType] = None
|
|
quota_configurations: list[QuotaConfiguration] = []
|
|
|
|
|
|
class ProviderResponse(BaseModel):
|
|
"""
|
|
Model class for provider response.
|
|
"""
|
|
|
|
tenant_id: str
|
|
provider: str
|
|
label: I18nObject
|
|
description: Optional[I18nObject] = None
|
|
icon_small: Optional[I18nObject] = None
|
|
icon_large: Optional[I18nObject] = None
|
|
background: Optional[str] = None
|
|
help: Optional[ProviderHelpEntity] = None
|
|
supported_model_types: list[ModelType]
|
|
configurate_methods: list[ConfigurateMethod]
|
|
provider_credential_schema: Optional[ProviderCredentialSchema] = None
|
|
model_credential_schema: Optional[ModelCredentialSchema] = None
|
|
preferred_provider_type: ProviderType
|
|
custom_configuration: CustomConfigurationResponse
|
|
system_configuration: SystemConfigurationResponse
|
|
|
|
# pydantic configs
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
def __init__(self, **data) -> None:
|
|
super().__init__(**data)
|
|
|
|
url_prefix = (
|
|
dify_config.CONSOLE_API_URL + f"/console/api/workspaces/{self.tenant_id}/model-providers/{self.provider}"
|
|
)
|
|
if self.icon_small is not None:
|
|
self.icon_small = I18nObject(
|
|
en_US=f"{url_prefix}/icon_small/en_US", zh_Hans=f"{url_prefix}/icon_small/zh_Hans"
|
|
)
|
|
|
|
if self.icon_large is not None:
|
|
self.icon_large = I18nObject(
|
|
en_US=f"{url_prefix}/icon_large/en_US", zh_Hans=f"{url_prefix}/icon_large/zh_Hans"
|
|
)
|
|
|
|
|
|
class ProviderWithModelsResponse(BaseModel):
|
|
"""
|
|
Model class for provider with models response.
|
|
"""
|
|
|
|
tenant_id: str
|
|
provider: str
|
|
label: I18nObject
|
|
icon_small: Optional[I18nObject] = None
|
|
icon_large: Optional[I18nObject] = None
|
|
status: CustomConfigurationStatus
|
|
models: list[ProviderModelWithStatusEntity]
|
|
|
|
def __init__(self, **data) -> None:
|
|
super().__init__(**data)
|
|
|
|
url_prefix = (
|
|
dify_config.CONSOLE_API_URL + f"/console/api/workspaces/{self.tenant_id}/model-providers/{self.provider}"
|
|
)
|
|
if self.icon_small is not None:
|
|
self.icon_small = I18nObject(
|
|
en_US=f"{url_prefix}/icon_small/en_US", zh_Hans=f"{url_prefix}/icon_small/zh_Hans"
|
|
)
|
|
|
|
if self.icon_large is not None:
|
|
self.icon_large = I18nObject(
|
|
en_US=f"{url_prefix}/icon_large/en_US", zh_Hans=f"{url_prefix}/icon_large/zh_Hans"
|
|
)
|
|
|
|
|
|
class SimpleProviderEntityResponse(SimpleProviderEntity):
|
|
"""
|
|
Simple provider entity response.
|
|
"""
|
|
|
|
tenant_id: str
|
|
|
|
def __init__(self, **data) -> None:
|
|
super().__init__(**data)
|
|
|
|
url_prefix = (
|
|
dify_config.CONSOLE_API_URL + f"/console/api/workspaces/{self.tenant_id}/model-providers/{self.provider}"
|
|
)
|
|
if self.icon_small is not None:
|
|
self.icon_small = I18nObject(
|
|
en_US=f"{url_prefix}/icon_small/en_US", zh_Hans=f"{url_prefix}/icon_small/zh_Hans"
|
|
)
|
|
|
|
if self.icon_large is not None:
|
|
self.icon_large = I18nObject(
|
|
en_US=f"{url_prefix}/icon_large/en_US", zh_Hans=f"{url_prefix}/icon_large/zh_Hans"
|
|
)
|
|
|
|
|
|
class DefaultModelResponse(BaseModel):
|
|
"""
|
|
Default model entity.
|
|
"""
|
|
|
|
model: str
|
|
model_type: ModelType
|
|
provider: SimpleProviderEntityResponse
|
|
|
|
# pydantic configs
|
|
model_config = ConfigDict(protected_namespaces=())
|
|
|
|
|
|
class ModelWithProviderEntityResponse(ProviderModelWithStatusEntity):
|
|
"""
|
|
Model with provider entity.
|
|
"""
|
|
|
|
provider: SimpleProviderEntityResponse
|
|
|
|
def __init__(self, tenant_id: str, model: ModelWithProviderEntity) -> None:
|
|
dump_model = model.model_dump()
|
|
dump_model["provider"]["tenant_id"] = tenant_id
|
|
super().__init__(**dump_model)
|