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.
- langchain/agents/agent.py +5 -9
- langchain/agents/agent_toolkits/vectorstore/base.py +114 -2
- langchain/agents/agent_toolkits/vectorstore/toolkit.py +0 -6
- langchain/agents/initialize.py +1 -1
- langchain/agents/loading.py +2 -2
- langchain/agents/mrkl/base.py +1 -1
- langchain/agents/openai_assistant/base.py +2 -2
- langchain/agents/openai_functions_agent/base.py +1 -1
- langchain/agents/openai_functions_multi_agent/base.py +1 -1
- langchain/chains/__init__.py +1 -0
- langchain/chains/api/base.py +121 -1
- langchain/chains/base.py +0 -2
- langchain/chains/combine_documents/map_reduce.py +2 -4
- langchain/chains/combine_documents/map_rerank.py +4 -6
- langchain/chains/combine_documents/reduce.py +1 -4
- langchain/chains/combine_documents/refine.py +2 -4
- langchain/chains/combine_documents/stuff.py +12 -4
- langchain/chains/conversation/base.py +2 -4
- langchain/chains/conversational_retrieval/base.py +4 -6
- langchain/chains/elasticsearch_database/base.py +16 -20
- langchain/chains/example_generator.py +3 -4
- langchain/chains/flare/base.py +1 -1
- langchain/chains/hyde/base.py +1 -4
- langchain/chains/llm.py +2 -4
- langchain/chains/llm_checker/base.py +12 -4
- langchain/chains/llm_math/base.py +2 -4
- langchain/chains/llm_summarization_checker/base.py +12 -4
- langchain/chains/loading.py +17 -0
- langchain/chains/mapreduce.py +12 -4
- langchain/chains/natbot/base.py +2 -4
- langchain/chains/openai_functions/__init__.py +2 -0
- langchain/chains/openai_functions/citation_fuzzy_match.py +54 -1
- langchain/chains/openai_functions/openapi.py +88 -1
- langchain/chains/openai_functions/qa_with_structure.py +19 -0
- langchain/chains/openai_functions/tagging.py +81 -0
- langchain/chains/qa_with_sources/base.py +21 -4
- langchain/chains/qa_with_sources/loading.py +16 -0
- langchain/chains/query_constructor/base.py +8 -2
- langchain/chains/query_constructor/schema.py +0 -2
- langchain/chains/question_answering/chain.py +15 -0
- langchain/chains/retrieval_qa/base.py +30 -6
- langchain/chains/router/base.py +1 -4
- langchain/chains/router/embedding_router.py +1 -4
- langchain/chains/router/llm_router.py +76 -1
- langchain/chains/router/multi_prompt.py +76 -1
- langchain/chains/sequential.py +3 -7
- langchain/chains/structured_output/base.py +1 -1
- langchain/chat_models/base.py +8 -10
- langchain/evaluation/agents/trajectory_eval_chain.py +2 -4
- langchain/evaluation/comparison/eval_chain.py +2 -4
- langchain/evaluation/criteria/eval_chain.py +2 -4
- langchain/evaluation/embedding_distance/base.py +0 -2
- langchain/evaluation/parsing/json_schema.py +1 -1
- langchain/evaluation/qa/eval_chain.py +2 -7
- langchain/evaluation/schema.py +8 -8
- langchain/evaluation/scoring/eval_chain.py +2 -4
- langchain/evaluation/string_distance/base.py +4 -4
- langchain/hub.py +60 -26
- langchain/indexes/vectorstore.py +3 -7
- langchain/memory/entity.py +0 -2
- langchain/memory/summary.py +9 -0
- langchain/output_parsers/retry.py +1 -1
- langchain/retrievers/contextual_compression.py +0 -2
- langchain/retrievers/document_compressors/base.py +0 -2
- langchain/retrievers/document_compressors/chain_filter.py +1 -1
- langchain/retrievers/document_compressors/cohere_rerank.py +2 -4
- langchain/retrievers/document_compressors/cross_encoder_rerank.py +1 -4
- langchain/retrievers/document_compressors/embeddings_filter.py +0 -2
- langchain/retrievers/document_compressors/listwise_rerank.py +1 -1
- langchain/retrievers/multi_query.py +4 -2
- langchain/retrievers/re_phraser.py +1 -1
- langchain/retrievers/self_query/base.py +1 -3
- langchain/retrievers/time_weighted_retriever.py +0 -2
- {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/METADATA +2 -2
- {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/RECORD +78 -78
- {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/LICENSE +0 -0
- {langchain-0.2.12.dist-info → langchain-0.2.13.dist-info}/WHEEL +0 -0
- {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
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
extra = Extra.ignore
|
|
240
|
+
extra = "ignore"
|
|
243
241
|
|
|
244
242
|
@property
|
|
245
243
|
def requires_reference(self) -> bool:
|
|
@@ -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
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
extra = Extra.ignore
|
|
224
|
+
extra = "ignore"
|
|
230
225
|
|
|
231
226
|
@classmethod
|
|
232
227
|
def _validate_input_vars(cls, prompt: PromptTemplate) -> None:
|
langchain/evaluation/schema.py
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
13
|
+
def _get_client(
|
|
14
|
+
api_key: Optional[str] = None,
|
|
15
|
+
api_url: Optional[str] = None,
|
|
16
|
+
) -> Any:
|
|
17
17
|
try:
|
|
18
|
-
from
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
26
|
-
|
|
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] =
|
|
36
|
-
new_repo_is_public: bool =
|
|
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
|
|
43
|
-
`owner/
|
|
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
|
|
51
|
-
|
|
52
|
-
:param new_repo_description: The description of the
|
|
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(
|
|
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
|
|
77
|
-
`owner/
|
|
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(
|
|
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)
|
langchain/indexes/vectorstore.py
CHANGED
|
@@ -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,
|
|
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."""
|
langchain/memory/entity.py
CHANGED
langchain/memory/summary.py
CHANGED
|
@@ -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:
|
|
@@ -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
|
-
|
|
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
|
|
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,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: langchain
|
|
3
|
-
Version: 0.2.
|
|
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.
|
|
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"
|