mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-23 03:19:38 +00:00
multiple: pydantic 2 compatibility, v0.3 (#26443)
Signed-off-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Dan O'Donovan <dan.odonovan@gmail.com> Co-authored-by: Tom Daniel Grande <tomdgrande@gmail.com> Co-authored-by: Grande <Tom.Daniel.Grande@statsbygg.no> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com> Co-authored-by: Tomaz Bratanic <bratanic.tomaz@gmail.com> Co-authored-by: ZhangShenao <15201440436@163.com> Co-authored-by: Friso H. Kingma <fhkingma@gmail.com> Co-authored-by: ChengZi <chen.zhang@zilliz.com> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Morgante Pell <morgantep@google.com>
This commit is contained in:
@@ -10,7 +10,12 @@ from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Union
|
||||
import aiohttp
|
||||
import requests
|
||||
from aiohttp import ClientTimeout, ServerTimeoutError
|
||||
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator, validator
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
ConfigDict,
|
||||
Field,
|
||||
model_validator,
|
||||
)
|
||||
from requests.exceptions import Timeout
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -40,17 +45,16 @@ class PowerBIDataset(BaseModel):
|
||||
schemas: Dict[str, str] = Field(default_factory=dict)
|
||||
aiosession: Optional[aiohttp.ClientSession] = None
|
||||
|
||||
class Config:
|
||||
arbitrary_types_allowed = True
|
||||
model_config = ConfigDict(
|
||||
arbitrary_types_allowed=True,
|
||||
)
|
||||
|
||||
@validator("table_names", allow_reuse=True)
|
||||
def fix_table_names(cls, table_names: List[str]) -> List[str]:
|
||||
"""Fix the table names."""
|
||||
return [fix_table_name(table) for table in table_names]
|
||||
|
||||
@root_validator(pre=True)
|
||||
def token_or_credential_present(cls, values: Dict[str, Any]) -> Dict[str, Any]:
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_params(cls, values: Dict[str, Any]) -> Any:
|
||||
"""Validate that at least one of token and credentials is present."""
|
||||
table_names = values.get("table_names", [])
|
||||
values["table_names"] = [fix_table_name(table) for table in table_names]
|
||||
if "token" in values or "credential" in values:
|
||||
return values
|
||||
raise ValueError("Please provide either a credential or a token.")
|
||||
|
Reference in New Issue
Block a user