langchain 0.2.5__py3-none-any.whl → 0.2.7__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/__init__.py +1 -0
- langchain/_api/module_import.py +2 -2
- langchain/agents/__init__.py +5 -4
- langchain/agents/agent.py +272 -50
- langchain/agents/agent_iterator.py +20 -0
- langchain/agents/agent_toolkits/__init__.py +1 -0
- langchain/agents/agent_toolkits/file_management/__init__.py +1 -0
- langchain/agents/agent_toolkits/playwright/__init__.py +1 -0
- langchain/agents/agent_toolkits/vectorstore/base.py +1 -0
- langchain/agents/agent_toolkits/vectorstore/toolkit.py +1 -0
- langchain/agents/agent_types.py +1 -0
- langchain/agents/chat/base.py +37 -1
- langchain/agents/chat/output_parser.py +14 -0
- langchain/agents/conversational/base.py +38 -6
- langchain/agents/conversational/output_parser.py +10 -0
- langchain/agents/conversational_chat/base.py +42 -3
- langchain/agents/format_scratchpad/__init__.py +1 -0
- langchain/agents/format_scratchpad/log.py +12 -1
- langchain/agents/format_scratchpad/log_to_messages.py +10 -1
- langchain/agents/format_scratchpad/openai_functions.py +10 -5
- langchain/agents/format_scratchpad/tools.py +11 -7
- langchain/agents/initialize.py +15 -7
- langchain/agents/json_chat/base.py +9 -3
- langchain/agents/loading.py +7 -0
- langchain/agents/mrkl/base.py +39 -10
- langchain/agents/mrkl/output_parser.py +12 -0
- langchain/agents/openai_assistant/base.py +37 -14
- langchain/agents/openai_functions_agent/agent_token_buffer_memory.py +32 -4
- langchain/agents/openai_functions_agent/base.py +61 -10
- langchain/agents/openai_functions_multi_agent/base.py +22 -7
- langchain/agents/openai_tools/base.py +3 -0
- langchain/agents/output_parsers/__init__.py +1 -0
- langchain/agents/react/base.py +1 -0
- langchain/agents/self_ask_with_search/base.py +1 -0
- langchain/agents/structured_chat/output_parser.py +3 -3
- langchain/agents/tool_calling_agent/base.py +13 -3
- langchain/agents/tools.py +3 -0
- langchain/agents/utils.py +9 -1
- langchain/base_language.py +1 -0
- langchain/callbacks/__init__.py +1 -0
- langchain/callbacks/base.py +1 -0
- langchain/callbacks/streaming_stdout.py +1 -0
- langchain/callbacks/streaming_stdout_final_only.py +1 -0
- langchain/callbacks/tracers/evaluation.py +1 -0
- langchain/chains/api/base.py +5 -2
- langchain/chains/base.py +1 -1
- langchain/chains/combine_documents/base.py +59 -0
- langchain/chains/combine_documents/map_reduce.py +4 -2
- langchain/chains/combine_documents/map_rerank.py +5 -3
- langchain/chains/combine_documents/refine.py +4 -2
- langchain/chains/combine_documents/stuff.py +1 -0
- langchain/chains/constitutional_ai/base.py +1 -0
- langchain/chains/constitutional_ai/models.py +1 -0
- langchain/chains/constitutional_ai/principles.py +1 -0
- langchain/chains/conversation/base.py +81 -1
- langchain/chains/conversational_retrieval/base.py +2 -1
- langchain/chains/elasticsearch_database/base.py +2 -1
- langchain/chains/hyde/base.py +1 -0
- langchain/chains/llm.py +4 -2
- langchain/chains/llm_checker/base.py +4 -3
- langchain/chains/llm_math/base.py +1 -0
- langchain/chains/loading.py +2 -1
- langchain/chains/mapreduce.py +1 -0
- langchain/chains/moderation.py +1 -1
- langchain/chains/natbot/base.py +1 -0
- langchain/chains/openai_functions/base.py +1 -0
- langchain/chains/openai_functions/extraction.py +6 -6
- langchain/chains/openai_tools/extraction.py +3 -3
- langchain/chains/qa_generation/base.py +47 -1
- langchain/chains/qa_with_sources/__init__.py +1 -0
- langchain/chains/qa_with_sources/loading.py +1 -0
- langchain/chains/qa_with_sources/vector_db.py +1 -1
- langchain/chains/query_constructor/base.py +1 -0
- langchain/chains/query_constructor/ir.py +1 -0
- langchain/chains/question_answering/chain.py +1 -0
- langchain/chains/retrieval_qa/base.py +3 -2
- langchain/chains/router/base.py +1 -0
- langchain/chains/router/llm_router.py +2 -1
- langchain/chains/router/multi_prompt.py +1 -0
- langchain/chains/router/multi_retrieval_qa.py +1 -0
- langchain/chains/sequential.py +2 -1
- langchain/chains/structured_output/base.py +12 -12
- langchain/chains/summarize/chain.py +1 -0
- langchain/chains/transform.py +4 -3
- langchain/chat_models/__init__.py +1 -0
- langchain/chat_models/base.py +2 -2
- langchain/docstore/__init__.py +1 -0
- langchain/document_loaders/__init__.py +1 -0
- langchain/document_transformers/__init__.py +1 -0
- langchain/embeddings/__init__.py +0 -1
- langchain/evaluation/__init__.py +2 -1
- langchain/evaluation/agents/__init__.py +1 -0
- langchain/evaluation/agents/trajectory_eval_prompt.py +1 -0
- langchain/evaluation/comparison/__init__.py +1 -0
- langchain/evaluation/comparison/eval_chain.py +1 -0
- langchain/evaluation/comparison/prompt.py +1 -0
- langchain/evaluation/embedding_distance/__init__.py +1 -0
- langchain/evaluation/embedding_distance/base.py +1 -0
- langchain/evaluation/loading.py +1 -0
- langchain/evaluation/parsing/base.py +1 -0
- langchain/evaluation/qa/__init__.py +1 -0
- langchain/evaluation/qa/eval_chain.py +1 -0
- langchain/evaluation/qa/generate_chain.py +1 -0
- langchain/evaluation/schema.py +1 -0
- langchain/evaluation/scoring/__init__.py +1 -0
- langchain/evaluation/scoring/eval_chain.py +1 -0
- langchain/evaluation/scoring/prompt.py +1 -0
- langchain/evaluation/string_distance/__init__.py +1 -0
- langchain/example_generator.py +1 -0
- langchain/formatting.py +1 -0
- langchain/globals/__init__.py +1 -0
- langchain/graphs/__init__.py +1 -0
- langchain/indexes/__init__.py +1 -0
- langchain/indexes/_sql_record_manager.py +9 -5
- langchain/indexes/graph.py +1 -0
- langchain/indexes/prompts/__init__.py +1 -0
- langchain/input.py +1 -0
- langchain/llms/__init__.py +1 -0
- langchain/load/__init__.py +1 -0
- langchain/memory/__init__.py +5 -0
- langchain/memory/vectorstore_token_buffer_memory.py +184 -0
- langchain/output_parsers/__init__.py +1 -0
- langchain/output_parsers/combining.py +1 -1
- langchain/output_parsers/enum.py +7 -3
- langchain/output_parsers/fix.py +57 -16
- langchain/output_parsers/pandas_dataframe.py +1 -1
- langchain/output_parsers/regex.py +1 -1
- langchain/output_parsers/regex_dict.py +1 -1
- langchain/output_parsers/retry.py +76 -29
- langchain/output_parsers/structured.py +3 -3
- langchain/output_parsers/yaml.py +4 -0
- langchain/prompts/__init__.py +1 -0
- langchain/prompts/example_selector/__init__.py +1 -0
- langchain/python.py +1 -0
- langchain/requests.py +1 -0
- langchain/retrievers/__init__.py +1 -0
- langchain/retrievers/document_compressors/chain_extract.py +1 -0
- langchain/retrievers/document_compressors/chain_filter.py +1 -0
- langchain/retrievers/ensemble.py +18 -3
- langchain/retrievers/multi_query.py +2 -1
- langchain/retrievers/re_phraser.py +2 -1
- langchain/retrievers/self_query/base.py +9 -8
- langchain/schema/__init__.py +1 -0
- langchain/schema/runnable/__init__.py +1 -0
- langchain/serpapi.py +1 -0
- langchain/smith/__init__.py +6 -5
- langchain/smith/evaluation/__init__.py +0 -1
- langchain/smith/evaluation/string_run_evaluator.py +1 -0
- langchain/sql_database.py +1 -0
- langchain/storage/__init__.py +1 -0
- langchain/storage/_lc_store.py +1 -0
- langchain/storage/in_memory.py +1 -0
- langchain/text_splitter.py +1 -0
- langchain/tools/__init__.py +1 -0
- langchain/tools/amadeus/__init__.py +1 -0
- langchain/tools/azure_cognitive_services/__init__.py +1 -0
- langchain/tools/bing_search/__init__.py +1 -0
- langchain/tools/dataforseo_api_search/__init__.py +1 -0
- langchain/tools/ddg_search/__init__.py +1 -0
- langchain/tools/edenai/__init__.py +1 -0
- langchain/tools/eleven_labs/__init__.py +1 -0
- langchain/tools/file_management/__init__.py +1 -0
- langchain/tools/github/__init__.py +1 -1
- langchain/tools/gitlab/__init__.py +1 -1
- langchain/tools/gmail/__init__.py +1 -0
- langchain/tools/golden_query/__init__.py +1 -0
- langchain/tools/google_cloud/__init__.py +1 -0
- langchain/tools/google_finance/__init__.py +1 -0
- langchain/tools/google_jobs/__init__.py +1 -0
- langchain/tools/google_lens/__init__.py +1 -0
- langchain/tools/google_places/__init__.py +1 -0
- langchain/tools/google_scholar/__init__.py +1 -0
- langchain/tools/google_search/__init__.py +1 -0
- langchain/tools/google_trends/__init__.py +1 -0
- langchain/tools/human/__init__.py +1 -0
- langchain/tools/memorize/__init__.py +1 -0
- langchain/tools/metaphor_search/__init__.py +1 -0
- langchain/tools/multion/__init__.py +1 -0
- langchain/tools/office365/__init__.py +1 -0
- langchain/tools/openapi/utils/openapi_utils.py +1 -0
- langchain/tools/openweathermap/__init__.py +1 -0
- langchain/tools/playwright/__init__.py +1 -0
- langchain/tools/shell/__init__.py +1 -0
- langchain/tools/slack/__init__.py +1 -0
- langchain/tools/sql_database/prompt.py +1 -0
- langchain/tools/steamship_image_generation/__init__.py +1 -0
- langchain/tools/tavily_search/__init__.py +1 -0
- langchain/tools/wolfram_alpha/__init__.py +1 -0
- langchain/tools/zapier/__init__.py +1 -0
- langchain/utilities/__init__.py +1 -0
- langchain/utilities/python.py +1 -0
- langchain/vectorstores/__init__.py +1 -0
- {langchain-0.2.5.dist-info → langchain-0.2.7.dist-info}/METADATA +3 -4
- {langchain-0.2.5.dist-info → langchain-0.2.7.dist-info}/RECORD +197 -196
- {langchain-0.2.5.dist-info → langchain-0.2.7.dist-info}/LICENSE +0 -0
- {langchain-0.2.5.dist-info → langchain-0.2.7.dist-info}/WHEEL +0 -0
- {langchain-0.2.5.dist-info → langchain-0.2.7.dist-info}/entry_points.txt +0 -0
langchain/retrievers/ensemble.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Ensemble retriever that ensemble the results of
|
|
3
3
|
multiple retrievers by using weighted Reciprocal Rank Fusion
|
|
4
4
|
"""
|
|
5
|
+
|
|
5
6
|
import asyncio
|
|
6
7
|
from collections import defaultdict
|
|
7
8
|
from collections.abc import Hashable
|
|
@@ -66,11 +67,14 @@ class EnsembleRetriever(BaseRetriever):
|
|
|
66
67
|
c: A constant added to the rank, controlling the balance between the importance
|
|
67
68
|
of high-ranked items and the consideration given to lower-ranked items.
|
|
68
69
|
Default is 60.
|
|
70
|
+
id_key: The key in the document's metadata used to determine unique documents.
|
|
71
|
+
If not specified, page_content is used.
|
|
69
72
|
"""
|
|
70
73
|
|
|
71
74
|
retrievers: List[RetrieverLike]
|
|
72
75
|
weights: List[float]
|
|
73
76
|
c: int = 60
|
|
77
|
+
id_key: Optional[str] = None
|
|
74
78
|
|
|
75
79
|
@property
|
|
76
80
|
def config_specs(self) -> List[ConfigurableFieldSpec]:
|
|
@@ -305,13 +309,24 @@ class EnsembleRetriever(BaseRetriever):
|
|
|
305
309
|
rrf_score: Dict[str, float] = defaultdict(float)
|
|
306
310
|
for doc_list, weight in zip(doc_lists, self.weights):
|
|
307
311
|
for rank, doc in enumerate(doc_list, start=1):
|
|
308
|
-
rrf_score[
|
|
312
|
+
rrf_score[
|
|
313
|
+
doc.page_content
|
|
314
|
+
if self.id_key is None
|
|
315
|
+
else doc.metadata[self.id_key]
|
|
316
|
+
] += weight / (rank + self.c)
|
|
309
317
|
|
|
310
318
|
# Docs are deduplicated by their contents then sorted by their scores
|
|
311
319
|
all_docs = chain.from_iterable(doc_lists)
|
|
312
320
|
sorted_docs = sorted(
|
|
313
|
-
unique_by_key(
|
|
321
|
+
unique_by_key(
|
|
322
|
+
all_docs,
|
|
323
|
+
lambda doc: doc.page_content
|
|
324
|
+
if self.id_key is None
|
|
325
|
+
else doc.metadata[self.id_key],
|
|
326
|
+
),
|
|
314
327
|
reverse=True,
|
|
315
|
-
key=lambda doc: rrf_score[
|
|
328
|
+
key=lambda doc: rrf_score[
|
|
329
|
+
doc.page_content if self.id_key is None else doc.metadata[self.id_key]
|
|
330
|
+
],
|
|
316
331
|
)
|
|
317
332
|
return sorted_docs
|
|
@@ -9,6 +9,7 @@ from langchain_core.callbacks import (
|
|
|
9
9
|
from langchain_core.documents import Document
|
|
10
10
|
from langchain_core.language_models import BaseLanguageModel
|
|
11
11
|
from langchain_core.output_parsers import BaseOutputParser
|
|
12
|
+
from langchain_core.prompts import BasePromptTemplate
|
|
12
13
|
from langchain_core.prompts.prompt import PromptTemplate
|
|
13
14
|
from langchain_core.retrievers import BaseRetriever
|
|
14
15
|
from langchain_core.runnables import Runnable
|
|
@@ -62,7 +63,7 @@ class MultiQueryRetriever(BaseRetriever):
|
|
|
62
63
|
cls,
|
|
63
64
|
retriever: BaseRetriever,
|
|
64
65
|
llm: BaseLanguageModel,
|
|
65
|
-
prompt:
|
|
66
|
+
prompt: BasePromptTemplate = DEFAULT_QUERY_PROMPT,
|
|
66
67
|
parser_key: Optional[str] = None,
|
|
67
68
|
include_original: bool = False,
|
|
68
69
|
) -> "MultiQueryRetriever":
|
|
@@ -7,6 +7,7 @@ from langchain_core.callbacks import (
|
|
|
7
7
|
)
|
|
8
8
|
from langchain_core.documents import Document
|
|
9
9
|
from langchain_core.language_models import BaseLLM
|
|
10
|
+
from langchain_core.prompts import BasePromptTemplate
|
|
10
11
|
from langchain_core.prompts.prompt import PromptTemplate
|
|
11
12
|
from langchain_core.retrievers import BaseRetriever
|
|
12
13
|
|
|
@@ -36,7 +37,7 @@ class RePhraseQueryRetriever(BaseRetriever):
|
|
|
36
37
|
cls,
|
|
37
38
|
retriever: BaseRetriever,
|
|
38
39
|
llm: BaseLLM,
|
|
39
|
-
prompt:
|
|
40
|
+
prompt: BasePromptTemplate = DEFAULT_QUERY_PROMPT,
|
|
40
41
|
) -> "RePhraseQueryRetriever":
|
|
41
42
|
"""Initialize from llm using default template.
|
|
42
43
|
|
|
@@ -169,12 +169,13 @@ def _get_builtin_translator(vectorstore: VectorStore) -> Visitor:
|
|
|
169
169
|
return ChromaTranslator()
|
|
170
170
|
|
|
171
171
|
try:
|
|
172
|
-
from langchain_postgres import PGVector
|
|
172
|
+
from langchain_postgres import PGVector # type: ignore[no-redef]
|
|
173
|
+
from langchain_postgres import PGVectorTranslator as NewPGVectorTranslator
|
|
173
174
|
except ImportError:
|
|
174
175
|
pass
|
|
175
176
|
else:
|
|
176
177
|
if isinstance(vectorstore, PGVector):
|
|
177
|
-
return
|
|
178
|
+
return NewPGVectorTranslator()
|
|
178
179
|
|
|
179
180
|
raise ValueError(
|
|
180
181
|
f"Self query retriever with Vector Store type {vectorstore.__class__}"
|
|
@@ -309,16 +310,16 @@ class SelfQueryRetriever(BaseRetriever):
|
|
|
309
310
|
"allowed_comparators" not in chain_kwargs
|
|
310
311
|
and structured_query_translator.allowed_comparators is not None
|
|
311
312
|
):
|
|
312
|
-
chain_kwargs[
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
chain_kwargs["allowed_comparators"] = (
|
|
314
|
+
structured_query_translator.allowed_comparators
|
|
315
|
+
)
|
|
315
316
|
if (
|
|
316
317
|
"allowed_operators" not in chain_kwargs
|
|
317
318
|
and structured_query_translator.allowed_operators is not None
|
|
318
319
|
):
|
|
319
|
-
chain_kwargs[
|
|
320
|
-
|
|
321
|
-
|
|
320
|
+
chain_kwargs["allowed_operators"] = (
|
|
321
|
+
structured_query_translator.allowed_operators
|
|
322
|
+
)
|
|
322
323
|
query_constructor = load_query_constructor_runnable(
|
|
323
324
|
llm,
|
|
324
325
|
document_contents,
|
langchain/schema/__init__.py
CHANGED
langchain/serpapi.py
CHANGED
langchain/smith/__init__.py
CHANGED
|
@@ -54,19 +54,19 @@ or LangSmith's `RunEvaluator` classes.
|
|
|
54
54
|
from langchain.evaluation import StringEvaluator
|
|
55
55
|
|
|
56
56
|
class MyStringEvaluator(StringEvaluator):
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
@property
|
|
59
59
|
def requires_input(self) -> bool:
|
|
60
60
|
return False
|
|
61
|
-
|
|
61
|
+
|
|
62
62
|
@property
|
|
63
63
|
def requires_reference(self) -> bool:
|
|
64
64
|
return True
|
|
65
|
-
|
|
65
|
+
|
|
66
66
|
@property
|
|
67
67
|
def evaluation_name(self) -> str:
|
|
68
68
|
return "exact_match"
|
|
69
|
-
|
|
69
|
+
|
|
70
70
|
def _evaluate_strings(self, prediction, reference=None, input=None, **kwargs) -> dict:
|
|
71
71
|
return {"score": prediction == reference}
|
|
72
72
|
|
|
@@ -80,7 +80,7 @@ or LangSmith's `RunEvaluator` classes.
|
|
|
80
80
|
"<my_dataset_name>",
|
|
81
81
|
construct_chain,
|
|
82
82
|
evaluation=evaluation_config,
|
|
83
|
-
)
|
|
83
|
+
)
|
|
84
84
|
|
|
85
85
|
**Primary Functions**
|
|
86
86
|
|
|
@@ -88,6 +88,7 @@ or LangSmith's `RunEvaluator` classes.
|
|
|
88
88
|
- :func:`run_on_dataset <langchain.smith.evaluation.runner_utils.run_on_dataset>`: Function to evaluate a chain, agent, or other LangChain component over a dataset.
|
|
89
89
|
- :class:`RunEvalConfig <langchain.smith.evaluation.config.RunEvalConfig>`: Class representing the configuration for running evaluation. You can select evaluators by :class:`EvaluatorType <langchain.evaluation.schema.EvaluatorType>` or config, or you can pass in `custom_evaluators`
|
|
90
90
|
""" # noqa: E501
|
|
91
|
+
|
|
91
92
|
from langchain.smith.evaluation import (
|
|
92
93
|
RunEvalConfig,
|
|
93
94
|
arun_on_dataset,
|
langchain/sql_database.py
CHANGED
langchain/storage/__init__.py
CHANGED
langchain/storage/_lc_store.py
CHANGED
langchain/storage/in_memory.py
CHANGED
langchain/text_splitter.py
CHANGED
langchain/tools/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""GitHub Tool"""
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""GitLab Tool"""
|
langchain/utilities/__init__.py
CHANGED
langchain/utilities/python.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: langchain
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Building applications with LLMs through composability
|
|
5
5
|
Home-page: https://github.com/langchain-ai/langchain
|
|
6
6
|
License: MIT
|
|
@@ -15,14 +15,14 @@ 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.12,<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"
|
|
22
22
|
Requires-Dist: numpy (>=1.26.0,<2.0.0) ; python_version >= "3.12"
|
|
23
23
|
Requires-Dist: pydantic (>=1,<3)
|
|
24
24
|
Requires-Dist: requests (>=2,<3)
|
|
25
|
-
Requires-Dist: tenacity (>=8.1.0,<9.0.0)
|
|
25
|
+
Requires-Dist: tenacity (>=8.1.0,<9.0.0,!=8.4.0)
|
|
26
26
|
Project-URL: Repository, https://github.com/langchain-ai/langchain
|
|
27
27
|
Description-Content-Type: text/markdown
|
|
28
28
|
|
|
@@ -36,7 +36,6 @@ Description-Content-Type: text/markdown
|
|
|
36
36
|
[](https://pepy.tech/project/langchain)
|
|
37
37
|
[](https://opensource.org/licenses/MIT)
|
|
38
38
|
[](https://twitter.com/langchainai)
|
|
39
|
-
[](https://discord.gg/6adMQxSpJS)
|
|
40
39
|
[](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/langchain-ai/langchain)
|
|
41
40
|
[](https://codespaces.new/langchain-ai/langchain)
|
|
42
41
|
[](https://star-history.com/#langchain-ai/langchain)
|