langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.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-core might be problematic. Click here for more details.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +45 -70
- langchain_core/_api/deprecation.py +80 -80
- langchain_core/_api/path.py +22 -8
- langchain_core/_import_utils.py +10 -4
- langchain_core/agents.py +25 -21
- langchain_core/caches.py +53 -63
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +341 -348
- langchain_core/callbacks/file.py +55 -44
- langchain_core/callbacks/manager.py +546 -683
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +35 -36
- langchain_core/callbacks/usage.py +65 -70
- langchain_core/chat_history.py +48 -55
- langchain_core/document_loaders/base.py +46 -21
- langchain_core/document_loaders/langsmith.py +39 -36
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +96 -74
- langchain_core/documents/compressor.py +12 -9
- langchain_core/documents/transformers.py +29 -28
- langchain_core/embeddings/fake.py +56 -57
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +21 -25
- langchain_core/exceptions.py +15 -9
- langchain_core/globals.py +4 -163
- langchain_core/indexing/api.py +132 -125
- langchain_core/indexing/base.py +64 -67
- langchain_core/indexing/in_memory.py +26 -6
- langchain_core/language_models/__init__.py +15 -27
- langchain_core/language_models/_utils.py +267 -117
- langchain_core/language_models/base.py +92 -177
- langchain_core/language_models/chat_models.py +547 -407
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +72 -118
- langchain_core/language_models/llms.py +168 -242
- langchain_core/load/dump.py +8 -11
- langchain_core/load/load.py +32 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +50 -56
- langchain_core/messages/__init__.py +36 -51
- langchain_core/messages/ai.py +377 -150
- langchain_core/messages/base.py +239 -47
- langchain_core/messages/block_translators/__init__.py +111 -0
- langchain_core/messages/block_translators/anthropic.py +470 -0
- langchain_core/messages/block_translators/bedrock.py +94 -0
- langchain_core/messages/block_translators/bedrock_converse.py +297 -0
- langchain_core/messages/block_translators/google_genai.py +530 -0
- langchain_core/messages/block_translators/google_vertexai.py +21 -0
- langchain_core/messages/block_translators/groq.py +143 -0
- langchain_core/messages/block_translators/langchain_v0.py +301 -0
- langchain_core/messages/block_translators/openai.py +1010 -0
- langchain_core/messages/chat.py +2 -3
- langchain_core/messages/content.py +1423 -0
- langchain_core/messages/function.py +7 -7
- langchain_core/messages/human.py +44 -38
- langchain_core/messages/modifier.py +3 -2
- langchain_core/messages/system.py +40 -27
- langchain_core/messages/tool.py +160 -58
- langchain_core/messages/utils.py +527 -638
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +68 -104
- langchain_core/output_parsers/json.py +13 -17
- langchain_core/output_parsers/list.py +11 -33
- langchain_core/output_parsers/openai_functions.py +56 -74
- langchain_core/output_parsers/openai_tools.py +68 -109
- langchain_core/output_parsers/pydantic.py +15 -13
- langchain_core/output_parsers/string.py +6 -2
- langchain_core/output_parsers/transform.py +17 -60
- langchain_core/output_parsers/xml.py +34 -44
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +26 -11
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +17 -6
- langchain_core/outputs/llm_result.py +15 -8
- langchain_core/prompt_values.py +29 -123
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -63
- langchain_core/prompts/chat.py +259 -288
- langchain_core/prompts/dict.py +19 -11
- langchain_core/prompts/few_shot.py +84 -90
- langchain_core/prompts/few_shot_with_templates.py +14 -12
- langchain_core/prompts/image.py +19 -14
- langchain_core/prompts/loading.py +6 -8
- langchain_core/prompts/message.py +7 -8
- langchain_core/prompts/prompt.py +42 -43
- langchain_core/prompts/string.py +37 -16
- langchain_core/prompts/structured.py +43 -46
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +52 -192
- langchain_core/runnables/base.py +1727 -1683
- langchain_core/runnables/branch.py +52 -73
- langchain_core/runnables/config.py +89 -103
- langchain_core/runnables/configurable.py +128 -130
- langchain_core/runnables/fallbacks.py +93 -82
- langchain_core/runnables/graph.py +127 -127
- langchain_core/runnables/graph_ascii.py +63 -41
- langchain_core/runnables/graph_mermaid.py +87 -70
- langchain_core/runnables/graph_png.py +31 -36
- langchain_core/runnables/history.py +145 -161
- langchain_core/runnables/passthrough.py +141 -144
- langchain_core/runnables/retry.py +84 -68
- langchain_core/runnables/router.py +33 -37
- langchain_core/runnables/schema.py +79 -72
- langchain_core/runnables/utils.py +95 -139
- langchain_core/stores.py +85 -131
- langchain_core/structured_query.py +11 -15
- langchain_core/sys_info.py +31 -32
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +221 -247
- langchain_core/tools/convert.py +144 -161
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -19
- langchain_core/tools/simple.py +52 -29
- langchain_core/tools/structured.py +56 -60
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/_streaming.py +6 -7
- langchain_core/tracers/base.py +103 -112
- langchain_core/tracers/context.py +29 -48
- langchain_core/tracers/core.py +142 -105
- langchain_core/tracers/evaluation.py +30 -34
- langchain_core/tracers/event_stream.py +162 -117
- langchain_core/tracers/langchain.py +34 -36
- langchain_core/tracers/log_stream.py +87 -49
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +18 -34
- langchain_core/tracers/run_collector.py +8 -20
- langchain_core/tracers/schemas.py +0 -125
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +47 -9
- langchain_core/utils/aiter.py +70 -66
- langchain_core/utils/env.py +12 -9
- langchain_core/utils/function_calling.py +139 -206
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +48 -45
- langchain_core/utils/json.py +14 -4
- langchain_core/utils/json_schema.py +159 -43
- langchain_core/utils/mustache.py +32 -25
- langchain_core/utils/pydantic.py +67 -40
- langchain_core/utils/strings.py +5 -5
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +104 -62
- langchain_core/vectorstores/base.py +131 -179
- langchain_core/vectorstores/in_memory.py +113 -182
- langchain_core/vectorstores/utils.py +23 -17
- langchain_core/version.py +1 -1
- langchain_core-1.0.0.dist-info/METADATA +68 -0
- langchain_core-1.0.0.dist-info/RECORD +172 -0
- {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
- langchain_core/beta/__init__.py +0 -1
- langchain_core/beta/runnables/__init__.py +0 -1
- langchain_core/beta/runnables/context.py +0 -448
- langchain_core/memory.py +0 -116
- langchain_core/messages/content_blocks.py +0 -1435
- langchain_core/prompts/pipeline.py +0 -133
- langchain_core/pydantic_v1/__init__.py +0 -30
- langchain_core/pydantic_v1/dataclasses.py +0 -23
- langchain_core/pydantic_v1/main.py +0 -23
- langchain_core/tracers/langchain_v1.py +0 -23
- langchain_core/utils/loading.py +0 -31
- langchain_core/v1/__init__.py +0 -1
- langchain_core/v1/chat_models.py +0 -1047
- langchain_core/v1/messages.py +0 -755
- langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
- langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
- langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
"""[DEPRECATED] Pipeline prompt template."""
|
|
2
|
-
|
|
3
|
-
from typing import Any
|
|
4
|
-
|
|
5
|
-
from pydantic import model_validator
|
|
6
|
-
|
|
7
|
-
from langchain_core._api.deprecation import deprecated
|
|
8
|
-
from langchain_core.prompt_values import PromptValue
|
|
9
|
-
from langchain_core.prompts.base import BasePromptTemplate
|
|
10
|
-
from langchain_core.prompts.chat import BaseChatPromptTemplate
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def _get_inputs(inputs: dict, input_variables: list[str]) -> dict:
|
|
14
|
-
return {k: inputs[k] for k in input_variables}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@deprecated(
|
|
18
|
-
since="0.3.22",
|
|
19
|
-
removal="1.0",
|
|
20
|
-
message=(
|
|
21
|
-
"This class is deprecated in favor of chaining individual prompts together."
|
|
22
|
-
),
|
|
23
|
-
)
|
|
24
|
-
class PipelinePromptTemplate(BasePromptTemplate):
|
|
25
|
-
"""Pipeline prompt template.
|
|
26
|
-
|
|
27
|
-
This has been deprecated in favor of chaining individual prompts together in your
|
|
28
|
-
code; e.g. using a for loop, you could do:
|
|
29
|
-
|
|
30
|
-
.. code-block:: python
|
|
31
|
-
|
|
32
|
-
my_input = {"key": "value"}
|
|
33
|
-
for name, prompt in pipeline_prompts:
|
|
34
|
-
my_input[name] = prompt.invoke(my_input).to_string()
|
|
35
|
-
my_output = final_prompt.invoke(my_input)
|
|
36
|
-
|
|
37
|
-
Prompt template for composing multiple prompt templates together.
|
|
38
|
-
|
|
39
|
-
This can be useful when you want to reuse parts of prompts.
|
|
40
|
-
|
|
41
|
-
A PipelinePrompt consists of two main parts:
|
|
42
|
-
- final_prompt: This is the final prompt that is returned
|
|
43
|
-
- pipeline_prompts: This is a list of tuples, consisting
|
|
44
|
-
of a string (`name`) and a Prompt Template.
|
|
45
|
-
Each PromptTemplate will be formatted and then passed
|
|
46
|
-
to future prompt templates as a variable with
|
|
47
|
-
the same name as `name`
|
|
48
|
-
|
|
49
|
-
"""
|
|
50
|
-
|
|
51
|
-
final_prompt: BasePromptTemplate
|
|
52
|
-
"""The final prompt that is returned."""
|
|
53
|
-
pipeline_prompts: list[tuple[str, BasePromptTemplate]]
|
|
54
|
-
"""A list of tuples, consisting of a string (`name`) and a Prompt Template."""
|
|
55
|
-
|
|
56
|
-
@classmethod
|
|
57
|
-
def get_lc_namespace(cls) -> list[str]:
|
|
58
|
-
"""Get the namespace of the langchain object."""
|
|
59
|
-
return ["langchain", "prompts", "pipeline"]
|
|
60
|
-
|
|
61
|
-
@model_validator(mode="before")
|
|
62
|
-
@classmethod
|
|
63
|
-
def get_input_variables(cls, values: dict) -> Any:
|
|
64
|
-
"""Get input variables."""
|
|
65
|
-
created_variables = set()
|
|
66
|
-
all_variables = set()
|
|
67
|
-
for k, prompt in values["pipeline_prompts"]:
|
|
68
|
-
created_variables.add(k)
|
|
69
|
-
all_variables.update(prompt.input_variables)
|
|
70
|
-
values["input_variables"] = list(all_variables.difference(created_variables))
|
|
71
|
-
return values
|
|
72
|
-
|
|
73
|
-
def format_prompt(self, **kwargs: Any) -> PromptValue:
|
|
74
|
-
"""Format the prompt with the inputs.
|
|
75
|
-
|
|
76
|
-
Args:
|
|
77
|
-
kwargs: Any arguments to be passed to the prompt template.
|
|
78
|
-
|
|
79
|
-
Returns:
|
|
80
|
-
A formatted string.
|
|
81
|
-
"""
|
|
82
|
-
for k, prompt in self.pipeline_prompts:
|
|
83
|
-
inputs = _get_inputs(kwargs, prompt.input_variables)
|
|
84
|
-
if isinstance(prompt, BaseChatPromptTemplate):
|
|
85
|
-
kwargs[k] = prompt.format_messages(**inputs)
|
|
86
|
-
else:
|
|
87
|
-
kwargs[k] = prompt.format(**inputs)
|
|
88
|
-
inputs = _get_inputs(kwargs, self.final_prompt.input_variables)
|
|
89
|
-
return self.final_prompt.format_prompt(**inputs)
|
|
90
|
-
|
|
91
|
-
async def aformat_prompt(self, **kwargs: Any) -> PromptValue:
|
|
92
|
-
"""Async format the prompt with the inputs.
|
|
93
|
-
|
|
94
|
-
Args:
|
|
95
|
-
kwargs: Any arguments to be passed to the prompt template.
|
|
96
|
-
|
|
97
|
-
Returns:
|
|
98
|
-
A formatted string.
|
|
99
|
-
"""
|
|
100
|
-
for k, prompt in self.pipeline_prompts:
|
|
101
|
-
inputs = _get_inputs(kwargs, prompt.input_variables)
|
|
102
|
-
if isinstance(prompt, BaseChatPromptTemplate):
|
|
103
|
-
kwargs[k] = await prompt.aformat_messages(**inputs)
|
|
104
|
-
else:
|
|
105
|
-
kwargs[k] = await prompt.aformat(**inputs)
|
|
106
|
-
inputs = _get_inputs(kwargs, self.final_prompt.input_variables)
|
|
107
|
-
return await self.final_prompt.aformat_prompt(**inputs)
|
|
108
|
-
|
|
109
|
-
def format(self, **kwargs: Any) -> str:
|
|
110
|
-
"""Format the prompt with the inputs.
|
|
111
|
-
|
|
112
|
-
Args:
|
|
113
|
-
kwargs: Any arguments to be passed to the prompt template.
|
|
114
|
-
|
|
115
|
-
Returns:
|
|
116
|
-
A formatted string.
|
|
117
|
-
"""
|
|
118
|
-
return self.format_prompt(**kwargs).to_string()
|
|
119
|
-
|
|
120
|
-
async def aformat(self, **kwargs: Any) -> str:
|
|
121
|
-
"""Async format the prompt with the inputs.
|
|
122
|
-
|
|
123
|
-
Args:
|
|
124
|
-
kwargs: Any arguments to be passed to the prompt template.
|
|
125
|
-
|
|
126
|
-
Returns:
|
|
127
|
-
A formatted string.
|
|
128
|
-
"""
|
|
129
|
-
return (await self.aformat_prompt(**kwargs)).to_string()
|
|
130
|
-
|
|
131
|
-
@property
|
|
132
|
-
def _prompt_type(self) -> str:
|
|
133
|
-
raise ValueError
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"""Pydantic v1 compatibility shim."""
|
|
2
|
-
|
|
3
|
-
from importlib import metadata
|
|
4
|
-
|
|
5
|
-
from pydantic.v1 import * # noqa: F403
|
|
6
|
-
|
|
7
|
-
from langchain_core._api.deprecation import warn_deprecated
|
|
8
|
-
|
|
9
|
-
try:
|
|
10
|
-
_PYDANTIC_MAJOR_VERSION: int = int(metadata.version("pydantic").split(".")[0])
|
|
11
|
-
except metadata.PackageNotFoundError:
|
|
12
|
-
_PYDANTIC_MAJOR_VERSION = 0
|
|
13
|
-
|
|
14
|
-
warn_deprecated(
|
|
15
|
-
"0.3.0",
|
|
16
|
-
removal="1.0.0",
|
|
17
|
-
alternative="pydantic.v1 or pydantic",
|
|
18
|
-
message=(
|
|
19
|
-
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
20
|
-
"The langchain_core.pydantic_v1 module was a "
|
|
21
|
-
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
22
|
-
"Please update the code to import from Pydantic directly.\n\n"
|
|
23
|
-
"For example, replace imports like: "
|
|
24
|
-
"`from langchain_core.pydantic_v1 import BaseModel`\n"
|
|
25
|
-
"with: `from pydantic import BaseModel`\n"
|
|
26
|
-
"or the v1 compatibility namespace if you are working in a code base "
|
|
27
|
-
"that has not been fully upgraded to pydantic 2 yet. "
|
|
28
|
-
"\tfrom pydantic.v1 import BaseModel\n"
|
|
29
|
-
),
|
|
30
|
-
)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""Pydantic v1 compatibility shim."""
|
|
2
|
-
|
|
3
|
-
from pydantic.v1.dataclasses import * # noqa: F403
|
|
4
|
-
|
|
5
|
-
from langchain_core._api import warn_deprecated
|
|
6
|
-
|
|
7
|
-
warn_deprecated(
|
|
8
|
-
"0.3.0",
|
|
9
|
-
removal="1.0.0",
|
|
10
|
-
alternative="pydantic.v1 or pydantic",
|
|
11
|
-
message=(
|
|
12
|
-
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
13
|
-
"The langchain_core.pydantic_v1 module was a "
|
|
14
|
-
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
15
|
-
"Please update the code to import from Pydantic directly.\n\n"
|
|
16
|
-
"For example, replace imports like: "
|
|
17
|
-
"`from langchain_core.pydantic_v1 import BaseModel`\n"
|
|
18
|
-
"with: `from pydantic import BaseModel`\n"
|
|
19
|
-
"or the v1 compatibility namespace if you are working in a code base "
|
|
20
|
-
"that has not been fully upgraded to pydantic 2 yet. "
|
|
21
|
-
"\tfrom pydantic.v1 import BaseModel\n"
|
|
22
|
-
),
|
|
23
|
-
)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""Pydantic v1 compatibility shim."""
|
|
2
|
-
|
|
3
|
-
from pydantic.v1.main import * # noqa: F403
|
|
4
|
-
|
|
5
|
-
from langchain_core._api import warn_deprecated
|
|
6
|
-
|
|
7
|
-
warn_deprecated(
|
|
8
|
-
"0.3.0",
|
|
9
|
-
removal="1.0.0",
|
|
10
|
-
alternative="pydantic.v1 or pydantic",
|
|
11
|
-
message=(
|
|
12
|
-
"As of langchain-core 0.3.0, LangChain uses pydantic v2 internally. "
|
|
13
|
-
"The langchain_core.pydantic_v1 module was a "
|
|
14
|
-
"compatibility shim for pydantic v1, and should no longer be used. "
|
|
15
|
-
"Please update the code to import from Pydantic directly.\n\n"
|
|
16
|
-
"For example, replace imports like: "
|
|
17
|
-
"`from langchain_core.pydantic_v1 import BaseModel`\n"
|
|
18
|
-
"with: `from pydantic import BaseModel`\n"
|
|
19
|
-
"or the v1 compatibility namespace if you are working in a code base "
|
|
20
|
-
"that has not been fully upgraded to pydantic 2 yet. "
|
|
21
|
-
"\tfrom pydantic.v1 import BaseModel\n"
|
|
22
|
-
),
|
|
23
|
-
)
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"""This module is deprecated and will be removed in a future release.
|
|
2
|
-
|
|
3
|
-
Please use LangChainTracer instead.
|
|
4
|
-
"""
|
|
5
|
-
|
|
6
|
-
from typing import Any
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def get_headers(*args: Any, **kwargs: Any) -> Any: # noqa: ARG001
|
|
10
|
-
"""Throw an error because this has been replaced by get_headers."""
|
|
11
|
-
msg = (
|
|
12
|
-
"get_headers for LangChainTracerV1 is no longer supported. "
|
|
13
|
-
"Please use LangChainTracer instead."
|
|
14
|
-
)
|
|
15
|
-
raise RuntimeError(msg)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def LangChainTracerV1(*args: Any, **kwargs: Any) -> Any: # noqa: N802,ARG001
|
|
19
|
-
"""Throw an error because this has been replaced by LangChainTracer."""
|
|
20
|
-
msg = (
|
|
21
|
-
"LangChainTracerV1 is no longer supported. Please use LangChainTracer instead."
|
|
22
|
-
)
|
|
23
|
-
raise RuntimeError(msg)
|
langchain_core/utils/loading.py
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"""Utilities for loading configurations from langchain_core-hub."""
|
|
2
|
-
|
|
3
|
-
import warnings
|
|
4
|
-
from typing import Any
|
|
5
|
-
|
|
6
|
-
from langchain_core._api.deprecation import deprecated
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@deprecated(
|
|
10
|
-
since="0.1.30",
|
|
11
|
-
removal="1.0",
|
|
12
|
-
message=(
|
|
13
|
-
"Using the hwchase17/langchain-hub "
|
|
14
|
-
"repo for prompts is deprecated. Please use "
|
|
15
|
-
"<https://smith.langchain.com/hub> instead."
|
|
16
|
-
),
|
|
17
|
-
)
|
|
18
|
-
def try_load_from_hub(
|
|
19
|
-
*args: Any, # noqa: ARG001
|
|
20
|
-
**kwargs: Any, # noqa: ARG001
|
|
21
|
-
) -> Any:
|
|
22
|
-
"""[DEPRECATED] Try to load from the old Hub."""
|
|
23
|
-
warnings.warn(
|
|
24
|
-
"Loading from the deprecated github-based Hub is no longer supported. "
|
|
25
|
-
"Please use the new LangChain Hub at https://smith.langchain.com/hub instead.",
|
|
26
|
-
DeprecationWarning,
|
|
27
|
-
stacklevel=2,
|
|
28
|
-
)
|
|
29
|
-
# return None, which indicates that we shouldn't load from old hub
|
|
30
|
-
# and might just be a filepath for e.g. load_chain
|
|
31
|
-
return None
|
langchain_core/v1/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"""LangChain v1.0 types."""
|