langchain 0.2.16__py3-none-any.whl → 0.3.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of langchain might be problematic. Click here for more details.
- langchain/agents/agent.py +21 -17
- langchain/agents/agent_toolkits/vectorstore/toolkit.py +10 -7
- langchain/agents/chat/base.py +1 -1
- langchain/agents/conversational/base.py +1 -1
- langchain/agents/conversational_chat/base.py +1 -1
- langchain/agents/mrkl/base.py +1 -1
- langchain/agents/openai_assistant/base.py +8 -7
- langchain/agents/openai_functions_agent/base.py +6 -5
- langchain/agents/openai_functions_multi_agent/base.py +6 -5
- langchain/agents/react/base.py +1 -1
- langchain/agents/self_ask_with_search/base.py +1 -1
- langchain/agents/structured_chat/base.py +1 -1
- langchain/agents/structured_chat/output_parser.py +1 -1
- langchain/chains/api/base.py +13 -11
- langchain/chains/base.py +13 -5
- langchain/chains/combine_documents/base.py +1 -1
- langchain/chains/combine_documents/map_reduce.py +14 -10
- langchain/chains/combine_documents/map_rerank.py +17 -14
- langchain/chains/combine_documents/reduce.py +5 -3
- langchain/chains/combine_documents/refine.py +11 -8
- langchain/chains/combine_documents/stuff.py +8 -6
- langchain/chains/constitutional_ai/models.py +1 -1
- langchain/chains/conversation/base.py +13 -11
- langchain/chains/conversational_retrieval/base.py +9 -7
- langchain/chains/elasticsearch_database/base.py +10 -8
- langchain/chains/flare/base.py +1 -1
- langchain/chains/hyde/base.py +5 -3
- langchain/chains/llm.py +5 -4
- langchain/chains/llm_checker/base.py +8 -6
- langchain/chains/llm_math/base.py +8 -6
- langchain/chains/llm_summarization_checker/base.py +8 -6
- langchain/chains/mapreduce.py +5 -3
- langchain/chains/moderation.py +4 -3
- langchain/chains/natbot/base.py +8 -6
- langchain/chains/openai_functions/base.py +1 -1
- langchain/chains/openai_functions/citation_fuzzy_match.py +1 -1
- langchain/chains/openai_functions/extraction.py +1 -1
- langchain/chains/openai_functions/qa_with_structure.py +1 -1
- langchain/chains/openai_tools/extraction.py +1 -1
- langchain/chains/prompt_selector.py +1 -1
- langchain/chains/qa_generation/base.py +1 -1
- langchain/chains/qa_with_sources/base.py +8 -6
- langchain/chains/qa_with_sources/retrieval.py +1 -1
- langchain/chains/qa_with_sources/vector_db.py +4 -3
- langchain/chains/query_constructor/schema.py +5 -4
- langchain/chains/retrieval_qa/base.py +12 -9
- langchain/chains/router/base.py +5 -3
- langchain/chains/router/embedding_router.py +5 -3
- langchain/chains/router/llm_router.py +6 -5
- langchain/chains/sequential.py +17 -13
- langchain/chains/structured_output/base.py +1 -1
- langchain/chains/transform.py +1 -1
- langchain/chat_models/base.py +1 -1
- langchain/evaluation/agents/trajectory_eval_chain.py +4 -3
- langchain/evaluation/comparison/eval_chain.py +4 -3
- langchain/evaluation/criteria/eval_chain.py +4 -3
- langchain/evaluation/embedding_distance/base.py +4 -3
- langchain/evaluation/qa/eval_chain.py +7 -4
- langchain/evaluation/qa/generate_chain.py +1 -1
- langchain/evaluation/scoring/eval_chain.py +4 -3
- langchain/evaluation/string_distance/base.py +1 -1
- langchain/indexes/vectorstore.py +9 -7
- langchain/memory/chat_memory.py +1 -1
- langchain/memory/combined.py +1 -1
- langchain/memory/entity.py +4 -3
- langchain/memory/summary.py +1 -1
- langchain/memory/vectorstore.py +1 -1
- langchain/memory/vectorstore_token_buffer_memory.py +1 -1
- langchain/output_parsers/fix.py +3 -2
- langchain/output_parsers/pandas_dataframe.py +1 -1
- langchain/output_parsers/retry.py +4 -3
- langchain/output_parsers/structured.py +1 -1
- langchain/output_parsers/yaml.py +1 -1
- langchain/retrievers/contextual_compression.py +4 -2
- langchain/retrievers/document_compressors/base.py +4 -2
- langchain/retrievers/document_compressors/chain_extract.py +4 -2
- langchain/retrievers/document_compressors/chain_filter.py +4 -2
- langchain/retrievers/document_compressors/cohere_rerank.py +8 -6
- langchain/retrievers/document_compressors/cross_encoder_rerank.py +5 -3
- langchain/retrievers/document_compressors/embeddings_filter.py +4 -3
- langchain/retrievers/document_compressors/listwise_rerank.py +4 -3
- langchain/retrievers/ensemble.py +4 -3
- langchain/retrievers/multi_vector.py +5 -4
- langchain/retrievers/self_query/base.py +8 -6
- langchain/retrievers/time_weighted_retriever.py +4 -3
- langchain/smith/evaluation/config.py +7 -5
- {langchain-0.2.16.dist-info → langchain-0.3.0.dev1.dist-info}/METADATA +4 -4
- {langchain-0.2.16.dist-info → langchain-0.3.0.dev1.dist-info}/RECORD +91 -91
- {langchain-0.2.16.dist-info → langchain-0.3.0.dev1.dist-info}/LICENSE +0 -0
- {langchain-0.2.16.dist-info → langchain-0.3.0.dev1.dist-info}/WHEEL +0 -0
- {langchain-0.2.16.dist-info → langchain-0.3.0.dev1.dist-info}/entry_points.txt +0 -0
|
@@ -8,8 +8,8 @@ from langchain_core.documents import Document
|
|
|
8
8
|
from langchain_core.language_models import LanguageModelLike
|
|
9
9
|
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
|
|
10
10
|
from langchain_core.prompts import BasePromptTemplate, format_document
|
|
11
|
-
from langchain_core.pydantic_v1 import Field, root_validator
|
|
12
11
|
from langchain_core.runnables import Runnable, RunnablePassthrough
|
|
12
|
+
from pydantic import ConfigDict, Field, model_validator
|
|
13
13
|
|
|
14
14
|
from langchain.chains.combine_documents.base import (
|
|
15
15
|
DEFAULT_DOCUMENT_PROMPT,
|
|
@@ -156,12 +156,14 @@ class StuffDocumentsChain(BaseCombineDocumentsChain):
|
|
|
156
156
|
document_separator: str = "\n\n"
|
|
157
157
|
"""The string with which to join the formatted documents"""
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
arbitrary_types_allowed
|
|
161
|
-
extra
|
|
159
|
+
model_config = ConfigDict(
|
|
160
|
+
arbitrary_types_allowed=True,
|
|
161
|
+
extra="forbid",
|
|
162
|
+
)
|
|
162
163
|
|
|
163
|
-
@
|
|
164
|
-
|
|
164
|
+
@model_validator(mode="before")
|
|
165
|
+
@classmethod
|
|
166
|
+
def get_default_document_variable_name(cls, values: Dict) -> Any:
|
|
165
167
|
"""Get default document variable name, if not provided.
|
|
166
168
|
|
|
167
169
|
If only one variable is present in the llm_chain.prompt,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"""Chain that carries on a conversation and calls an LLM."""
|
|
2
2
|
|
|
3
|
-
from typing import
|
|
3
|
+
from typing import List
|
|
4
4
|
|
|
5
5
|
from langchain_core._api import deprecated
|
|
6
6
|
from langchain_core.memory import BaseMemory
|
|
7
7
|
from langchain_core.prompts import BasePromptTemplate
|
|
8
|
-
from
|
|
8
|
+
from pydantic import ConfigDict, Field, model_validator
|
|
9
|
+
from typing_extensions import Self
|
|
9
10
|
|
|
10
11
|
from langchain.chains.conversation.prompt import PROMPT
|
|
11
12
|
from langchain.chains.llm import LLMChain
|
|
@@ -110,9 +111,10 @@ class ConversationChain(LLMChain):
|
|
|
110
111
|
input_key: str = "input" #: :meta private:
|
|
111
112
|
output_key: str = "response" #: :meta private:
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
arbitrary_types_allowed
|
|
115
|
-
extra
|
|
114
|
+
model_config = ConfigDict(
|
|
115
|
+
arbitrary_types_allowed=True,
|
|
116
|
+
extra="forbid",
|
|
117
|
+
)
|
|
116
118
|
|
|
117
119
|
@classmethod
|
|
118
120
|
def is_lc_serializable(cls) -> bool:
|
|
@@ -123,17 +125,17 @@ class ConversationChain(LLMChain):
|
|
|
123
125
|
"""Use this since so some prompt vars come from history."""
|
|
124
126
|
return [self.input_key]
|
|
125
127
|
|
|
126
|
-
@
|
|
127
|
-
def validate_prompt_input_variables(
|
|
128
|
+
@model_validator(mode="after")
|
|
129
|
+
def validate_prompt_input_variables(self) -> Self:
|
|
128
130
|
"""Validate that prompt input variables are consistent."""
|
|
129
|
-
memory_keys =
|
|
130
|
-
input_key =
|
|
131
|
+
memory_keys = self.memory.memory_variables
|
|
132
|
+
input_key = self.input_key
|
|
131
133
|
if input_key in memory_keys:
|
|
132
134
|
raise ValueError(
|
|
133
135
|
f"The input key {input_key} was also found in the memory keys "
|
|
134
136
|
f"({memory_keys}) - please provide keys that don't overlap."
|
|
135
137
|
)
|
|
136
|
-
prompt_variables =
|
|
138
|
+
prompt_variables = self.prompt.input_variables
|
|
137
139
|
expected_keys = memory_keys + [input_key]
|
|
138
140
|
if set(expected_keys) != set(prompt_variables):
|
|
139
141
|
raise ValueError(
|
|
@@ -141,4 +143,4 @@ class ConversationChain(LLMChain):
|
|
|
141
143
|
f"{prompt_variables}, but got {memory_keys} as inputs from "
|
|
142
144
|
f"memory, and {input_key} as the normal input key."
|
|
143
145
|
)
|
|
144
|
-
return
|
|
146
|
+
return self
|
|
@@ -18,10 +18,10 @@ from langchain_core.documents import Document
|
|
|
18
18
|
from langchain_core.language_models import BaseLanguageModel
|
|
19
19
|
from langchain_core.messages import BaseMessage
|
|
20
20
|
from langchain_core.prompts import BasePromptTemplate
|
|
21
|
-
from langchain_core.pydantic_v1 import BaseModel, Field, root_validator
|
|
22
21
|
from langchain_core.retrievers import BaseRetriever
|
|
23
22
|
from langchain_core.runnables import RunnableConfig
|
|
24
23
|
from langchain_core.vectorstores import VectorStore
|
|
24
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
25
25
|
|
|
26
26
|
from langchain.chains.base import Chain
|
|
27
27
|
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
|
|
@@ -96,10 +96,11 @@ class BaseConversationalRetrievalChain(Chain):
|
|
|
96
96
|
"""If specified, the chain will return a fixed response if no docs
|
|
97
97
|
are found for the question. """
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
arbitrary_types_allowed
|
|
102
|
-
extra
|
|
99
|
+
model_config = ConfigDict(
|
|
100
|
+
populate_by_name=True,
|
|
101
|
+
arbitrary_types_allowed=True,
|
|
102
|
+
extra="forbid",
|
|
103
|
+
)
|
|
103
104
|
|
|
104
105
|
@property
|
|
105
106
|
def input_keys(self) -> List[str]:
|
|
@@ -482,8 +483,9 @@ class ChatVectorDBChain(BaseConversationalRetrievalChain):
|
|
|
482
483
|
def _chain_type(self) -> str:
|
|
483
484
|
return "chat-vector-db"
|
|
484
485
|
|
|
485
|
-
@
|
|
486
|
-
|
|
486
|
+
@model_validator(mode="before")
|
|
487
|
+
@classmethod
|
|
488
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
487
489
|
warnings.warn(
|
|
488
490
|
"`ChatVectorDBChain` is deprecated - "
|
|
489
491
|
"please use `from langchain.chains import ConversationalRetrievalChain`"
|
|
@@ -9,8 +9,9 @@ from langchain_core.language_models import BaseLanguageModel
|
|
|
9
9
|
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
|
|
10
10
|
from langchain_core.output_parsers.json import SimpleJsonOutputParser
|
|
11
11
|
from langchain_core.prompts import BasePromptTemplate
|
|
12
|
-
from langchain_core.pydantic_v1 import root_validator
|
|
13
12
|
from langchain_core.runnables import Runnable
|
|
13
|
+
from pydantic import ConfigDict, model_validator
|
|
14
|
+
from typing_extensions import Self
|
|
14
15
|
|
|
15
16
|
from langchain.chains.base import Chain
|
|
16
17
|
from langchain.chains.elasticsearch_database.prompts import ANSWER_PROMPT, DSL_PROMPT
|
|
@@ -51,17 +52,18 @@ class ElasticsearchDatabaseChain(Chain):
|
|
|
51
52
|
return_intermediate_steps: bool = False
|
|
52
53
|
"""Whether or not to return the intermediate steps along with the final answer."""
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
arbitrary_types_allowed
|
|
56
|
-
extra
|
|
55
|
+
model_config = ConfigDict(
|
|
56
|
+
arbitrary_types_allowed=True,
|
|
57
|
+
extra="forbid",
|
|
58
|
+
)
|
|
57
59
|
|
|
58
|
-
@
|
|
59
|
-
def validate_indices(
|
|
60
|
-
if
|
|
60
|
+
@model_validator(mode="after")
|
|
61
|
+
def validate_indices(self) -> Self:
|
|
62
|
+
if self.include_indices and self.ignore_indices:
|
|
61
63
|
raise ValueError(
|
|
62
64
|
"Cannot specify both 'include_indices' and 'ignore_indices'."
|
|
63
65
|
)
|
|
64
|
-
return
|
|
66
|
+
return self
|
|
65
67
|
|
|
66
68
|
@property
|
|
67
69
|
def input_keys(self) -> List[str]:
|
langchain/chains/flare/base.py
CHANGED
|
@@ -11,9 +11,9 @@ from langchain_core.language_models import BaseLanguageModel
|
|
|
11
11
|
from langchain_core.messages import AIMessage
|
|
12
12
|
from langchain_core.output_parsers import StrOutputParser
|
|
13
13
|
from langchain_core.prompts import BasePromptTemplate
|
|
14
|
-
from langchain_core.pydantic_v1 import Field
|
|
15
14
|
from langchain_core.retrievers import BaseRetriever
|
|
16
15
|
from langchain_core.runnables import Runnable
|
|
16
|
+
from pydantic import Field
|
|
17
17
|
|
|
18
18
|
from langchain.chains.base import Chain
|
|
19
19
|
from langchain.chains.flare.prompts import (
|
langchain/chains/hyde/base.py
CHANGED
|
@@ -14,6 +14,7 @@ from langchain_core.language_models import BaseLanguageModel
|
|
|
14
14
|
from langchain_core.output_parsers import StrOutputParser
|
|
15
15
|
from langchain_core.prompts import BasePromptTemplate
|
|
16
16
|
from langchain_core.runnables import Runnable
|
|
17
|
+
from pydantic import ConfigDict
|
|
17
18
|
|
|
18
19
|
from langchain.chains.base import Chain
|
|
19
20
|
from langchain.chains.hyde.prompts import PROMPT_MAP
|
|
@@ -29,9 +30,10 @@ class HypotheticalDocumentEmbedder(Chain, Embeddings):
|
|
|
29
30
|
base_embeddings: Embeddings
|
|
30
31
|
llm_chain: Runnable
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
arbitrary_types_allowed
|
|
34
|
-
extra
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
arbitrary_types_allowed=True,
|
|
35
|
+
extra="forbid",
|
|
36
|
+
)
|
|
35
37
|
|
|
36
38
|
@property
|
|
37
39
|
def input_keys(self) -> List[str]:
|
langchain/chains/llm.py
CHANGED
|
@@ -23,7 +23,6 @@ from langchain_core.output_parsers import BaseLLMOutputParser, StrOutputParser
|
|
|
23
23
|
from langchain_core.outputs import ChatGeneration, Generation, LLMResult
|
|
24
24
|
from langchain_core.prompt_values import PromptValue
|
|
25
25
|
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
|
|
26
|
-
from langchain_core.pydantic_v1 import Field
|
|
27
26
|
from langchain_core.runnables import (
|
|
28
27
|
Runnable,
|
|
29
28
|
RunnableBinding,
|
|
@@ -32,6 +31,7 @@ from langchain_core.runnables import (
|
|
|
32
31
|
)
|
|
33
32
|
from langchain_core.runnables.configurable import DynamicRunnable
|
|
34
33
|
from langchain_core.utils.input import get_colored_text
|
|
34
|
+
from pydantic import ConfigDict, Field
|
|
35
35
|
|
|
36
36
|
from langchain.chains.base import Chain
|
|
37
37
|
|
|
@@ -95,9 +95,10 @@ class LLMChain(Chain):
|
|
|
95
95
|
If false, will return a bunch of extra information about the generation."""
|
|
96
96
|
llm_kwargs: dict = Field(default_factory=dict)
|
|
97
97
|
|
|
98
|
-
|
|
99
|
-
arbitrary_types_allowed
|
|
100
|
-
extra
|
|
98
|
+
model_config = ConfigDict(
|
|
99
|
+
arbitrary_types_allowed=True,
|
|
100
|
+
extra="forbid",
|
|
101
|
+
)
|
|
101
102
|
|
|
102
103
|
@property
|
|
103
104
|
def input_keys(self) -> List[str]:
|
|
@@ -9,7 +9,7 @@ from langchain_core._api import deprecated
|
|
|
9
9
|
from langchain_core.callbacks import CallbackManagerForChainRun
|
|
10
10
|
from langchain_core.language_models import BaseLanguageModel
|
|
11
11
|
from langchain_core.prompts import PromptTemplate
|
|
12
|
-
from
|
|
12
|
+
from pydantic import ConfigDict, model_validator
|
|
13
13
|
|
|
14
14
|
from langchain.chains.base import Chain
|
|
15
15
|
from langchain.chains.llm import LLMChain
|
|
@@ -100,12 +100,14 @@ class LLMCheckerChain(Chain):
|
|
|
100
100
|
input_key: str = "query" #: :meta private:
|
|
101
101
|
output_key: str = "result" #: :meta private:
|
|
102
102
|
|
|
103
|
-
|
|
104
|
-
arbitrary_types_allowed
|
|
105
|
-
extra
|
|
103
|
+
model_config = ConfigDict(
|
|
104
|
+
arbitrary_types_allowed=True,
|
|
105
|
+
extra="forbid",
|
|
106
|
+
)
|
|
106
107
|
|
|
107
|
-
@
|
|
108
|
-
|
|
108
|
+
@model_validator(mode="before")
|
|
109
|
+
@classmethod
|
|
110
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
109
111
|
if "llm" in values:
|
|
110
112
|
warnings.warn(
|
|
111
113
|
"Directly instantiating an LLMCheckerChain with an llm is deprecated. "
|
|
@@ -14,7 +14,7 @@ from langchain_core.callbacks import (
|
|
|
14
14
|
)
|
|
15
15
|
from langchain_core.language_models import BaseLanguageModel
|
|
16
16
|
from langchain_core.prompts import BasePromptTemplate
|
|
17
|
-
from
|
|
17
|
+
from pydantic import ConfigDict, model_validator
|
|
18
18
|
|
|
19
19
|
from langchain.chains.base import Chain
|
|
20
20
|
from langchain.chains.llm import LLMChain
|
|
@@ -156,12 +156,14 @@ class LLMMathChain(Chain):
|
|
|
156
156
|
input_key: str = "question" #: :meta private:
|
|
157
157
|
output_key: str = "answer" #: :meta private:
|
|
158
158
|
|
|
159
|
-
|
|
160
|
-
arbitrary_types_allowed
|
|
161
|
-
extra
|
|
159
|
+
model_config = ConfigDict(
|
|
160
|
+
arbitrary_types_allowed=True,
|
|
161
|
+
extra="forbid",
|
|
162
|
+
)
|
|
162
163
|
|
|
163
|
-
@
|
|
164
|
-
|
|
164
|
+
@model_validator(mode="before")
|
|
165
|
+
@classmethod
|
|
166
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
165
167
|
try:
|
|
166
168
|
import numexpr # noqa: F401
|
|
167
169
|
except ImportError:
|
|
@@ -10,7 +10,7 @@ from langchain_core._api import deprecated
|
|
|
10
10
|
from langchain_core.callbacks import CallbackManagerForChainRun
|
|
11
11
|
from langchain_core.language_models import BaseLanguageModel
|
|
12
12
|
from langchain_core.prompts.prompt import PromptTemplate
|
|
13
|
-
from
|
|
13
|
+
from pydantic import ConfigDict, model_validator
|
|
14
14
|
|
|
15
15
|
from langchain.chains.base import Chain
|
|
16
16
|
from langchain.chains.llm import LLMChain
|
|
@@ -105,12 +105,14 @@ class LLMSummarizationCheckerChain(Chain):
|
|
|
105
105
|
max_checks: int = 2
|
|
106
106
|
"""Maximum number of times to check the assertions. Default to double-checking."""
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
arbitrary_types_allowed
|
|
110
|
-
extra
|
|
108
|
+
model_config = ConfigDict(
|
|
109
|
+
arbitrary_types_allowed=True,
|
|
110
|
+
extra="forbid",
|
|
111
|
+
)
|
|
111
112
|
|
|
112
|
-
@
|
|
113
|
-
|
|
113
|
+
@model_validator(mode="before")
|
|
114
|
+
@classmethod
|
|
115
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
114
116
|
if "llm" in values:
|
|
115
117
|
warnings.warn(
|
|
116
118
|
"Directly instantiating an LLMSummarizationCheckerChain with an llm is "
|
langchain/chains/mapreduce.py
CHANGED
|
@@ -14,6 +14,7 @@ from langchain_core.documents import Document
|
|
|
14
14
|
from langchain_core.language_models import BaseLanguageModel
|
|
15
15
|
from langchain_core.prompts import BasePromptTemplate
|
|
16
16
|
from langchain_text_splitters import TextSplitter
|
|
17
|
+
from pydantic import ConfigDict
|
|
17
18
|
|
|
18
19
|
from langchain.chains import ReduceDocumentsChain
|
|
19
20
|
from langchain.chains.base import Chain
|
|
@@ -77,9 +78,10 @@ class MapReduceChain(Chain):
|
|
|
77
78
|
**kwargs,
|
|
78
79
|
)
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
arbitrary_types_allowed
|
|
82
|
-
extra
|
|
81
|
+
model_config = ConfigDict(
|
|
82
|
+
arbitrary_types_allowed=True,
|
|
83
|
+
extra="forbid",
|
|
84
|
+
)
|
|
83
85
|
|
|
84
86
|
@property
|
|
85
87
|
def input_keys(self) -> List[str]:
|
langchain/chains/moderation.py
CHANGED
|
@@ -6,8 +6,8 @@ from langchain_core.callbacks import (
|
|
|
6
6
|
AsyncCallbackManagerForChainRun,
|
|
7
7
|
CallbackManagerForChainRun,
|
|
8
8
|
)
|
|
9
|
-
from langchain_core.pydantic_v1 import Field, root_validator
|
|
10
9
|
from langchain_core.utils import check_package_version, get_from_dict_or_env
|
|
10
|
+
from pydantic import Field, model_validator
|
|
11
11
|
|
|
12
12
|
from langchain.chains.base import Chain
|
|
13
13
|
|
|
@@ -40,8 +40,9 @@ class OpenAIModerationChain(Chain):
|
|
|
40
40
|
openai_organization: Optional[str] = None
|
|
41
41
|
openai_pre_1_0: bool = Field(default=None)
|
|
42
42
|
|
|
43
|
-
@
|
|
44
|
-
|
|
43
|
+
@model_validator(mode="before")
|
|
44
|
+
@classmethod
|
|
45
|
+
def validate_environment(cls, values: Dict) -> Any:
|
|
45
46
|
"""Validate that api key and python package exists in environment."""
|
|
46
47
|
openai_api_key = get_from_dict_or_env(
|
|
47
48
|
values, "openai_api_key", "OPENAI_API_KEY"
|
langchain/chains/natbot/base.py
CHANGED
|
@@ -9,8 +9,8 @@ from langchain_core._api import deprecated
|
|
|
9
9
|
from langchain_core.callbacks import CallbackManagerForChainRun
|
|
10
10
|
from langchain_core.language_models import BaseLanguageModel
|
|
11
11
|
from langchain_core.output_parsers import StrOutputParser
|
|
12
|
-
from langchain_core.pydantic_v1 import root_validator
|
|
13
12
|
from langchain_core.runnables import Runnable
|
|
13
|
+
from pydantic import ConfigDict, model_validator
|
|
14
14
|
|
|
15
15
|
from langchain.chains.base import Chain
|
|
16
16
|
from langchain.chains.natbot.prompt import PROMPT
|
|
@@ -59,12 +59,14 @@ class NatBotChain(Chain):
|
|
|
59
59
|
previous_command: str = "" #: :meta private:
|
|
60
60
|
output_key: str = "command" #: :meta private:
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
arbitrary_types_allowed
|
|
64
|
-
extra
|
|
62
|
+
model_config = ConfigDict(
|
|
63
|
+
arbitrary_types_allowed=True,
|
|
64
|
+
extra="forbid",
|
|
65
|
+
)
|
|
65
66
|
|
|
66
|
-
@
|
|
67
|
-
|
|
67
|
+
@model_validator(mode="before")
|
|
68
|
+
@classmethod
|
|
69
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
68
70
|
if "llm" in values:
|
|
69
71
|
warnings.warn(
|
|
70
72
|
"Directly instantiating an NatBotChain with an llm is deprecated. "
|
|
@@ -19,11 +19,11 @@ from langchain_core.output_parsers.openai_functions import (
|
|
|
19
19
|
PydanticAttrOutputFunctionsParser,
|
|
20
20
|
)
|
|
21
21
|
from langchain_core.prompts import BasePromptTemplate
|
|
22
|
-
from langchain_core.pydantic_v1 import BaseModel
|
|
23
22
|
from langchain_core.utils.function_calling import (
|
|
24
23
|
PYTHON_TO_JSON_TYPES,
|
|
25
24
|
convert_to_openai_function,
|
|
26
25
|
)
|
|
26
|
+
from pydantic import BaseModel
|
|
27
27
|
|
|
28
28
|
from langchain.chains import LLMChain
|
|
29
29
|
from langchain.chains.structured_output.base import (
|
|
@@ -5,8 +5,8 @@ from langchain_core.language_models import BaseChatModel, BaseLanguageModel
|
|
|
5
5
|
from langchain_core.messages import HumanMessage, SystemMessage
|
|
6
6
|
from langchain_core.output_parsers.openai_functions import PydanticOutputFunctionsParser
|
|
7
7
|
from langchain_core.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate
|
|
8
|
-
from langchain_core.pydantic_v1 import BaseModel, Field
|
|
9
8
|
from langchain_core.runnables import Runnable
|
|
9
|
+
from pydantic import BaseModel, Field
|
|
10
10
|
|
|
11
11
|
from langchain.chains.llm import LLMChain
|
|
12
12
|
from langchain.chains.openai_functions.utils import get_llm_kwargs
|
|
@@ -7,7 +7,7 @@ from langchain_core.output_parsers.openai_functions import (
|
|
|
7
7
|
PydanticAttrOutputFunctionsParser,
|
|
8
8
|
)
|
|
9
9
|
from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate
|
|
10
|
-
from
|
|
10
|
+
from pydantic import BaseModel
|
|
11
11
|
|
|
12
12
|
from langchain.chains.base import Chain
|
|
13
13
|
from langchain.chains.llm import LLMChain
|
|
@@ -10,8 +10,8 @@ from langchain_core.output_parsers.openai_functions import (
|
|
|
10
10
|
)
|
|
11
11
|
from langchain_core.prompts import PromptTemplate
|
|
12
12
|
from langchain_core.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate
|
|
13
|
-
from langchain_core.pydantic_v1 import BaseModel, Field
|
|
14
13
|
from langchain_core.utils.pydantic import is_basemodel_subclass
|
|
14
|
+
from pydantic import BaseModel, Field
|
|
15
15
|
|
|
16
16
|
from langchain.chains.llm import LLMChain
|
|
17
17
|
from langchain.chains.openai_functions.utils import get_llm_kwargs
|
|
@@ -4,9 +4,9 @@ from langchain_core._api import deprecated
|
|
|
4
4
|
from langchain_core.language_models import BaseLanguageModel
|
|
5
5
|
from langchain_core.output_parsers.openai_tools import PydanticToolsParser
|
|
6
6
|
from langchain_core.prompts import ChatPromptTemplate
|
|
7
|
-
from langchain_core.pydantic_v1 import BaseModel
|
|
8
7
|
from langchain_core.runnables import Runnable
|
|
9
8
|
from langchain_core.utils.function_calling import convert_pydantic_to_openai_function
|
|
9
|
+
from pydantic import BaseModel
|
|
10
10
|
|
|
11
11
|
_EXTRACTION_TEMPLATE = """Extract and save the relevant entities mentioned \
|
|
12
12
|
in the following passage together with their properties.
|
|
@@ -5,7 +5,7 @@ from langchain_core.language_models import BaseLanguageModel
|
|
|
5
5
|
from langchain_core.language_models.chat_models import BaseChatModel
|
|
6
6
|
from langchain_core.language_models.llms import BaseLLM
|
|
7
7
|
from langchain_core.prompts import BasePromptTemplate
|
|
8
|
-
from
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class BasePromptSelector(BaseModel, ABC):
|
|
@@ -7,8 +7,8 @@ from langchain_core._api import deprecated
|
|
|
7
7
|
from langchain_core.callbacks import CallbackManagerForChainRun
|
|
8
8
|
from langchain_core.language_models import BaseLanguageModel
|
|
9
9
|
from langchain_core.prompts import BasePromptTemplate
|
|
10
|
-
from langchain_core.pydantic_v1 import Field
|
|
11
10
|
from langchain_text_splitters import RecursiveCharacterTextSplitter, TextSplitter
|
|
11
|
+
from pydantic import Field
|
|
12
12
|
|
|
13
13
|
from langchain.chains.base import Chain
|
|
14
14
|
from langchain.chains.llm import LLMChain
|
|
@@ -15,7 +15,7 @@ from langchain_core.callbacks import (
|
|
|
15
15
|
from langchain_core.documents import Document
|
|
16
16
|
from langchain_core.language_models import BaseLanguageModel
|
|
17
17
|
from langchain_core.prompts import BasePromptTemplate
|
|
18
|
-
from
|
|
18
|
+
from pydantic import ConfigDict, model_validator
|
|
19
19
|
|
|
20
20
|
from langchain.chains import ReduceDocumentsChain
|
|
21
21
|
from langchain.chains.base import Chain
|
|
@@ -97,9 +97,10 @@ class BaseQAWithSourcesChain(Chain, ABC):
|
|
|
97
97
|
)
|
|
98
98
|
return cls(combine_documents_chain=combine_documents_chain, **kwargs)
|
|
99
99
|
|
|
100
|
-
|
|
101
|
-
arbitrary_types_allowed
|
|
102
|
-
extra
|
|
100
|
+
model_config = ConfigDict(
|
|
101
|
+
arbitrary_types_allowed=True,
|
|
102
|
+
extra="forbid",
|
|
103
|
+
)
|
|
103
104
|
|
|
104
105
|
@property
|
|
105
106
|
def input_keys(self) -> List[str]:
|
|
@@ -120,8 +121,9 @@ class BaseQAWithSourcesChain(Chain, ABC):
|
|
|
120
121
|
_output_keys = _output_keys + ["source_documents"]
|
|
121
122
|
return _output_keys
|
|
122
123
|
|
|
123
|
-
@
|
|
124
|
-
|
|
124
|
+
@model_validator(mode="before")
|
|
125
|
+
@classmethod
|
|
126
|
+
def validate_naming(cls, values: Dict) -> Any:
|
|
125
127
|
"""Fix backwards compatibility in naming."""
|
|
126
128
|
if "combine_document_chain" in values:
|
|
127
129
|
values["combine_documents_chain"] = values.pop("combine_document_chain")
|
|
@@ -7,8 +7,8 @@ from langchain_core.callbacks import (
|
|
|
7
7
|
CallbackManagerForChainRun,
|
|
8
8
|
)
|
|
9
9
|
from langchain_core.documents import Document
|
|
10
|
-
from langchain_core.pydantic_v1 import Field
|
|
11
10
|
from langchain_core.retrievers import BaseRetriever
|
|
11
|
+
from pydantic import Field
|
|
12
12
|
|
|
13
13
|
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
|
14
14
|
from langchain.chains.qa_with_sources.base import BaseQAWithSourcesChain
|
|
@@ -8,8 +8,8 @@ from langchain_core.callbacks import (
|
|
|
8
8
|
CallbackManagerForChainRun,
|
|
9
9
|
)
|
|
10
10
|
from langchain_core.documents import Document
|
|
11
|
-
from langchain_core.pydantic_v1 import Field, root_validator
|
|
12
11
|
from langchain_core.vectorstores import VectorStore
|
|
12
|
+
from pydantic import Field, model_validator
|
|
13
13
|
|
|
14
14
|
from langchain.chains.combine_documents.stuff import StuffDocumentsChain
|
|
15
15
|
from langchain.chains.qa_with_sources.base import BaseQAWithSourcesChain
|
|
@@ -61,8 +61,9 @@ class VectorDBQAWithSourcesChain(BaseQAWithSourcesChain):
|
|
|
61
61
|
) -> List[Document]:
|
|
62
62
|
raise NotImplementedError("VectorDBQAWithSourcesChain does not support async")
|
|
63
63
|
|
|
64
|
-
@
|
|
65
|
-
|
|
64
|
+
@model_validator(mode="before")
|
|
65
|
+
@classmethod
|
|
66
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
66
67
|
warnings.warn(
|
|
67
68
|
"`VectorDBQAWithSourcesChain` is deprecated - "
|
|
68
69
|
"please use `from langchain.chains import RetrievalQAWithSourcesChain`"
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
from
|
|
1
|
+
from pydantic import BaseModel, ConfigDict
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class AttributeInfo(BaseModel):
|
|
@@ -8,6 +8,7 @@ class AttributeInfo(BaseModel):
|
|
|
8
8
|
description: str
|
|
9
9
|
type: str
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
arbitrary_types_allowed
|
|
13
|
-
frozen
|
|
11
|
+
model_config = ConfigDict(
|
|
12
|
+
arbitrary_types_allowed=True,
|
|
13
|
+
frozen=True,
|
|
14
|
+
)
|
|
@@ -16,9 +16,9 @@ from langchain_core.callbacks import (
|
|
|
16
16
|
from langchain_core.documents import Document
|
|
17
17
|
from langchain_core.language_models import BaseLanguageModel
|
|
18
18
|
from langchain_core.prompts import PromptTemplate
|
|
19
|
-
from langchain_core.pydantic_v1 import Field, root_validator
|
|
20
19
|
from langchain_core.retrievers import BaseRetriever
|
|
21
20
|
from langchain_core.vectorstores import VectorStore
|
|
21
|
+
from pydantic import ConfigDict, Field, model_validator
|
|
22
22
|
|
|
23
23
|
from langchain.chains.base import Chain
|
|
24
24
|
from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
|
|
@@ -47,10 +47,11 @@ class BaseRetrievalQA(Chain):
|
|
|
47
47
|
return_source_documents: bool = False
|
|
48
48
|
"""Return the source documents or not."""
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
arbitrary_types_allowed
|
|
53
|
-
extra
|
|
50
|
+
model_config = ConfigDict(
|
|
51
|
+
populate_by_name=True,
|
|
52
|
+
arbitrary_types_allowed=True,
|
|
53
|
+
extra="forbid",
|
|
54
|
+
)
|
|
54
55
|
|
|
55
56
|
@property
|
|
56
57
|
def input_keys(self) -> List[str]:
|
|
@@ -309,16 +310,18 @@ class VectorDBQA(BaseRetrievalQA):
|
|
|
309
310
|
search_kwargs: Dict[str, Any] = Field(default_factory=dict)
|
|
310
311
|
"""Extra search args."""
|
|
311
312
|
|
|
312
|
-
@
|
|
313
|
-
|
|
313
|
+
@model_validator(mode="before")
|
|
314
|
+
@classmethod
|
|
315
|
+
def raise_deprecation(cls, values: Dict) -> Any:
|
|
314
316
|
warnings.warn(
|
|
315
317
|
"`VectorDBQA` is deprecated - "
|
|
316
318
|
"please use `from langchain.chains import RetrievalQA`"
|
|
317
319
|
)
|
|
318
320
|
return values
|
|
319
321
|
|
|
320
|
-
@
|
|
321
|
-
|
|
322
|
+
@model_validator(mode="before")
|
|
323
|
+
@classmethod
|
|
324
|
+
def validate_search_type(cls, values: Dict) -> Any:
|
|
322
325
|
"""Validate search type."""
|
|
323
326
|
if "search_type" in values:
|
|
324
327
|
search_type = values["search_type"]
|
langchain/chains/router/base.py
CHANGED
|
@@ -10,6 +10,7 @@ from langchain_core.callbacks import (
|
|
|
10
10
|
CallbackManagerForChainRun,
|
|
11
11
|
Callbacks,
|
|
12
12
|
)
|
|
13
|
+
from pydantic import ConfigDict
|
|
13
14
|
|
|
14
15
|
from langchain.chains.base import Chain
|
|
15
16
|
|
|
@@ -60,9 +61,10 @@ class MultiRouteChain(Chain):
|
|
|
60
61
|
"""If True, use default_chain when an invalid destination name is provided.
|
|
61
62
|
Defaults to False."""
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
arbitrary_types_allowed
|
|
65
|
-
extra
|
|
64
|
+
model_config = ConfigDict(
|
|
65
|
+
arbitrary_types_allowed=True,
|
|
66
|
+
extra="forbid",
|
|
67
|
+
)
|
|
66
68
|
|
|
67
69
|
@property
|
|
68
70
|
def input_keys(self) -> List[str]:
|