mirror of
https://github.com/RYDE-WORK/Langchain-Chatchat.git
synced 2026-02-03 21:23:13 +08:00
一些兼容 pydantic<3,>=1.9.0 model_config 的代码,
This commit is contained in:
parent
d0267bf66b
commit
6dd00b5d94
@ -1,6 +1,7 @@
|
||||
from enum import Enum
|
||||
from typing import List, Literal, Optional
|
||||
|
||||
from ..._compat import PYDANTIC_V2, ConfigDict
|
||||
from ..._models import BaseModel
|
||||
|
||||
from model_providers.core.entities.model_entities import (
|
||||
@ -72,6 +73,13 @@ class ProviderResponse(BaseModel):
|
||||
preferred_provider_type: ProviderType
|
||||
custom_configuration: CustomConfigurationResponse
|
||||
system_configuration: SystemConfigurationResponse
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
def __init__(self, **data) -> None:
|
||||
super().__init__(**data)
|
||||
@ -171,6 +179,14 @@ class DefaultModelResponse(BaseModel):
|
||||
model_type: ModelType
|
||||
provider: SimpleProviderEntityResponse
|
||||
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
|
||||
class ModelWithProviderEntityResponse(ModelWithProviderEntity):
|
||||
"""
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
|
||||
from ..._compat import PYDANTIC_V2, ConfigDict
|
||||
from ..._models import BaseModel
|
||||
|
||||
from model_providers.core.model_runtime.entities.common_entities import I18nObject
|
||||
@ -77,3 +78,11 @@ class DefaultModelEntity(BaseModel):
|
||||
model: str
|
||||
model_type: ModelType
|
||||
provider: DefaultModelProviderEntity
|
||||
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
@ -4,6 +4,7 @@ import logging
|
||||
from json import JSONDecodeError
|
||||
from typing import Dict, Iterator, List, Optional
|
||||
|
||||
from ..._compat import PYDANTIC_V2, ConfigDict
|
||||
from ..._models import BaseModel
|
||||
|
||||
from model_providers.core.entities.model_entities import (
|
||||
@ -349,7 +350,13 @@ class ProviderModelBundle(BaseModel):
|
||||
provider_instance: ModelProvider
|
||||
model_type_instance: AIModel
|
||||
|
||||
class Config:
|
||||
"""Configuration for this pydantic object."""
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=(),
|
||||
arbitrary_types_allowed=True
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
arbitrary_types_allowed = True
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
|
||||
from ..._compat import PYDANTIC_V2, ConfigDict
|
||||
from ..._models import BaseModel
|
||||
|
||||
from model_providers.core.model_runtime.entities.model_entities import ModelType
|
||||
@ -57,6 +58,14 @@ class RestrictModel(BaseModel):
|
||||
base_model_name: Optional[str] = None
|
||||
model_type: ModelType
|
||||
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
|
||||
class QuotaConfiguration(BaseModel):
|
||||
"""
|
||||
@ -99,6 +108,14 @@ class CustomModelConfiguration(BaseModel):
|
||||
model_type: ModelType
|
||||
credentials: dict
|
||||
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
|
||||
class CustomConfiguration(BaseModel):
|
||||
"""
|
||||
|
||||
@ -2,6 +2,7 @@ from decimal import Decimal
|
||||
from enum import Enum
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from ...._compat import PYDANTIC_V2, ConfigDict
|
||||
from ...._models import BaseModel
|
||||
|
||||
from model_providers.core.model_runtime.entities.common_entities import I18nObject
|
||||
@ -162,9 +163,13 @@ class ProviderModel(BaseModel):
|
||||
fetch_from: FetchFrom
|
||||
model_properties: Dict[ModelPropertyKey, Any]
|
||||
deprecated: bool = False
|
||||
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
|
||||
class ParameterRule(BaseModel):
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
from enum import Enum
|
||||
from typing import List, Optional
|
||||
|
||||
from ...._compat import PYDANTIC_V2, ConfigDict
|
||||
from ...._models import BaseModel
|
||||
|
||||
from model_providers.core.model_runtime.entities.common_entities import I18nObject
|
||||
@ -134,8 +135,13 @@ class ProviderEntity(BaseModel):
|
||||
provider_credential_schema: Optional[ProviderCredentialSchema] = None
|
||||
model_credential_schema: Optional[ModelCredentialSchema] = None
|
||||
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
if PYDANTIC_V2:
|
||||
model_config = ConfigDict(
|
||||
protected_namespaces=()
|
||||
)
|
||||
else:
|
||||
class Config:
|
||||
protected_namespaces = ()
|
||||
|
||||
def to_simple_provider(self) -> SimpleProviderEntity:
|
||||
"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user