langchain 0.2.12__py3-none-any.whl → 0.2.13__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.
Files changed (78) hide show
  1. langchain/agents/agent.py +5 -9
  2. langchain/agents/agent_toolkits/vectorstore/base.py +114 -2
  3. langchain/agents/agent_toolkits/vectorstore/toolkit.py +0 -6
  4. langchain/agents/initialize.py +1 -1
  5. langchain/agents/loading.py +2 -2
  6. langchain/agents/mrkl/base.py +1 -1
  7. langchain/agents/openai_assistant/base.py +2 -2
  8. langchain/agents/openai_functions_agent/base.py +1 -1
  9. langchain/agents/openai_functions_multi_agent/base.py +1 -1
  10. langchain/chains/__init__.py +1 -0
  11. langchain/chains/api/base.py +121 -1
  12. langchain/chains/base.py +0 -2
  13. langchain/chains/combine_documents/map_reduce.py +2 -4
  14. langchain/chains/combine_documents/map_rerank.py +4 -6
  15. langchain/chains/combine_documents/reduce.py +1 -4
  16. langchain/chains/combine_documents/refine.py +2 -4
  17. langchain/chains/combine_documents/stuff.py +12 -4
  18. langchain/chains/conversation/base.py +2 -4
  19. langchain/chains/conversational_retrieval/base.py +4 -6
  20. langchain/chains/elasticsearch_database/base.py +16 -20
  21. langchain/chains/example_generator.py +3 -4
  22. langchain/chains/flare/base.py +1 -1
  23. langchain/chains/hyde/base.py +1 -4
  24. langchain/chains/llm.py +2 -4
  25. langchain/chains/llm_checker/base.py +12 -4
  26. langchain/chains/llm_math/base.py +2 -4
  27. langchain/chains/llm_summarization_checker/base.py +12 -4
  28. langchain/chains/loading.py +17 -0
  29. langchain/chains/mapreduce.py +12 -4
  30. langchain/chains/natbot/base.py +2 -4
  31. langchain/chains/openai_functions/__init__.py +2 -0
  32. langchain/chains/openai_functions/citation_fuzzy_match.py +54 -1
  33. langchain/chains/openai_functions/openapi.py +88 -1
  34. langchain/chains/openai_functions/qa_with_structure.py +19 -0
  35. langchain/chains/openai_functions/tagging.py +81 -0
  36. langchain/chains/qa_with_sources/base.py +21 -4
  37. langchain/chains/qa_with_sources/loading.py +16 -0
  38. langchain/chains/query_constructor/base.py +8 -2
  39. langchain/chains/query_constructor/schema.py +0 -2
  40. langchain/chains/question_answering/chain.py +15 -0
  41. langchain/chains/retrieval_qa/base.py +30 -6
  42. langchain/chains/router/base.py +1 -4
  43. langchain/chains/router/embedding_router.py +1 -4
  44. langchain/chains/router/llm_router.py +76 -1
  45. langchain/chains/router/multi_prompt.py +76 -1
  46. langchain/chains/sequential.py +3 -7
  47. langchain/chains/structured_output/base.py +1 -1
  48. langchain/chat_models/base.py +8 -10
  49. langchain/evaluation/agents/trajectory_eval_chain.py +2 -4
  50. langchain/evaluation/comparison/eval_chain.py +2 -4
  51. langchain/evaluation/criteria/eval_chain.py +2 -4
  52. langchain/evaluation/embedding_distance/base.py +0 -2
  53. langchain/evaluation/parsing/json_schema.py +1 -1
  54. langchain/evaluation/qa/eval_chain.py +2 -7
  55. langchain/evaluation/schema.py +8 -8
  56. langchain/evaluation/scoring/eval_chain.py +2 -4
  57. langchain/evaluation/string_distance/base.py +4 -4
  58. langchain/hub.py +60 -26
  59. langchain/indexes/vectorstore.py +3 -7
  60. langchain/memory/entity.py +0 -2
  61. langchain/memory/summary.py +9 -0
  62. langchain/output_parsers/retry.py +1 -1
  63. langchain/retrievers/contextual_compression.py +0 -2
  64. langchain/retrievers/document_compressors/base.py +0 -2
  65. langchain/retrievers/document_compressors/chain_filter.py +1 -1
  66. langchain/retrievers/document_compressors/cohere_rerank.py +2 -4
  67. langchain/retrievers/document_compressors/cross_encoder_rerank.py +1 -4
  68. langchain/retrievers/document_compressors/embeddings_filter.py +0 -2
  69. langchain/retrievers/document_compressors/listwise_rerank.py +1 -1
  70. langchain/retrievers/multi_query.py +4 -2
  71. langchain/retrievers/re_phraser.py +1 -1
  72. langchain/retrievers/self_query/base.py +1 -3
  73. langchain/retrievers/time_weighted_retriever.py +0 -2
  74. {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/METADATA +2 -2
  75. {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/RECORD +78 -78
  76. {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/LICENSE +0 -0
  77. {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/WHEEL +0 -0
  78. {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/entry_points.txt +0 -0
@@ -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 langchain_core.pydantic_v1 import Extra, Field
13
+ from langchain_core.pydantic_v1 import Field
14
14
 
15
15
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
16
16
  from langchain.chains.llm import LLMChain
@@ -192,9 +192,7 @@ class PairwiseStringEvalChain(PairwiseStringEvaluator, LLMEvalChain, LLMChain):
192
192
  return False
193
193
 
194
194
  class Config:
195
- """Configuration for the PairwiseStringEvalChain."""
196
-
197
- extra = Extra.ignore
195
+ extra = "ignore"
198
196
 
199
197
  @property
200
198
  def requires_reference(self) -> bool:
@@ -8,7 +8,7 @@ from langchain_core.callbacks.manager import Callbacks
8
8
  from langchain_core.language_models import BaseLanguageModel
9
9
  from langchain_core.output_parsers import BaseOutputParser
10
10
  from langchain_core.prompts import BasePromptTemplate
11
- from langchain_core.pydantic_v1 import Extra, Field
11
+ from langchain_core.pydantic_v1 import Field
12
12
 
13
13
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
14
14
  from langchain.chains.llm import LLMChain
@@ -237,9 +237,7 @@ class CriteriaEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
237
237
  return False
238
238
 
239
239
  class Config:
240
- """Configuration for the QAEvalChain."""
241
-
242
- extra = Extra.ignore
240
+ extra = "ignore"
243
241
 
244
242
  @property
245
243
  def requires_reference(self) -> bool:
@@ -114,8 +114,6 @@ class _EmbeddingDistanceChainMixin(Chain):
114
114
  return values
115
115
 
116
116
  class Config:
117
- """Permit embeddings to go unvalidated."""
118
-
119
117
  arbitrary_types_allowed: bool = True
120
118
 
121
119
  @property
@@ -36,7 +36,7 @@ class JsonSchemaEvaluator(StringEvaluator):
36
36
  """Initializes the JsonSchemaEvaluator.
37
37
 
38
38
  Args:
39
- **kwargs: Additional keyword arguments.
39
+ kwargs: Additional keyword arguments.
40
40
 
41
41
  Raises:
42
42
  ImportError: If the jsonschema package is not installed.
@@ -9,7 +9,6 @@ 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 langchain_core.pydantic_v1 import Extra
13
12
 
14
13
  from langchain.chains.llm import LLMChain
15
14
  from langchain.evaluation.qa.eval_prompt import CONTEXT_PROMPT, COT_PROMPT, PROMPT
@@ -74,9 +73,7 @@ class QAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
74
73
  output_key: str = "results" #: :meta private:
75
74
 
76
75
  class Config:
77
- """Configuration for the QAEvalChain."""
78
-
79
- extra = Extra.ignore
76
+ extra = "ignore"
80
77
 
81
78
  @classmethod
82
79
  def is_lc_serializable(cls) -> bool:
@@ -224,9 +221,7 @@ class ContextQAEvalChain(LLMChain, StringEvaluator, LLMEvalChain):
224
221
  return True
225
222
 
226
223
  class Config:
227
- """Configuration for the QAEvalChain."""
228
-
229
- extra = Extra.ignore
224
+ extra = "ignore"
230
225
 
231
226
  @classmethod
232
227
  def _validate_input_vars(cls, prompt: PromptTemplate) -> None:
@@ -158,7 +158,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
158
158
  prediction (str): The LLM or chain prediction to evaluate.
159
159
  reference (Optional[str], optional): The reference label to evaluate against.
160
160
  input (Optional[str], optional): The input to consider during evaluation.
161
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
161
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
162
162
  Returns:
163
163
  dict: The evaluation results containing the score or value.
164
164
  It is recommended that the dictionary contain the following keys:
@@ -181,7 +181,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
181
181
  prediction (str): The LLM or chain prediction to evaluate.
182
182
  reference (Optional[str], optional): The reference label to evaluate against.
183
183
  input (Optional[str], optional): The input to consider during evaluation.
184
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
184
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
185
185
  Returns:
186
186
  dict: The evaluation results containing the score or value.
187
187
  It is recommended that the dictionary contain the following keys:
@@ -212,7 +212,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
212
212
  prediction (str): The LLM or chain prediction to evaluate.
213
213
  reference (Optional[str], optional): The reference label to evaluate against.
214
214
  input (Optional[str], optional): The input to consider during evaluation.
215
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
215
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
216
216
  Returns:
217
217
  dict: The evaluation results containing the score or value.
218
218
  """ # noqa: E501
@@ -235,7 +235,7 @@ class StringEvaluator(_EvalArgsMixin, ABC):
235
235
  prediction (str): The LLM or chain prediction to evaluate.
236
236
  reference (Optional[str], optional): The reference label to evaluate against.
237
237
  input (Optional[str], optional): The input to consider during evaluation.
238
- **kwargs: Additional keyword arguments, including callbacks, tags, etc.
238
+ kwargs: Additional keyword arguments, including callbacks, tags, etc.
239
239
  Returns:
240
240
  dict: The evaluation results containing the score or value.
241
241
  """ # noqa: E501
@@ -265,7 +265,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
265
265
  prediction_b (str): The output string from the second model.
266
266
  reference (Optional[str], optional): The expected output / reference string.
267
267
  input (Optional[str], optional): The input string.
268
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
268
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
269
269
  Returns:
270
270
  dict: A dictionary containing the preference, scores, and/or other information.
271
271
  """ # noqa: E501
@@ -286,7 +286,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
286
286
  prediction_b (str): The output string from the second model.
287
287
  reference (Optional[str], optional): The expected output / reference string.
288
288
  input (Optional[str], optional): The input string.
289
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
289
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
290
290
  Returns:
291
291
  dict: A dictionary containing the preference, scores, and/or other information.
292
292
  """ # noqa: E501
@@ -316,7 +316,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
316
316
  prediction_b (str): The output string from the second model.
317
317
  reference (Optional[str], optional): The expected output / reference string.
318
318
  input (Optional[str], optional): The input string.
319
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
319
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
320
320
  Returns:
321
321
  dict: A dictionary containing the preference, scores, and/or other information.
322
322
  """ # noqa: E501
@@ -345,7 +345,7 @@ class PairwiseStringEvaluator(_EvalArgsMixin, ABC):
345
345
  prediction_b (str): The output string from the second model.
346
346
  reference (Optional[str], optional): The expected output / reference string.
347
347
  input (Optional[str], optional): The input string.
348
- **kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
348
+ kwargs: Additional keyword arguments, such as callbacks and optional reference strings.
349
349
  Returns:
350
350
  dict: A dictionary containing the preference, scores, and/or other information.
351
351
  """ # noqa: E501
@@ -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 langchain_core.pydantic_v1 import Extra, Field
13
+ from langchain_core.pydantic_v1 import Field
14
14
 
15
15
  from langchain.chains.constitutional_ai.models import ConstitutionalPrinciple
16
16
  from langchain.chains.llm import LLMChain
@@ -180,9 +180,7 @@ class ScoreStringEvalChain(StringEvaluator, LLMEvalChain, LLMChain):
180
180
  """The name of the criterion being evaluated."""
181
181
 
182
182
  class Config:
183
- """Configuration for the ScoreStringEvalChain."""
184
-
185
- extra = Extra.ignore
183
+ extra = "ignore"
186
184
 
187
185
  @classmethod
188
186
  def is_lc_serializable(cls) -> bool:
@@ -278,7 +278,7 @@ class StringDistanceEvalChain(StringEvaluator, _RapidFuzzChainMixin):
278
278
  reference (Optional[str], optional): The reference string.
279
279
  input (Optional[str], optional): The input string.
280
280
  callbacks (Callbacks, optional): The callbacks to use.
281
- **kwargs: Additional keyword arguments.
281
+ kwargs: Additional keyword arguments.
282
282
 
283
283
  Returns:
284
284
  dict: The evaluation results containing the score.
@@ -314,7 +314,7 @@ class StringDistanceEvalChain(StringEvaluator, _RapidFuzzChainMixin):
314
314
  reference (Optional[str], optional): The reference string.
315
315
  input (Optional[str], optional): The input string.
316
316
  callbacks (Callbacks, optional): The callbacks to use.
317
- **kwargs: Additional keyword arguments.
317
+ kwargs: Additional keyword arguments.
318
318
 
319
319
  Returns:
320
320
  dict: The evaluation results containing the score.
@@ -412,7 +412,7 @@ class PairwiseStringDistanceEvalChain(PairwiseStringEvaluator, _RapidFuzzChainMi
412
412
  callbacks (Callbacks, optional): The callbacks to use.
413
413
  tags (List[str], optional): Tags to apply to traces.
414
414
  metadata (Dict[str, Any], optional): Metadata to apply to traces.
415
- **kwargs: Additional keyword arguments.
415
+ kwargs: Additional keyword arguments.
416
416
 
417
417
  Returns:
418
418
  dict: The evaluation results containing the score.
@@ -446,7 +446,7 @@ class PairwiseStringDistanceEvalChain(PairwiseStringEvaluator, _RapidFuzzChainMi
446
446
  callbacks (Callbacks, optional): The callbacks to use.
447
447
  tags (List[str], optional): Tags to apply to traces.
448
448
  metadata (Dict[str, Any], optional): Metadata to apply to traces.
449
- **kwargs: Additional keyword arguments.
449
+ kwargs: Additional keyword arguments.
450
450
 
451
451
  Returns:
452
452
  dict: The evaluation results containing the score.
langchain/hub.py CHANGED
@@ -3,27 +3,37 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import json
6
- from typing import TYPE_CHECKING, Any, Optional
6
+ from typing import Any, Optional, Sequence
7
7
 
8
8
  from langchain_core.load.dump import dumps
9
9
  from langchain_core.load.load import loads
10
10
  from langchain_core.prompts import BasePromptTemplate
11
11
 
12
- if TYPE_CHECKING:
13
- from langchainhub import Client
14
12
 
15
-
16
- def _get_client(api_url: Optional[str] = None, api_key: Optional[str] = None) -> Client:
13
+ def _get_client(
14
+ api_key: Optional[str] = None,
15
+ api_url: Optional[str] = None,
16
+ ) -> Any:
17
17
  try:
18
- from langchainhub import Client
19
- except ImportError as e:
20
- raise ImportError(
21
- "Could not import langchainhub, please install with `pip install "
22
- "langchainhub`."
23
- ) from e
18
+ from langsmith import Client as LangSmithClient
19
+
20
+ ls_client = LangSmithClient(api_url, api_key=api_key)
21
+ if hasattr(ls_client, "push_prompt") and hasattr(ls_client, "pull_prompt"):
22
+ return ls_client
23
+ else:
24
+ from langchainhub import Client as LangChainHubClient
24
25
 
25
- # Client logic will also attempt to load URL/key from environment variables
26
- return Client(api_url, api_key=api_key)
26
+ return LangChainHubClient(api_url, api_key=api_key)
27
+ except ImportError:
28
+ try:
29
+ from langchainhub import Client as LangChainHubClient
30
+
31
+ return LangChainHubClient(api_url, api_key=api_key)
32
+ except ImportError as e:
33
+ raise ImportError(
34
+ "Could not import langsmith or langchainhub (deprecated),"
35
+ "please install with `pip install langsmith`."
36
+ ) from e
27
37
 
28
38
 
29
39
  def push(
@@ -32,27 +42,43 @@ def push(
32
42
  *,
33
43
  api_url: Optional[str] = None,
34
44
  api_key: Optional[str] = None,
35
- parent_commit_hash: Optional[str] = "latest",
36
- new_repo_is_public: bool = True,
37
- new_repo_description: str = "",
45
+ parent_commit_hash: Optional[str] = None,
46
+ new_repo_is_public: bool = False,
47
+ new_repo_description: Optional[str] = None,
48
+ readme: Optional[str] = None,
49
+ tags: Optional[Sequence[str]] = None,
38
50
  ) -> str:
39
51
  """
40
52
  Push an object to the hub and returns the URL it can be viewed at in a browser.
41
53
 
42
- :param repo_full_name: The full name of the repo to push to in the format of
43
- `owner/repo`.
54
+ :param repo_full_name: The full name of the prompt to push to in the format of
55
+ `owner/prompt_name` or `prompt_name`.
44
56
  :param object: The LangChain to serialize and push to the hub.
45
57
  :param api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
46
58
  if you have an api key set, or a localhost instance if not.
47
59
  :param api_key: The API key to use to authenticate with the LangChain Hub API.
48
60
  :param parent_commit_hash: The commit hash of the parent commit to push to. Defaults
49
61
  to the latest commit automatically.
50
- :param new_repo_is_public: Whether the repo should be public. Defaults to
51
- True (Public by default).
52
- :param new_repo_description: The description of the repo. Defaults to an empty
62
+ :param new_repo_is_public: Whether the prompt should be public. Defaults to
63
+ False (Private by default).
64
+ :param new_repo_description: The description of the prompt. Defaults to an empty
53
65
  string.
54
66
  """
55
- client = _get_client(api_url=api_url, api_key=api_key)
67
+ client = _get_client(api_key=api_key, api_url=api_url)
68
+
69
+ # Then it's langsmith
70
+ if hasattr(client, "push_prompt"):
71
+ return client.push_prompt(
72
+ repo_full_name,
73
+ object=object,
74
+ parent_commit_hash=parent_commit_hash,
75
+ is_public=new_repo_is_public,
76
+ description=new_repo_description,
77
+ readme=readme,
78
+ tags=tags,
79
+ )
80
+
81
+ # Then it's langchainhub
56
82
  manifest_json = dumps(object)
57
83
  message = client.push(
58
84
  repo_full_name,
@@ -67,20 +93,28 @@ def push(
67
93
  def pull(
68
94
  owner_repo_commit: str,
69
95
  *,
96
+ include_model: Optional[bool] = None,
70
97
  api_url: Optional[str] = None,
71
98
  api_key: Optional[str] = None,
72
99
  ) -> Any:
73
100
  """
74
101
  Pull an object from the hub and returns it as a LangChain object.
75
102
 
76
- :param owner_repo_commit: The full name of the repo to pull from in the format of
77
- `owner/repo:commit_hash`.
103
+ :param owner_repo_commit: The full name of the prompt to pull from in the format of
104
+ `owner/prompt_name:commit_hash` or `owner/prompt_name`
105
+ or just `prompt_name` if it's your own prompt.
78
106
  :param api_url: The URL of the LangChain Hub API. Defaults to the hosted API service
79
107
  if you have an api key set, or a localhost instance if not.
80
108
  :param api_key: The API key to use to authenticate with the LangChain Hub API.
81
109
  """
82
- client = _get_client(api_url=api_url, api_key=api_key)
110
+ client = _get_client(api_key=api_key, api_url=api_url)
111
+
112
+ # Then it's langsmith
113
+ if hasattr(client, "pull_prompt"):
114
+ response = client.pull_prompt(owner_repo_commit, include_model=include_model)
115
+ return response
83
116
 
117
+ # Then it's langchainhub
84
118
  if hasattr(client, "pull_repo"):
85
119
  # >= 0.1.15
86
120
  res_dict = client.pull_repo(owner_repo_commit)
@@ -93,6 +127,6 @@ def pull(
93
127
  obj.metadata["lc_hub_commit_hash"] = res_dict["commit_hash"]
94
128
  return obj
95
129
 
96
- # Then it's < 0.1.15
130
+ # Then it's < 0.1.15 langchainhub
97
131
  resp: str = client.pull(owner_repo_commit)
98
132
  return loads(resp)
@@ -4,7 +4,7 @@ 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, Extra, Field
7
+ from langchain_core.pydantic_v1 import BaseModel, Field
8
8
  from langchain_core.vectorstores import VectorStore
9
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter, TextSplitter
10
10
 
@@ -22,10 +22,8 @@ class VectorStoreIndexWrapper(BaseModel):
22
22
  vectorstore: VectorStore
23
23
 
24
24
  class Config:
25
- """Configuration for this pydantic object."""
26
-
27
- extra = Extra.forbid
28
25
  arbitrary_types_allowed = True
26
+ extra = "forbid"
29
27
 
30
28
  def query(
31
29
  self,
@@ -145,10 +143,8 @@ class VectorstoreIndexCreator(BaseModel):
145
143
  vectorstore_kwargs: dict = Field(default_factory=dict)
146
144
 
147
145
  class Config:
148
- """Configuration for this pydantic object."""
149
-
150
- extra = Extra.forbid
151
146
  arbitrary_types_allowed = True
147
+ extra = "forbid"
152
148
 
153
149
  def from_loaders(self, loaders: List[BaseLoader]) -> VectorStoreIndexWrapper:
154
150
  """Create a vectorstore index from loaders."""
@@ -246,8 +246,6 @@ class SQLiteEntityStore(BaseEntityStore):
246
246
  conn: Any = None
247
247
 
248
248
  class Config:
249
- """Configuration for this pydantic object."""
250
-
251
249
  arbitrary_types_allowed = True
252
250
 
253
251
  def __init__(
@@ -2,6 +2,7 @@ from __future__ import annotations
2
2
 
3
3
  from typing import Any, Dict, List, Type
4
4
 
5
+ from langchain_core._api import deprecated
5
6
  from langchain_core.chat_history import BaseChatMessageHistory
6
7
  from langchain_core.language_models import BaseLanguageModel
7
8
  from langchain_core.messages import BaseMessage, SystemMessage, get_buffer_string
@@ -14,6 +15,14 @@ from langchain.memory.chat_memory import BaseChatMemory
14
15
  from langchain.memory.prompt import SUMMARY_PROMPT
15
16
 
16
17
 
18
+ @deprecated(
19
+ since="0.2.12",
20
+ removal="1.0",
21
+ message=(
22
+ "Refer here for how to incorporate summaries of conversation history: "
23
+ "https://langchain-ai.github.io/langgraph/how-tos/memory/add-summary-conversation-history/" # noqa: E501
24
+ ),
25
+ )
17
26
  class SummarizerMixin(BaseModel):
18
27
  """Mixin for summarizer."""
19
28
 
@@ -214,7 +214,7 @@ class RetryWithErrorOutputParser(BaseOutputParser[T]):
214
214
  Returns:
215
215
  A RetryWithErrorOutputParser.
216
216
  """
217
- chain = prompt | llm
217
+ chain = prompt | llm | StrOutputParser()
218
218
  return cls(parser=parser, retry_chain=chain, max_retries=max_retries)
219
219
 
220
220
  def parse_with_prompt(self, completion: str, prompt_value: PromptValue) -> T:
@@ -22,8 +22,6 @@ class ContextualCompressionRetriever(BaseRetriever):
22
22
  """Base Retriever to use for getting relevant documents."""
23
23
 
24
24
  class Config:
25
- """Configuration for this pydantic object."""
26
-
27
25
  arbitrary_types_allowed = True
28
26
 
29
27
  def _get_relevant_documents(
@@ -16,8 +16,6 @@ class DocumentCompressorPipeline(BaseDocumentCompressor):
16
16
  """List of document filters that are chained together and run in sequence."""
17
17
 
18
18
  class Config:
19
- """Configuration for this pydantic object."""
20
-
21
19
  arbitrary_types_allowed = True
22
20
 
23
21
  def compress_documents(
@@ -104,7 +104,7 @@ class LLMChainFilter(BaseDocumentCompressor):
104
104
  Args:
105
105
  llm: The language model to use for filtering.
106
106
  prompt: The prompt to use for the filter.
107
- **kwargs: Additional arguments to pass to the constructor.
107
+ kwargs: Additional arguments to pass to the constructor.
108
108
 
109
109
  Returns:
110
110
  A LLMChainFilter that uses the given language model.
@@ -6,7 +6,7 @@ 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 Extra, root_validator
9
+ from langchain_core.pydantic_v1 import root_validator
10
10
  from langchain_core.utils import get_from_dict_or_env
11
11
 
12
12
  from langchain.retrievers.document_compressors.base import BaseDocumentCompressor
@@ -31,10 +31,8 @@ class CohereRerank(BaseDocumentCompressor):
31
31
  """Identifier for the application making the request."""
32
32
 
33
33
  class Config:
34
- """Configuration for this pydantic object."""
35
-
36
- extra = Extra.forbid
37
34
  arbitrary_types_allowed = True
35
+ extra = "forbid"
38
36
 
39
37
  @root_validator(pre=True)
40
38
  def validate_environment(cls, values: Dict) -> Dict:
@@ -5,7 +5,6 @@ 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 langchain_core.pydantic_v1 import Extra
9
8
 
10
9
  from langchain.retrievers.document_compressors.cross_encoder import BaseCrossEncoder
11
10
 
@@ -20,10 +19,8 @@ class CrossEncoderReranker(BaseDocumentCompressor):
20
19
  """Number of documents to return."""
21
20
 
22
21
  class Config:
23
- """Configuration for this pydantic object."""
24
-
25
- extra = Extra.forbid
26
22
  arbitrary_types_allowed = True
23
+ extra = "forbid"
27
24
 
28
25
  def compress_documents(
29
26
  self,
@@ -42,8 +42,6 @@ class EmbeddingsFilter(BaseDocumentCompressor):
42
42
  to None."""
43
43
 
44
44
  class Config:
45
- """Configuration for this pydantic object."""
46
-
47
45
  arbitrary_types_allowed = True
48
46
 
49
47
  @pre_init
@@ -105,7 +105,7 @@ class LLMListwiseRerank(BaseDocumentCompressor):
105
105
  llm: The language model to use for filtering. **Must implement
106
106
  BaseLanguageModel.with_structured_output().**
107
107
  prompt: The prompt to use for the filter.
108
- **kwargs: Additional arguments to pass to the constructor.
108
+ kwargs: Additional arguments to pass to the constructor.
109
109
 
110
110
  Returns:
111
111
  A LLMListwiseRerank document compressor that uses the given language model.
@@ -72,6 +72,8 @@ class MultiQueryRetriever(BaseRetriever):
72
72
  Args:
73
73
  retriever: retriever to query documents from
74
74
  llm: llm for query generation using DEFAULT_QUERY_PROMPT
75
+ prompt: The prompt which aims to generate several different versions
76
+ of the given user query
75
77
  include_original: Whether to include the original query in the list of
76
78
  generated queries.
77
79
 
@@ -95,7 +97,7 @@ class MultiQueryRetriever(BaseRetriever):
95
97
  """Get relevant documents given a user query.
96
98
 
97
99
  Args:
98
- question: user query
100
+ query: user query
99
101
 
100
102
  Returns:
101
103
  Unique union of relevant documents from all generated queries
@@ -158,7 +160,7 @@ class MultiQueryRetriever(BaseRetriever):
158
160
  """Get relevant documents given a user query.
159
161
 
160
162
  Args:
161
- question: user query
163
+ query: user query
162
164
 
163
165
  Returns:
164
166
  Unique union of relevant documents from all generated queries
@@ -64,7 +64,7 @@ class RePhraseQueryRetriever(BaseRetriever):
64
64
  *,
65
65
  run_manager: CallbackManagerForRetrieverRun,
66
66
  ) -> List[Document]:
67
- """Get relevated documents given a user question.
67
+ """Get relevant documents given a user question.
68
68
 
69
69
  Args:
70
70
  query: user question
@@ -215,10 +215,8 @@ class SelfQueryRetriever(BaseRetriever):
215
215
  """Use original query instead of the revised new query from LLM"""
216
216
 
217
217
  class Config:
218
- """Configuration for this pydantic object."""
219
-
220
- arbitrary_types_allowed = True
221
218
  allow_population_by_field_name = True
219
+ arbitrary_types_allowed = True
222
220
 
223
221
  @root_validator(pre=True)
224
222
  def validate_translator(cls, values: Dict) -> Dict:
@@ -47,8 +47,6 @@ class TimeWeightedVectorStoreRetriever(BaseRetriever):
47
47
  """
48
48
 
49
49
  class Config:
50
- """Configuration for this pydantic object."""
51
-
52
50
  arbitrary_types_allowed = True
53
51
 
54
52
  def _document_get_date(self, field: str, document: Document) -> datetime.datetime:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: langchain
3
- Version: 0.2.12
3
+ Version: 0.2.13
4
4
  Summary: Building applications with LLMs through composability
5
5
  Home-page: https://github.com/langchain-ai/langchain
6
6
  License: MIT
@@ -15,7 +15,7 @@ Requires-Dist: PyYAML (>=5.3)
15
15
  Requires-Dist: SQLAlchemy (>=1.4,<3)
16
16
  Requires-Dist: aiohttp (>=3.8.3,<4.0.0)
17
17
  Requires-Dist: async-timeout (>=4.0.0,<5.0.0) ; python_version < "3.11"
18
- Requires-Dist: langchain-core (>=0.2.27,<0.3.0)
18
+ Requires-Dist: langchain-core (>=0.2.30,<0.3.0)
19
19
  Requires-Dist: langchain-text-splitters (>=0.2.0,<0.3.0)
20
20
  Requires-Dist: langsmith (>=0.1.17,<0.2.0)
21
21
  Requires-Dist: numpy (>=1,<2) ; python_version < "3.12"