mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-27 06:18:05 +00:00
exa[major]: use pydantic v2 (#26069)
This commit is contained in:
@@ -1,18 +1,14 @@
|
|||||||
from typing import ( # type: ignore[import-not-found, import-not-found]
|
from typing import Any, Dict, List, Literal, Optional, Union
|
||||||
Any,
|
|
||||||
Dict,
|
|
||||||
List,
|
|
||||||
Literal,
|
|
||||||
Optional,
|
|
||||||
Union,
|
|
||||||
)
|
|
||||||
|
|
||||||
from exa_py import Exa # type: ignore
|
from exa_py import Exa # type: ignore[untyped-import]
|
||||||
from exa_py.api import HighlightsContentsOptions, TextContentsOptions # type: ignore
|
from exa_py.api import (
|
||||||
|
HighlightsContentsOptions, # type: ignore[untyped-import]
|
||||||
|
TextContentsOptions, # type: ignore[untyped-import]
|
||||||
|
)
|
||||||
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
from langchain_core.callbacks import CallbackManagerForRetrieverRun
|
||||||
from langchain_core.documents import Document
|
from langchain_core.documents import Document
|
||||||
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
|
||||||
from langchain_core.retrievers import BaseRetriever
|
from langchain_core.retrievers import BaseRetriever
|
||||||
|
from pydantic import Field, SecretStr, model_validator
|
||||||
|
|
||||||
from langchain_exa._utilities import initialize_client
|
from langchain_exa._utilities import initialize_client
|
||||||
|
|
||||||
@@ -64,8 +60,9 @@ class ExaSearchRetriever(BaseRetriever):
|
|||||||
exa_api_key: SecretStr = Field(default=None)
|
exa_api_key: SecretStr = Field(default=None)
|
||||||
exa_base_url: Optional[str] = None
|
exa_base_url: Optional[str] = None
|
||||||
|
|
||||||
@root_validator(pre=True)
|
@model_validator(mode="before")
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
@classmethod
|
||||||
|
def validate_environment(cls, values: Dict) -> Any:
|
||||||
"""Validate the environment."""
|
"""Validate the environment."""
|
||||||
values = initialize_client(values)
|
values = initialize_client(values)
|
||||||
return values
|
return values
|
||||||
|
@@ -1,14 +1,17 @@
|
|||||||
"""Tool for the Exa Search API.""" # type: ignore[import-not-found, import-not-found]
|
"""Tool for the Exa Search API."""
|
||||||
|
|
||||||
from typing import Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
|
||||||
from exa_py import Exa # type: ignore
|
from exa_py import Exa # type: ignore[untyped-import]
|
||||||
from exa_py.api import HighlightsContentsOptions, TextContentsOptions # type: ignore
|
from exa_py.api import (
|
||||||
|
HighlightsContentsOptions, # type: ignore[untyped-import]
|
||||||
|
TextContentsOptions, # type: ignore[untyped-import]
|
||||||
|
)
|
||||||
from langchain_core.callbacks import (
|
from langchain_core.callbacks import (
|
||||||
CallbackManagerForToolRun,
|
CallbackManagerForToolRun,
|
||||||
)
|
)
|
||||||
from langchain_core.pydantic_v1 import Field, SecretStr, root_validator
|
|
||||||
from langchain_core.tools import BaseTool
|
from langchain_core.tools import BaseTool
|
||||||
|
from pydantic import Field, SecretStr, model_validator
|
||||||
|
|
||||||
from langchain_exa._utilities import initialize_client
|
from langchain_exa._utilities import initialize_client
|
||||||
|
|
||||||
@@ -61,8 +64,9 @@ class ExaSearchResults(BaseTool):
|
|||||||
client: Exa = Field(default=None)
|
client: Exa = Field(default=None)
|
||||||
exa_api_key: SecretStr = Field(default=None)
|
exa_api_key: SecretStr = Field(default=None)
|
||||||
|
|
||||||
@root_validator(pre=True)
|
@model_validator(mode="before")
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
@classmethod
|
||||||
|
def validate_environment(cls, values: Dict) -> Any:
|
||||||
"""Validate the environment."""
|
"""Validate the environment."""
|
||||||
values = initialize_client(values)
|
values = initialize_client(values)
|
||||||
return values
|
return values
|
||||||
@@ -114,8 +118,9 @@ class ExaFindSimilarResults(BaseTool):
|
|||||||
exa_api_key: SecretStr = Field(default=None)
|
exa_api_key: SecretStr = Field(default=None)
|
||||||
exa_base_url: Optional[str] = None
|
exa_base_url: Optional[str] = None
|
||||||
|
|
||||||
@root_validator(pre=True)
|
@model_validator(mode="before")
|
||||||
def validate_environment(cls, values: Dict) -> Dict:
|
@classmethod
|
||||||
|
def validate_environment(cls, values: Dict) -> Any:
|
||||||
"""Validate the environment."""
|
"""Validate the environment."""
|
||||||
values = initialize_client(values)
|
values = initialize_client(values)
|
||||||
return values
|
return values
|
||||||
|
Reference in New Issue
Block a user