mirror of
https://github.com/hwchase17/langchain
synced 2024-11-06 03:20:49 +00:00
Create pydantic v1 namespace, add partial compatibility for pydantic v2 (#9123)
First of a few PRs to add full compatibility to both pydantic v1 and v2. This PR creates pydantic v1 namespace and adds it to sys.modules. Upcoming changes: 1. Handle `openapi-schema-pydantic = "^1.2"` and dependent chains/tools 2. bump dependencies to versions that are cross compatible for pydantic or remove them (see below) 3. Add tests to github workflows to test with pydantic v1 and v2 **Dependencies** From a quick look (could be wrong since was done manually) **dependencies pinning pydantic below 2** (some of these can be bumped to newer versions are provide cross-compatible code) anthropic bentoml confection fastapi langsmith octoai-sdk openapi-schema-pydantic qdrant-client spacy steamship thinc zep-python Unpinned marqo (*) nomic (*) xinference(*)
This commit is contained in:
parent
8189dea0d8
commit
c172f972ea
@ -1,8 +1,28 @@
|
||||
# ruff: noqa: E402
|
||||
"""Main entrypoint into package."""
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
from importlib import metadata
|
||||
from typing import Optional
|
||||
|
||||
## Create namespaces for pydantic v1 and v2.
|
||||
# This code must stay at the top of the file before other modules may
|
||||
# attempt to import pydantic since it adds pydantic_v1 and pydantic_v2 to sys.modules.
|
||||
#
|
||||
# This hack is done for the following reasons:
|
||||
# * Langchain will attempt to remain compatible with both pydantic v1 and v2 since
|
||||
# both dependencies and dependents may be stuck on either version of v1 or v2.
|
||||
# * Creating namespaces for pydantic v1 and v2 should allow us to write code that
|
||||
# unambiguously uses either v1 or v2 API.
|
||||
# * This change is easier to roll out and roll back.
|
||||
|
||||
try:
|
||||
pydantic_v1 = importlib.import_module("pydantic.v1")
|
||||
except ImportError:
|
||||
pydantic_v1 = importlib.import_module("pydantic")
|
||||
|
||||
sys.modules["pydantic_v1"] = pydantic_v1
|
||||
|
||||
from langchain.agents import MRKLChain, ReActChain, SelfAskWithSearchChain
|
||||
from langchain.cache import BaseCache
|
||||
from langchain.chains import (
|
||||
@ -67,6 +87,7 @@ llm_cache: Optional[BaseCache] = None
|
||||
# For backwards compatibility
|
||||
SerpAPIChain = SerpAPIWrapper
|
||||
|
||||
|
||||
__all__ = [
|
||||
"LLMChain",
|
||||
"LLMBashChain",
|
||||
|
@ -10,7 +10,7 @@ from pathlib import Path
|
||||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
import yaml
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
from langchain.agents.agent_iterator import AgentExecutorIterator
|
||||
from langchain.agents.agent_types import AgentType
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.tools import BaseTool
|
||||
|
@ -19,7 +19,7 @@ class AzureCognitiveServicesToolkit(BaseToolkit):
|
||||
def get_tools(self) -> List[BaseTool]:
|
||||
"""Get the tools in the toolkit."""
|
||||
|
||||
tools = [
|
||||
tools: List[BaseTool] = [
|
||||
AzureCogsFormRecognizerTool(),
|
||||
AzureCogsSpeech2TextTool(),
|
||||
AzureCogsText2SpeechTool(),
|
||||
|
@ -2,7 +2,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
from langchain.tools import BaseTool
|
||||
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import List, Optional
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.tools import BaseTool
|
||||
@ -15,7 +15,8 @@ from langchain.tools.file_management.read import ReadFileTool
|
||||
from langchain.tools.file_management.write import WriteFileTool
|
||||
|
||||
_FILE_TOOLS = {
|
||||
tool_cls.__fields__["name"].default: tool_cls
|
||||
# "Type[Runnable[Any, Any]]" has no attribute "__fields__" [attr-defined]
|
||||
tool_cls.__fields__["name"].default: tool_cls # type: ignore[attr-defined]
|
||||
for tool_cls in [
|
||||
CopyFileTool,
|
||||
DeleteFileTool,
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.tools import BaseTool
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, List, Optional, Sequence
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.agents.agent_toolkits.nla.tool import NLATool
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.tools import BaseTool
|
||||
|
@ -5,7 +5,7 @@ from functools import partial
|
||||
from typing import Any, Callable, Dict, List, Optional
|
||||
|
||||
import yaml
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import AgentExecutor
|
||||
from langchain.agents.agent_toolkits.openapi.planner_prompt import (
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, List, Optional, Type, cast
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.tools.base import BaseTool
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Toolkit for interacting with a Power BI dataset."""
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.callbacks.base import BaseCallbackManager
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Toolkit for interacting with Spark SQL."""
|
||||
from typing import List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Toolkit for interacting with an SQL database."""
|
||||
from typing import List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.schema.language_model import BaseLanguageModel
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Toolkit for interacting with a vector store."""
|
||||
from typing import List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.agents.agent_toolkits.base import BaseToolkit
|
||||
from langchain.llms.openai import OpenAI
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, List, Optional, Sequence, Tuple
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentOutputParser
|
||||
from langchain.agents.chat.output_parser import ChatOutputParser
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, List, Optional, Sequence
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentOutputParser
|
||||
from langchain.agents.agent_types import AgentType
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, List, Optional, Sequence, Tuple
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentOutputParser
|
||||
from langchain.agents.conversational_chat.output_parser import ConvoOutputParser
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, List, NamedTuple, Optional, Sequence
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
|
||||
from langchain.agents.agent_types import AgentType
|
||||
|
@ -4,7 +4,7 @@ from dataclasses import dataclass
|
||||
from json import JSONDecodeError
|
||||
from typing import Any, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.agents import BaseSingleActionAgent
|
||||
from langchain.callbacks.base import BaseCallbackManager
|
||||
|
@ -4,7 +4,7 @@ from dataclasses import dataclass
|
||||
from json import JSONDecodeError
|
||||
from typing import Any, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.agents import BaseMultiActionAgent
|
||||
from langchain.callbacks.base import BaseCallbackManager
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Chain that implements the ReAct paper from https://arxiv.org/pdf/2210.03629.pdf."""
|
||||
from typing import Any, List, Optional, Sequence
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
|
||||
from langchain.agents.agent_types import AgentType
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Chain that does self-ask with search."""
|
||||
from typing import Any, Sequence, Union
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
|
||||
from langchain.agents.agent_types import AgentType
|
||||
|
@ -1,7 +1,7 @@
|
||||
import re
|
||||
from typing import Any, List, Optional, Sequence, Tuple
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import Agent, AgentOutputParser
|
||||
from langchain.agents.structured_chat.output_parser import (
|
||||
|
@ -5,7 +5,7 @@ import logging
|
||||
import re
|
||||
from typing import Optional, Union
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.agents.agent import AgentOutputParser
|
||||
from langchain.agents.structured_chat.prompt import FORMAT_INSTRUCTIONS
|
||||
|
@ -8,7 +8,7 @@ from uuid import UUID
|
||||
|
||||
from langsmith.schemas import RunBase as BaseRunV2
|
||||
from langsmith.schemas import RunTypeEnum as RunTypeEnumDep
|
||||
from pydantic import BaseModel, Field, root_validator
|
||||
from pydantic_v1 import BaseModel, Field, root_validator
|
||||
|
||||
from langchain.schema import LLMResult
|
||||
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from typing import Any, Dict, List, NamedTuple, Optional, cast
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
from requests import Response
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun, Callbacks
|
||||
|
@ -10,7 +10,7 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Union
|
||||
|
||||
import yaml
|
||||
from pydantic import Field, root_validator, validator
|
||||
from pydantic_v1 import Field, root_validator, validator
|
||||
|
||||
import langchain
|
||||
from langchain.callbacks.base import BaseCallbackManager
|
||||
|
@ -3,7 +3,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import Callbacks
|
||||
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, cast
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import Callbacks
|
||||
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Callable, List, Optional, Protocol, Tuple
|
||||
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.callbacks.manager import Callbacks
|
||||
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Tuple
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import Callbacks
|
||||
from langchain.chains.combine_documents.base import (
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Any, Dict, List, Optional, Tuple
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import Callbacks
|
||||
from langchain.chains.combine_documents.base import (
|
||||
|
@ -1,5 +1,5 @@
|
||||
"""Models for the Constitutional AI chain."""
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
|
||||
class ConstitutionalPrinciple(BaseModel):
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Chain that carries on a conversation and calls an LLM."""
|
||||
from typing import Dict, List
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.chains.conversation.prompt import PROMPT
|
||||
from langchain.chains.llm import LLMChain
|
||||
|
@ -7,7 +7,7 @@ from abc import abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -5,7 +5,7 @@ from abc import abstractmethod
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple
|
||||
|
||||
import numpy as np
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
CallbackManagerForChainRun,
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
|
@ -5,7 +5,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -7,7 +7,7 @@ from __future__ import annotations
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import numpy as np
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
from pydantic import Extra, Field
|
||||
from pydantic_v1 import Extra, Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManager,
|
||||
|
@ -5,7 +5,7 @@ import logging
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -7,7 +7,7 @@ import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import numexpr
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains import LLMChain
|
||||
|
@ -6,7 +6,7 @@ import warnings
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import re
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.callbacks.manager import (
|
||||
|
@ -7,7 +7,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Mapping, Optional
|
||||
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun, Callbacks
|
||||
from langchain.chains import ReduceDocumentsChain
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Pass input through a moderation endpoint."""
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import warnings
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -12,7 +12,7 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
from langchain.base_language import BaseLanguageModel
|
||||
from langchain.chains import LLMChain
|
||||
@ -87,7 +87,9 @@ def _get_python_function_arguments(function: Callable, arg_descriptions: dict) -
|
||||
if arg == "return":
|
||||
continue
|
||||
if isinstance(arg_type, type) and issubclass(arg_type, BaseModel):
|
||||
properties[arg] = arg_type.schema()
|
||||
# Mypy error:
|
||||
# "type" has no attribute "schema"
|
||||
properties[arg] = arg_type.schema() # type: ignore[attr-defined]
|
||||
elif arg_type.__name__ in PYTHON_TO_JSON_TYPES:
|
||||
properties[arg] = {"type": PYTHON_TO_JSON_TYPES[arg_type.__name__]}
|
||||
if arg in arg_descriptions:
|
||||
@ -147,7 +149,9 @@ def convert_to_openai_function(
|
||||
if isinstance(function, dict):
|
||||
return function
|
||||
elif isinstance(function, type) and issubclass(function, BaseModel):
|
||||
schema = function.schema()
|
||||
# Mypy error:
|
||||
# "type" has no attribute "schema"
|
||||
schema = function.schema() # type: ignore[attr-defined]
|
||||
return {
|
||||
"name": schema["title"],
|
||||
"description": schema["description"],
|
||||
@ -224,7 +228,7 @@ def create_openai_fn_chain(
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
|
||||
class RecordPerson(BaseModel):
|
||||
@ -310,7 +314,7 @@ def create_structured_output_chain(
|
||||
from langchain.chat_models import ChatOpenAI
|
||||
from langchain.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
class Dog(BaseModel):
|
||||
\"\"\"Identifying information about a dog.\"\"\"
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Iterator, List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.chains.openai_functions.utils import get_llm_kwargs
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, List
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
from langchain.chains.base import Chain
|
||||
from langchain.chains.llm import LLMChain
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, List, Optional, Type, Union
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.chains.openai_functions.utils import get_llm_kwargs
|
||||
|
@ -1,7 +1,7 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Callable, List, Tuple
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.chat_models.base import BaseChatModel
|
||||
from langchain.llms.base import BaseLLM
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.base import Chain
|
||||
|
@ -7,7 +7,7 @@ import re
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -3,7 +3,7 @@
|
||||
import warnings
|
||||
from typing import Any, Dict, List
|
||||
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -5,7 +5,7 @@ from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
from typing import Any, List, Optional, Sequence, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
|
||||
class Visitor(ABC):
|
||||
|
@ -1,4 +1,4 @@
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
|
||||
class AttributeInfo(BaseModel):
|
||||
|
@ -6,7 +6,7 @@ import warnings
|
||||
from abc import abstractmethod
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, Field, root_validator
|
||||
from pydantic_v1 import Extra, Field, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
from abc import ABC
|
||||
from typing import Any, Dict, List, Mapping, NamedTuple, Optional
|
||||
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional, Sequence, Tuple, Type
|
||||
|
||||
from pydantic import Extra
|
||||
from pydantic_v1 import Extra
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForChainRun
|
||||
from langchain.chains.router.base import RouterChain
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
|
||||
from typing import Any, Dict, List, Optional, Type, cast
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Chain pipeline where the outputs of one step feed directly into next."""
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import Extra, root_validator
|
||||
from pydantic_v1 import Extra, root_validator
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -3,7 +3,7 @@ import functools
|
||||
import logging
|
||||
from typing import Any, Awaitable, Callable, Dict, List, Optional
|
||||
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForChainRun,
|
||||
|
@ -7,7 +7,7 @@ import sys
|
||||
from typing import TYPE_CHECKING, Optional, Set
|
||||
|
||||
import requests
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
|
||||
from langchain.adapters.openai import convert_message_to_dict
|
||||
from langchain.chat_models.openai import (
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import Any, Dict, Mapping
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.chat_models.openai import ChatOpenAI
|
||||
from langchain.schema import ChatResult
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import validator
|
||||
from pydantic_v1 import validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
||||
from langchain.chat_models.base import SimpleChatModel
|
||||
|
@ -14,7 +14,7 @@ from typing import (
|
||||
cast,
|
||||
)
|
||||
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
|
||||
import langchain
|
||||
from langchain.callbacks.base import BaseCallbackManager
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional
|
||||
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
from tenacity import (
|
||||
before_sleep_log,
|
||||
retry,
|
||||
|
@ -5,7 +5,7 @@ from io import StringIO
|
||||
from typing import Any, Callable, Dict, List, Mapping, Optional
|
||||
|
||||
import yaml
|
||||
from pydantic import Field
|
||||
from pydantic_v1 import Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForLLMRun,
|
||||
|
@ -15,7 +15,7 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
from tenacity import (
|
||||
before_sleep_log,
|
||||
retry,
|
||||
|
@ -3,7 +3,7 @@ import logging
|
||||
from functools import partial
|
||||
from typing import Any, Dict, List, Mapping, Optional
|
||||
|
||||
from pydantic import BaseModel, Extra
|
||||
from pydantic_v1 import BaseModel, Extra
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForLLMRun,
|
||||
@ -26,7 +26,9 @@ from langchain.schema.messages import (
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ChatParams(BaseModel, extra=Extra.allow):
|
||||
# Ignoring type because below is valid pydantic code
|
||||
# Unexpected keyword argument "extra" for "__init_subclass__" of "object" [call-arg]
|
||||
class ChatParams(BaseModel, extra=Extra.allow): # type: ignore[call-arg]
|
||||
"""Parameters for the MLflow AI Gateway LLM."""
|
||||
|
||||
temperature: float = 0.0
|
||||
|
@ -17,7 +17,7 @@ from typing import (
|
||||
Union,
|
||||
)
|
||||
|
||||
from pydantic import Field, root_validator
|
||||
from pydantic_v1 import Field, root_validator
|
||||
|
||||
from langchain.adapters.openai import convert_dict_to_message, convert_message_to_dict
|
||||
from langchain.callbacks.manager import (
|
||||
|
@ -2,7 +2,7 @@
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic_v1 import root_validator
|
||||
|
||||
from langchain.callbacks.manager import CallbackManagerForLLMRun
|
||||
from langchain.chat_models.base import BaseChatModel
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, Callable, Dict, List
|
||||
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -13,7 +13,7 @@ from io import BufferedReader, BytesIO
|
||||
from pathlib import PurePath
|
||||
from typing import Any, Generator, Iterable, Mapping, Optional, Union
|
||||
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
PathLike = Union[str, PurePath]
|
||||
|
||||
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List, Mapping, Optional, Sequence, Union
|
||||
|
||||
import requests
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -11,7 +11,7 @@ import tempfile
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -3,7 +3,7 @@ import warnings
|
||||
from typing import Any, Dict, Iterator, List, Optional
|
||||
|
||||
import requests
|
||||
from pydantic import BaseModel, root_validator, validator
|
||||
from pydantic_v1 import BaseModel, root_validator, validator
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
|
@ -3,7 +3,7 @@ from datetime import datetime
|
||||
from typing import Dict, Iterator, List, Literal, Optional, Union
|
||||
|
||||
import requests
|
||||
from pydantic import BaseModel, root_validator, validator
|
||||
from pydantic_v1 import BaseModel, root_validator, validator
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -11,7 +11,7 @@ import os
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
||||
|
||||
from pydantic import BaseModel, root_validator, validator
|
||||
from pydantic_v1 import BaseModel, root_validator, validator
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -8,7 +8,7 @@ from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Dict, List, Optional, Type, Union
|
||||
|
||||
from pydantic import BaseModel, BaseSettings, Field, FilePath, SecretStr
|
||||
from pydantic_v1 import BaseModel, BaseSettings, Field, FilePath, SecretStr
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -3,7 +3,7 @@ from __future__ import annotations
|
||||
import tempfile
|
||||
from typing import TYPE_CHECKING, List
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -6,8 +6,8 @@ from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional, Sequence, Union
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
from pydantic import root_validator
|
||||
from pydantic.dataclasses import dataclass
|
||||
from pydantic_v1 import root_validator
|
||||
from pydantic_v1.dataclasses import dataclass
|
||||
|
||||
from langchain.docstore.document import Document
|
||||
from langchain.document_loaders.base import BaseLoader
|
||||
|
@ -2,7 +2,7 @@
|
||||
from typing import Any, Callable, List, Sequence
|
||||
|
||||
import numpy as np
|
||||
from pydantic import BaseModel, Field
|
||||
from pydantic_v1 import BaseModel, Field
|
||||
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from langchain.schema import BaseDocumentTransformer, Document
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Reorder documents"""
|
||||
from typing import Any, List, Sequence
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
from langchain.schema import BaseDocumentTransformer, Document
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
"""Document transformers that use OpenAI Functions models"""
|
||||
from typing import Any, Dict, Optional, Sequence, Type, Union
|
||||
|
||||
from pydantic import BaseModel
|
||||
from pydantic_v1 import BaseModel
|
||||
|
||||
from langchain.chains.llm import LLMChain
|
||||
from langchain.chains.openai_functions import create_tagging_chain
|
||||
|
@ -1,6 +1,6 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import BaseModel, root_validator
|
||||
from pydantic_v1 import BaseModel, root_validator
|
||||
|
||||
from langchain.embeddings.base import Embeddings
|
||||
from langchain.utils import get_from_dict_or_env
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user