langchain 0.2.15__py3-none-any.whl → 0.3.0__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 +23 -19
- 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/openai_tools/base.py +8 -3
- 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 +14 -12
- langchain/chains/base.py +17 -9
- 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 +10 -8
- langchain/chains/elasticsearch_database/base.py +11 -9
- langchain/chains/flare/base.py +5 -2
- langchain/chains/hyde/base.py +6 -4
- langchain/chains/llm.py +7 -7
- 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 +14 -12
- langchain/chains/natbot/base.py +8 -6
- langchain/chains/openai_functions/base.py +3 -3
- langchain/chains/openai_functions/citation_fuzzy_match.py +1 -1
- langchain/chains/openai_functions/extraction.py +8 -4
- langchain/chains/openai_functions/qa_with_structure.py +5 -2
- langchain/chains/openai_functions/tagging.py +5 -2
- langchain/chains/openai_tools/extraction.py +2 -2
- 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 +8 -8
- langchain/chains/transform.py +1 -1
- langchain/chat_models/base.py +2 -2
- 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 +5 -3
- 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 +3 -2
- langchain/output_parsers/retry.py +4 -3
- langchain/output_parsers/structured.py +1 -1
- langchain/output_parsers/yaml.py +5 -2
- langchain/pydantic_v1/__init__.py +20 -0
- langchain/pydantic_v1/dataclasses.py +20 -0
- langchain/pydantic_v1/main.py +20 -0
- 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 +5 -4
- langchain/retrievers/document_compressors/listwise_rerank.py +4 -3
- langchain/retrievers/ensemble.py +18 -14
- langchain/retrievers/multi_vector.py +5 -4
- langchain/retrievers/self_query/base.py +19 -8
- langchain/retrievers/time_weighted_retriever.py +4 -3
- langchain/smith/evaluation/config.py +7 -5
- {langchain-0.2.15.dist-info → langchain-0.3.0.dist-info}/METADATA +5 -5
- {langchain-0.2.15.dist-info → langchain-0.3.0.dist-info}/RECORD +96 -96
- {langchain-0.2.15.dist-info → langchain-0.3.0.dist-info}/LICENSE +0 -0
- {langchain-0.2.15.dist-info → langchain-0.3.0.dist-info}/WHEEL +0 -0
- {langchain-0.2.15.dist-info → langchain-0.3.0.dist-info}/entry_points.txt +0 -0
|
@@ -9,6 +9,7 @@ from typing import Any, List, Optional, Sequence, Tuple
|
|
|
9
9
|
from langchain_core.callbacks.manager import Callbacks
|
|
10
10
|
from langchain_core.language_models import BaseLanguageModel
|
|
11
11
|
from langchain_core.prompts import PromptTemplate
|
|
12
|
+
from pydantic import ConfigDict
|
|
12
13
|
|
|
13
14
|
from langchain.chains.llm import LLMChain
|
|
14
15
|
from langchain.evaluation.qa.eval_prompt import CONTEXT_PROMPT, COT_PROMPT, PROMPT
|
|
@@ -72,8 +73,9 @@ class QAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
|
|
|
72
73
|
|
|
73
74
|
output_key: str = "results" #: :meta private:
|
|
74
75
|
|
|
75
|
-
|
|
76
|
-
extra
|
|
76
|
+
model_config = ConfigDict(
|
|
77
|
+
extra="ignore",
|
|
78
|
+
)
|
|
77
79
|
|
|
78
80
|
@classmethod
|
|
79
81
|
def is_lc_serializable(cls) -> bool:
|
|
@@ -220,8 +222,9 @@ class ContextQAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
|
|
|
220
222
|
"""Whether the chain requires an input string."""
|
|
221
223
|
return True
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
extra
|
|
225
|
+
model_config = ConfigDict(
|
|
226
|
+
extra="ignore",
|
|
227
|
+
)
|
|
225
228
|
|
|
226
229
|
@classmethod
|
|
227
230
|
def _validate_input_vars(cls, prompt: PromptTemplate) -> None:
|
|
@@ -6,7 +6,7 @@ from typing import Any
|
|
|
6
6
|
|
|
7
7
|
from langchain_core.language_models import BaseLanguageModel
|
|
8
8
|
from langchain_core.output_parsers import BaseLLMOutputParser
|
|
9
|
-
from
|
|
9
|
+
from pydantic import Field
|
|
10
10
|
|
|
11
11
|
from langchain.chains.llm import LLMChain
|
|
12
12
|
from langchain.evaluation.qa.generate_prompt import PROMPT
|
|
@@ -10,7 +10,7 @@ from langchain_core.callbacks.manager import Callbacks
|
|
|
10
10
|
from langchain_core.language_models import BaseLanguageModel
|
|
11
11
|
from langchain_core.output_parsers import BaseOutputParser
|
|
12
12
|
from langchain_core.prompts.prompt import PromptTemplate
|
|
13
|
-
from
|
|
13
|
+
from pydantic import ConfigDict, Field
|
|
14
14
|
|
|
15
15
|
from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
|
|
16
16
|
from langchain.chains.llm import LLMChain
|
|
@@ -179,8 +179,9 @@ class ScoreStringEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
|
|
|
179
179
|
criterion_name: str
|
|
180
180
|
"""The name of the criterion being evaluated."""
|
|
181
181
|
|
|
182
|
-
|
|
183
|
-
extra
|
|
182
|
+
model_config = ConfigDict(
|
|
183
|
+
extra="ignore",
|
|
184
|
+
)
|
|
184
185
|
|
|
185
186
|
@classmethod
|
|
186
187
|
def is_lc_serializable(cls) -> bool:
|
|
@@ -8,8 +8,8 @@ from langchain_core.callbacks.manager import (
|
|
|
8
8
|
CallbackManagerForChainRun,
|
|
9
9
|
Callbacks,
|
|
10
10
|
)
|
|
11
|
-
from langchain_core.pydantic_v1 import Field
|
|
12
11
|
from langchain_core.utils import pre_init
|
|
12
|
+
from pydantic import Field
|
|
13
13
|
|
|
14
14
|
from langchain.chains.base import Chain
|
|
15
15
|
from langchain.evaluation.schema import PairwiseStringEvaluator, StringEvaluator
|
langchain/indexes/vectorstore.py
CHANGED
|
@@ -4,9 +4,9 @@ from langchain_core.document_loaders import BaseLoader
|
|
|
4
4
|
from langchain_core.documents import Document
|
|
5
5
|
from langchain_core.embeddings import Embeddings
|
|
6
6
|
from langchain_core.language_models import BaseLanguageModel
|
|
7
|
-
from langchain_core.pydantic_v1 import BaseModel, Field
|
|
8
7
|
from langchain_core.vectorstores import VectorStore
|
|
9
8
|
from langchain_text_splitters import RecursiveCharacterTextSplitter, TextSplitter
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
10
10
|
|
|
11
11
|
from langchain.chains.qa_with_sources.retrieval import RetrievalQAWithSourcesChain
|
|
12
12
|
from langchain.chains.retrieval_qa.base import RetrievalQA
|
|
@@ -21,9 +21,10 @@ class VectorStoreIndexWrapper(BaseModel):
|
|
|
21
21
|
|
|
22
22
|
vectorstore: VectorStore
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
arbitrary_types_allowed
|
|
26
|
-
extra
|
|
24
|
+
model_config = ConfigDict(
|
|
25
|
+
arbitrary_types_allowed=True,
|
|
26
|
+
extra="forbid",
|
|
27
|
+
)
|
|
27
28
|
|
|
28
29
|
def query(
|
|
29
30
|
self,
|
|
@@ -142,9 +143,10 @@ class VectorstoreIndexCreator(BaseModel):
|
|
|
142
143
|
text_splitter: TextSplitter = Field(default_factory=_get_default_text_splitter)
|
|
143
144
|
vectorstore_kwargs: dict = Field(default_factory=dict)
|
|
144
145
|
|
|
145
|
-
|
|
146
|
-
arbitrary_types_allowed
|
|
147
|
-
extra
|
|
146
|
+
model_config = ConfigDict(
|
|
147
|
+
arbitrary_types_allowed=True,
|
|
148
|
+
extra="forbid",
|
|
149
|
+
)
|
|
148
150
|
|
|
149
151
|
def from_loaders(self, loaders: List[BaseLoader]) -> VectorStoreIndexWrapper:
|
|
150
152
|
"""Create a vectorstore index from loaders."""
|
langchain/memory/chat_memory.py
CHANGED
|
@@ -8,7 +8,7 @@ from langchain_core.chat_history import (
|
|
|
8
8
|
)
|
|
9
9
|
from langchain_core.memory import BaseMemory
|
|
10
10
|
from langchain_core.messages import AIMessage, HumanMessage
|
|
11
|
-
from
|
|
11
|
+
from pydantic import Field
|
|
12
12
|
|
|
13
13
|
from langchain.memory.utils import get_prompt_input_key
|
|
14
14
|
|
langchain/memory/combined.py
CHANGED
|
@@ -2,7 +2,7 @@ import warnings
|
|
|
2
2
|
from typing import Any, Dict, List, Set
|
|
3
3
|
|
|
4
4
|
from langchain_core.memory import BaseMemory
|
|
5
|
-
from
|
|
5
|
+
from pydantic import field_validator
|
|
6
6
|
|
|
7
7
|
from langchain.memory.chat_memory import BaseChatMemory
|
|
8
8
|
|
|
@@ -13,7 +13,8 @@ class CombinedMemory(BaseMemory):
|
|
|
13
13
|
memories: List[BaseMemory]
|
|
14
14
|
"""For tracking all the memories that should be accessed."""
|
|
15
15
|
|
|
16
|
-
@
|
|
16
|
+
@field_validator("memories")
|
|
17
|
+
@classmethod
|
|
17
18
|
def check_repeated_memory_variable(
|
|
18
19
|
cls, value: List[BaseMemory]
|
|
19
20
|
) -> List[BaseMemory]:
|
|
@@ -29,7 +30,8 @@ class CombinedMemory(BaseMemory):
|
|
|
29
30
|
|
|
30
31
|
return value
|
|
31
32
|
|
|
32
|
-
@
|
|
33
|
+
@field_validator("memories")
|
|
34
|
+
@classmethod
|
|
33
35
|
def check_input_key(cls, value: List[BaseMemory]) -> List[BaseMemory]:
|
|
34
36
|
"""Check that if memories are of type BaseChatMemory that input keys exist."""
|
|
35
37
|
for val in value:
|
langchain/memory/entity.py
CHANGED
|
@@ -6,7 +6,7 @@ from typing import Any, Dict, Iterable, List, Optional
|
|
|
6
6
|
from langchain_core.language_models import BaseLanguageModel
|
|
7
7
|
from langchain_core.messages import BaseMessage, get_buffer_string
|
|
8
8
|
from langchain_core.prompts import BasePromptTemplate
|
|
9
|
-
from
|
|
9
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
10
10
|
|
|
11
11
|
from langchain.chains.llm import LLMChain
|
|
12
12
|
from langchain.memory.chat_memory import BaseChatMemory
|
|
@@ -245,8 +245,9 @@ class SQLiteEntityStore(BaseEntityStore):
|
|
|
245
245
|
table_name: str = "memory_store"
|
|
246
246
|
conn: Any = None
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
arbitrary_types_allowed
|
|
248
|
+
model_config = ConfigDict(
|
|
249
|
+
arbitrary_types_allowed=True,
|
|
250
|
+
)
|
|
250
251
|
|
|
251
252
|
def __init__(
|
|
252
253
|
self,
|
langchain/memory/summary.py
CHANGED
|
@@ -7,8 +7,8 @@ from langchain_core.chat_history import BaseChatMessageHistory
|
|
|
7
7
|
from langchain_core.language_models import BaseLanguageModel
|
|
8
8
|
from langchain_core.messages import BaseMessage, SystemMessage, get_buffer_string
|
|
9
9
|
from langchain_core.prompts import BasePromptTemplate
|
|
10
|
-
from langchain_core.pydantic_v1 import BaseModel
|
|
11
10
|
from langchain_core.utils import pre_init
|
|
11
|
+
from pydantic import BaseModel
|
|
12
12
|
|
|
13
13
|
from langchain.chains.llm import LLMChain
|
|
14
14
|
from langchain.memory.chat_memory import BaseChatMemory
|
langchain/memory/vectorstore.py
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
from typing import Any, Dict, List, Optional, Sequence, Union
|
|
4
4
|
|
|
5
5
|
from langchain_core.documents import Document
|
|
6
|
-
from langchain_core.pydantic_v1 import Field
|
|
7
6
|
from langchain_core.vectorstores import VectorStoreRetriever
|
|
7
|
+
from pydantic import Field
|
|
8
8
|
|
|
9
9
|
from langchain.memory.chat_memory import BaseMemory
|
|
10
10
|
from langchain.memory.utils import get_prompt_input_key
|
|
@@ -13,8 +13,8 @@ from typing import Any, Dict, List
|
|
|
13
13
|
|
|
14
14
|
from langchain_core.messages import BaseMessage
|
|
15
15
|
from langchain_core.prompts.chat import SystemMessagePromptTemplate
|
|
16
|
-
from langchain_core.pydantic_v1 import Field, PrivateAttr
|
|
17
16
|
from langchain_core.vectorstores import VectorStoreRetriever
|
|
17
|
+
from pydantic import Field, PrivateAttr
|
|
18
18
|
|
|
19
19
|
from langchain.memory import ConversationTokenBufferMemory, VectorStoreRetrieverMemory
|
|
20
20
|
from langchain.memory.chat_memory import BaseChatMemory
|
langchain/output_parsers/fix.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from typing import Any, TypeVar, Union
|
|
3
|
+
from typing import Annotated, Any, TypeVar, Union
|
|
4
4
|
|
|
5
5
|
from langchain_core.exceptions import OutputParserException
|
|
6
6
|
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
|
|
7
7
|
from langchain_core.prompts import BasePromptTemplate
|
|
8
8
|
from langchain_core.runnables import Runnable, RunnableSerializable
|
|
9
|
+
from pydantic import SkipValidation
|
|
9
10
|
from typing_extensions import TypedDict
|
|
10
11
|
|
|
11
12
|
from langchain.output_parsers.prompts import NAIVE_FIX_PROMPT
|
|
@@ -26,7 +27,7 @@ class OutputFixingParser(BaseOutputParser[T]):
|
|
|
26
27
|
def is_lc_serializable(cls) -> bool:
|
|
27
28
|
return True
|
|
28
29
|
|
|
29
|
-
parser: BaseOutputParser[T]
|
|
30
|
+
parser: Annotated[BaseOutputParser[T], SkipValidation()]
|
|
30
31
|
"""The parser to use to parse the output."""
|
|
31
32
|
# Should be an LLMChain but we want to avoid top-level imports from langchain.chains
|
|
32
33
|
retry_chain: Union[
|
|
@@ -3,7 +3,7 @@ from typing import Any, Dict, List, Tuple, Union
|
|
|
3
3
|
|
|
4
4
|
from langchain_core.exceptions import OutputParserException
|
|
5
5
|
from langchain_core.output_parsers.base import BaseOutputParser
|
|
6
|
-
from
|
|
6
|
+
from pydantic import field_validator
|
|
7
7
|
|
|
8
8
|
from langchain.output_parsers.format_instructions import (
|
|
9
9
|
PANDAS_DATAFRAME_FORMAT_INSTRUCTIONS,
|
|
@@ -16,7 +16,8 @@ class PandasDataFrameOutputParser(BaseOutputParser[Dict[str, Any]]):
|
|
|
16
16
|
"""The Pandas DataFrame to parse."""
|
|
17
17
|
dataframe: Any
|
|
18
18
|
|
|
19
|
-
@
|
|
19
|
+
@field_validator("dataframe")
|
|
20
|
+
@classmethod
|
|
20
21
|
def validate_dataframe(cls, val: Any) -> Any:
|
|
21
22
|
import pandas as pd
|
|
22
23
|
|
|
@@ -8,7 +8,8 @@ from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
|
|
|
8
8
|
from langchain_core.prompt_values import PromptValue
|
|
9
9
|
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
|
|
10
10
|
from langchain_core.runnables import RunnableSerializable
|
|
11
|
-
from
|
|
11
|
+
from pydantic import SkipValidation
|
|
12
|
+
from typing_extensions import Annotated, TypedDict
|
|
12
13
|
|
|
13
14
|
NAIVE_COMPLETION_RETRY = """Prompt:
|
|
14
15
|
{prompt}
|
|
@@ -53,7 +54,7 @@ class RetryOutputParser(BaseOutputParser[T]):
|
|
|
53
54
|
LLM, and telling it the completion did not satisfy criteria in the prompt.
|
|
54
55
|
"""
|
|
55
56
|
|
|
56
|
-
parser: BaseOutputParser[T]
|
|
57
|
+
parser: Annotated[BaseOutputParser[T], SkipValidation()]
|
|
57
58
|
"""The parser to use to parse the output."""
|
|
58
59
|
# Should be an LLMChain but we want to avoid top-level imports from langchain.chains
|
|
59
60
|
retry_chain: Union[RunnableSerializable[RetryOutputParserRetryChainInput, str], Any]
|
|
@@ -183,7 +184,7 @@ class RetryWithErrorOutputParser(BaseOutputParser[T]):
|
|
|
183
184
|
LLM, which in theory should give it more information on how to fix it.
|
|
184
185
|
"""
|
|
185
186
|
|
|
186
|
-
parser: BaseOutputParser[T]
|
|
187
|
+
parser: Annotated[BaseOutputParser[T], SkipValidation()]
|
|
187
188
|
"""The parser to use to parse the output."""
|
|
188
189
|
# Should be an LLMChain but we want to avoid top-level imports from langchain.chains
|
|
189
190
|
retry_chain: Union[
|
|
@@ -4,7 +4,7 @@ from typing import Any, Dict, List
|
|
|
4
4
|
|
|
5
5
|
from langchain_core.output_parsers import BaseOutputParser
|
|
6
6
|
from langchain_core.output_parsers.json import parse_and_check_json_markdown
|
|
7
|
-
from
|
|
7
|
+
from pydantic import BaseModel
|
|
8
8
|
|
|
9
9
|
from langchain.output_parsers.format_instructions import (
|
|
10
10
|
STRUCTURED_FORMAT_INSTRUCTIONS,
|
langchain/output_parsers/yaml.py
CHANGED
|
@@ -5,7 +5,7 @@ from typing import Type, TypeVar
|
|
|
5
5
|
import yaml
|
|
6
6
|
from langchain_core.exceptions import OutputParserException
|
|
7
7
|
from langchain_core.output_parsers import BaseOutputParser
|
|
8
|
-
from
|
|
8
|
+
from pydantic import BaseModel, ValidationError
|
|
9
9
|
|
|
10
10
|
from langchain.output_parsers.format_instructions import YAML_FORMAT_INSTRUCTIONS
|
|
11
11
|
|
|
@@ -35,7 +35,10 @@ class YamlOutputParser(BaseOutputParser[T]):
|
|
|
35
35
|
yaml_str = text
|
|
36
36
|
|
|
37
37
|
json_object = yaml.safe_load(yaml_str)
|
|
38
|
-
|
|
38
|
+
if hasattr(self.pydantic_object, "model_validate"):
|
|
39
|
+
return self.pydantic_object.model_validate(json_object)
|
|
40
|
+
else:
|
|
41
|
+
return self.pydantic_object.parse_obj(json_object)
|
|
39
42
|
|
|
40
43
|
except (yaml.YAMLError, ValidationError) as e:
|
|
41
44
|
name = self.pydantic_object.__name__
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from importlib import metadata
|
|
2
2
|
|
|
3
|
+
from langchain_core._api import warn_deprecated
|
|
4
|
+
|
|
3
5
|
## Create namespaces for pydantic v1 and v2.
|
|
4
6
|
# This code must stay at the top of the file before other modules may
|
|
5
7
|
# attempt to import pydantic since it adds pydantic_v1 and pydantic_v2 to sys.modules.
|
|
@@ -21,3 +23,21 @@ try:
|
|
|
21
23
|
_PYDANTIC_MAJOR_VERSION: int = int(metadata.version("pydantic").split(".")[0])
|
|
22
24
|
except metadata.PackageNotFoundError:
|
|
23
25
|
_PYDANTIC_MAJOR_VERSION = 0
|
|
26
|
+
|
|
27
|
+
warn_deprecated(
|
|
28
|
+
"0.3.0",
|
|
29
|
+
removal="1.0.0",
|
|
30
|
+
alternative="pydantic.v1 or pydantic",
|
|
31
|
+
message=(
|
|
32
|
+
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
33
|
+
"The langchain.pydantic_v1 module was a "
|
|
34
|
+
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
35
|
+
"Please update the code to import from Pydantic directly.\n\n"
|
|
36
|
+
"For example, replace imports like: "
|
|
37
|
+
"`from langchain.pydantic_v1 import BaseModel`\n"
|
|
38
|
+
"with: `from pydantic import BaseModel`\n"
|
|
39
|
+
"or the v1 compatibility namespace if you are working in a code base "
|
|
40
|
+
"that has not been fully upgraded to pydantic 2 yet. "
|
|
41
|
+
"\tfrom pydantic.v1 import BaseModel\n"
|
|
42
|
+
),
|
|
43
|
+
)
|
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
from langchain_core._api import warn_deprecated
|
|
2
|
+
|
|
1
3
|
try:
|
|
2
4
|
from pydantic.v1.dataclasses import * # noqa: F403
|
|
3
5
|
except ImportError:
|
|
4
6
|
from pydantic.dataclasses import * # type: ignore # noqa: F403
|
|
7
|
+
|
|
8
|
+
warn_deprecated(
|
|
9
|
+
"0.3.0",
|
|
10
|
+
removal="1.0.0",
|
|
11
|
+
alternative="pydantic.v1 or pydantic",
|
|
12
|
+
message=(
|
|
13
|
+
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
14
|
+
"The langchain.pydantic_v1 module was a "
|
|
15
|
+
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
16
|
+
"Please update the code to import from Pydantic directly.\n\n"
|
|
17
|
+
"For example, replace imports like: "
|
|
18
|
+
"`from langchain.pydantic_v1 import BaseModel`\n"
|
|
19
|
+
"with: `from pydantic import BaseModel`\n"
|
|
20
|
+
"or the v1 compatibility namespace if you are working in a code base "
|
|
21
|
+
"that has not been fully upgraded to pydantic 2 yet. "
|
|
22
|
+
"\tfrom pydantic.v1 import BaseModel\n"
|
|
23
|
+
),
|
|
24
|
+
)
|
langchain/pydantic_v1/main.py
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
|
+
from langchain_core._api import warn_deprecated
|
|
2
|
+
|
|
1
3
|
try:
|
|
2
4
|
from pydantic.v1.main import * # noqa: F403
|
|
3
5
|
except ImportError:
|
|
4
6
|
from pydantic.main import * # type: ignore # noqa: F403
|
|
7
|
+
|
|
8
|
+
warn_deprecated(
|
|
9
|
+
"0.3.0",
|
|
10
|
+
removal="1.0.0",
|
|
11
|
+
alternative="pydantic.v1 or pydantic",
|
|
12
|
+
message=(
|
|
13
|
+
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
14
|
+
"The langchain.pydantic_v1 module was a "
|
|
15
|
+
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
16
|
+
"Please update the code to import from Pydantic directly.\n\n"
|
|
17
|
+
"For example, replace imports like: "
|
|
18
|
+
"`from langchain.pydantic_v1 import BaseModel`\n"
|
|
19
|
+
"with: `from pydantic import BaseModel`\n"
|
|
20
|
+
"or the v1 compatibility namespace if you are working in a code base "
|
|
21
|
+
"that has not been fully upgraded to pydantic 2 yet. "
|
|
22
|
+
"\tfrom pydantic.v1 import BaseModel\n"
|
|
23
|
+
),
|
|
24
|
+
)
|
|
@@ -6,6 +6,7 @@ from langchain_core.callbacks import (
|
|
|
6
6
|
)
|
|
7
7
|
from langchain_core.documents import Document
|
|
8
8
|
from langchain_core.retrievers import BaseRetriever, RetrieverLike
|
|
9
|
+
from pydantic import ConfigDict
|
|
9
10
|
|
|
10
11
|
from langchain.retrievers.document_compressors.base import (
|
|
11
12
|
BaseDocumentCompressor,
|
|
@@ -21,8 +22,9 @@ class ContextualCompressionRetriever(BaseRetriever):
|
|
|
21
22
|
base_retriever: RetrieverLike
|
|
22
23
|
"""Base Retriever to use for getting relevant documents."""
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
arbitrary_types_allowed
|
|
25
|
+
model_config = ConfigDict(
|
|
26
|
+
arbitrary_types_allowed=True,
|
|
27
|
+
)
|
|
26
28
|
|
|
27
29
|
def _get_relevant_documents(
|
|
28
30
|
self,
|
|
@@ -7,6 +7,7 @@ from langchain_core.documents import (
|
|
|
7
7
|
BaseDocumentTransformer,
|
|
8
8
|
Document,
|
|
9
9
|
)
|
|
10
|
+
from pydantic import ConfigDict
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
class DocumentCompressorPipeline(BaseDocumentCompressor):
|
|
@@ -15,8 +16,9 @@ class DocumentCompressorPipeline(BaseDocumentCompressor):
|
|
|
15
16
|
transformers: List[Union[BaseDocumentTransformer, BaseDocumentCompressor]]
|
|
16
17
|
"""List of document filters that are chained together and run in sequence."""
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
arbitrary_types_allowed
|
|
19
|
+
model_config = ConfigDict(
|
|
20
|
+
arbitrary_types_allowed=True,
|
|
21
|
+
)
|
|
20
22
|
|
|
21
23
|
def compress_documents(
|
|
22
24
|
self,
|
|
@@ -11,6 +11,7 @@ from langchain_core.language_models import BaseLanguageModel
|
|
|
11
11
|
from langchain_core.output_parsers import BaseOutputParser, StrOutputParser
|
|
12
12
|
from langchain_core.prompts import PromptTemplate
|
|
13
13
|
from langchain_core.runnables import Runnable
|
|
14
|
+
from pydantic import ConfigDict
|
|
14
15
|
|
|
15
16
|
from langchain.chains.llm import LLMChain
|
|
16
17
|
from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
|
|
@@ -56,8 +57,9 @@ class LLMChainExtractor(BaseDocumentCompressor):
|
|
|
56
57
|
get_input: Callable[[str, Document], dict] = default_get_input
|
|
57
58
|
"""Callable for constructing the chain input from the query and a Document."""
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
arbitrary_types_allowed
|
|
60
|
+
model_config = ConfigDict(
|
|
61
|
+
arbitrary_types_allowed=True,
|
|
62
|
+
)
|
|
61
63
|
|
|
62
64
|
def compress_documents(
|
|
63
65
|
self,
|
|
@@ -9,6 +9,7 @@ from langchain_core.output_parsers import StrOutputParser
|
|
|
9
9
|
from langchain_core.prompts import BasePromptTemplate, PromptTemplate
|
|
10
10
|
from langchain_core.runnables import Runnable
|
|
11
11
|
from langchain_core.runnables.config import RunnableConfig
|
|
12
|
+
from pydantic import ConfigDict
|
|
12
13
|
|
|
13
14
|
from langchain.chains import LLMChain
|
|
14
15
|
from langchain.output_parsers.boolean import BooleanOutputParser
|
|
@@ -41,8 +42,9 @@ class LLMChainFilter(BaseDocumentCompressor):
|
|
|
41
42
|
get_input: Callable[[str, Document], dict] = default_get_input
|
|
42
43
|
"""Callable for constructing the chain input from the query and a Document."""
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
arbitrary_types_allowed
|
|
45
|
+
model_config = ConfigDict(
|
|
46
|
+
arbitrary_types_allowed=True,
|
|
47
|
+
)
|
|
46
48
|
|
|
47
49
|
def compress_documents(
|
|
48
50
|
self,
|
|
@@ -6,8 +6,8 @@ from typing import Any, Dict, List, Optional, Sequence, Union
|
|
|
6
6
|
from langchain_core._api.deprecation import deprecated
|
|
7
7
|
from langchain_core.callbacks.manager import Callbacks
|
|
8
8
|
from langchain_core.documents import Document
|
|
9
|
-
from langchain_core.pydantic_v1 import root_validator
|
|
10
9
|
from langchain_core.utils import get_from_dict_or_env
|
|
10
|
+
from pydantic import ConfigDict, model_validator
|
|
11
11
|
|
|
12
12
|
from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
|
|
13
13
|
|
|
@@ -30,12 +30,14 @@ class CohereRerank(BaseDocumentCompressor):
|
|
|
30
30
|
user_agent: str = "langchain"
|
|
31
31
|
"""Identifier for the application making the request."""
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
arbitrary_types_allowed
|
|
35
|
-
extra
|
|
33
|
+
model_config = ConfigDict(
|
|
34
|
+
arbitrary_types_allowed=True,
|
|
35
|
+
extra="forbid",
|
|
36
|
+
)
|
|
36
37
|
|
|
37
|
-
@
|
|
38
|
-
|
|
38
|
+
@model_validator(mode="before")
|
|
39
|
+
@classmethod
|
|
40
|
+
def validate_environment(cls, values: Dict) -> Any:
|
|
39
41
|
"""Validate that api key and python package exists in environment."""
|
|
40
42
|
if not values.get("client"):
|
|
41
43
|
try:
|
|
@@ -5,6 +5,7 @@ from typing import Optional, Sequence
|
|
|
5
5
|
|
|
6
6
|
from langchain_core.callbacks import Callbacks
|
|
7
7
|
from langchain_core.documents import BaseDocumentCompressor, Document
|
|
8
|
+
from pydantic import ConfigDict
|
|
8
9
|
|
|
9
10
|
from langchain.retrievers.document_compressors.cross_encoder import BaseCrossEncoder
|
|
10
11
|
|
|
@@ -18,9 +19,10 @@ class CrossEncoderReranker(BaseDocumentCompressor):
|
|
|
18
19
|
top_n: int = 3
|
|
19
20
|
"""Number of documents to return."""
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
arbitrary_types_allowed
|
|
23
|
-
extra
|
|
22
|
+
model_config = ConfigDict(
|
|
23
|
+
arbitrary_types_allowed=True,
|
|
24
|
+
extra="forbid",
|
|
25
|
+
)
|
|
24
26
|
|
|
25
27
|
def compress_documents(
|
|
26
28
|
self,
|
|
@@ -4,8 +4,8 @@ import numpy as np
|
|
|
4
4
|
from langchain_core.callbacks.manager import Callbacks
|
|
5
5
|
from langchain_core.documents import Document
|
|
6
6
|
from langchain_core.embeddings import Embeddings
|
|
7
|
-
from langchain_core.pydantic_v1 import Field
|
|
8
7
|
from langchain_core.utils import pre_init
|
|
8
|
+
from pydantic import ConfigDict, Field
|
|
9
9
|
|
|
10
10
|
from langchain.retrievers.document_compressors.base import (
|
|
11
11
|
BaseDocumentCompressor,
|
|
@@ -36,13 +36,14 @@ class EmbeddingsFilter(BaseDocumentCompressor):
|
|
|
36
36
|
k: Optional[int] = 20
|
|
37
37
|
"""The number of relevant documents to return. Can be set to None, in which case
|
|
38
38
|
`similarity_threshold` must be specified. Defaults to 20."""
|
|
39
|
-
similarity_threshold: Optional[float]
|
|
39
|
+
similarity_threshold: Optional[float] = None
|
|
40
40
|
"""Threshold for determining when two documents are similar enough
|
|
41
41
|
to be considered redundant. Defaults to None, must be specified if `k` is set
|
|
42
42
|
to None."""
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
arbitrary_types_allowed
|
|
44
|
+
model_config = ConfigDict(
|
|
45
|
+
arbitrary_types_allowed=True,
|
|
46
|
+
)
|
|
46
47
|
|
|
47
48
|
@pre_init
|
|
48
49
|
def validate_params(cls, values: Dict) -> Dict:
|
|
@@ -6,8 +6,8 @@ from langchain_core.callbacks import Callbacks
|
|
|
6
6
|
from langchain_core.documents import BaseDocumentCompressor, Document
|
|
7
7
|
from langchain_core.language_models import BaseLanguageModel
|
|
8
8
|
from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate
|
|
9
|
-
from langchain_core.pydantic_v1 import BaseModel, Field
|
|
10
9
|
from langchain_core.runnables import Runnable, RunnableLambda, RunnablePassthrough
|
|
10
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
11
11
|
|
|
12
12
|
_default_system_tmpl = """{context}
|
|
13
13
|
|
|
@@ -76,8 +76,9 @@ class LLMListwiseRerank(BaseDocumentCompressor):
|
|
|
76
76
|
top_n: int = 3
|
|
77
77
|
"""Number of documents to return."""
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
arbitrary_types_allowed
|
|
79
|
+
model_config = ConfigDict(
|
|
80
|
+
arbitrary_types_allowed=True,
|
|
81
|
+
)
|
|
81
82
|
|
|
82
83
|
def compress_documents(
|
|
83
84
|
self,
|