langchain-core 0.3.75__py3-none-any.whl → 0.3.76__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/_api/beta_decorator.py +17 -40
- langchain_core/_api/deprecation.py +19 -6
- langchain_core/_api/path.py +19 -2
- langchain_core/_import_utils.py +7 -0
- langchain_core/agents.py +10 -6
- langchain_core/beta/runnables/context.py +1 -2
- langchain_core/callbacks/base.py +11 -4
- langchain_core/callbacks/manager.py +81 -69
- langchain_core/callbacks/usage.py +4 -2
- langchain_core/chat_history.py +4 -6
- langchain_core/document_loaders/base.py +34 -9
- langchain_core/document_loaders/langsmith.py +3 -0
- langchain_core/documents/base.py +35 -10
- langchain_core/documents/transformers.py +4 -2
- langchain_core/embeddings/fake.py +8 -5
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/exceptions.py +7 -0
- langchain_core/globals.py +17 -28
- langchain_core/indexing/api.py +56 -44
- langchain_core/indexing/base.py +5 -8
- langchain_core/indexing/in_memory.py +23 -3
- langchain_core/language_models/__init__.py +3 -2
- langchain_core/language_models/base.py +31 -20
- langchain_core/language_models/chat_models.py +94 -25
- langchain_core/language_models/fake_chat_models.py +5 -7
- langchain_core/language_models/llms.py +49 -17
- langchain_core/load/dump.py +2 -3
- langchain_core/load/load.py +15 -1
- langchain_core/load/serializable.py +38 -43
- langchain_core/memory.py +7 -3
- langchain_core/messages/ai.py +36 -19
- langchain_core/messages/base.py +13 -6
- langchain_core/messages/content_blocks.py +23 -2
- langchain_core/messages/human.py +2 -6
- langchain_core/messages/system.py +2 -6
- langchain_core/messages/tool.py +33 -13
- langchain_core/messages/utils.py +182 -72
- langchain_core/output_parsers/base.py +5 -2
- langchain_core/output_parsers/json.py +4 -4
- langchain_core/output_parsers/list.py +7 -22
- langchain_core/output_parsers/openai_functions.py +3 -0
- langchain_core/output_parsers/openai_tools.py +6 -1
- langchain_core/output_parsers/pydantic.py +4 -0
- langchain_core/output_parsers/string.py +5 -1
- langchain_core/output_parsers/xml.py +19 -19
- langchain_core/outputs/chat_generation.py +18 -7
- langchain_core/outputs/generation.py +14 -3
- langchain_core/outputs/llm_result.py +8 -1
- langchain_core/prompt_values.py +10 -4
- langchain_core/prompts/base.py +4 -9
- langchain_core/prompts/chat.py +87 -58
- langchain_core/prompts/dict.py +16 -8
- langchain_core/prompts/few_shot.py +9 -11
- langchain_core/prompts/few_shot_with_templates.py +5 -1
- langchain_core/prompts/image.py +12 -5
- langchain_core/prompts/message.py +5 -6
- langchain_core/prompts/pipeline.py +13 -8
- langchain_core/prompts/prompt.py +22 -8
- langchain_core/prompts/string.py +18 -10
- langchain_core/prompts/structured.py +7 -2
- langchain_core/rate_limiters.py +2 -2
- langchain_core/retrievers.py +7 -6
- langchain_core/runnables/base.py +402 -183
- langchain_core/runnables/branch.py +14 -19
- langchain_core/runnables/config.py +9 -15
- langchain_core/runnables/configurable.py +34 -19
- langchain_core/runnables/fallbacks.py +20 -13
- langchain_core/runnables/graph.py +44 -37
- langchain_core/runnables/graph_ascii.py +40 -17
- langchain_core/runnables/graph_mermaid.py +27 -15
- langchain_core/runnables/graph_png.py +27 -31
- langchain_core/runnables/history.py +55 -58
- langchain_core/runnables/passthrough.py +44 -21
- langchain_core/runnables/retry.py +9 -5
- langchain_core/runnables/router.py +9 -8
- langchain_core/runnables/schema.py +2 -0
- langchain_core/runnables/utils.py +51 -89
- langchain_core/stores.py +13 -25
- langchain_core/sys_info.py +9 -8
- langchain_core/tools/base.py +30 -23
- langchain_core/tools/convert.py +24 -13
- langchain_core/tools/simple.py +35 -3
- langchain_core/tools/structured.py +25 -2
- langchain_core/tracers/base.py +2 -2
- langchain_core/tracers/context.py +5 -1
- langchain_core/tracers/core.py +109 -39
- langchain_core/tracers/evaluation.py +22 -26
- langchain_core/tracers/event_stream.py +40 -27
- langchain_core/tracers/langchain.py +12 -3
- langchain_core/tracers/langchain_v1.py +10 -2
- langchain_core/tracers/log_stream.py +56 -17
- langchain_core/tracers/root_listeners.py +4 -20
- langchain_core/tracers/run_collector.py +6 -16
- langchain_core/tracers/schemas.py +5 -1
- langchain_core/utils/aiter.py +14 -6
- langchain_core/utils/env.py +3 -0
- langchain_core/utils/function_calling.py +37 -20
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +11 -3
- langchain_core/utils/json.py +5 -2
- langchain_core/utils/json_schema.py +15 -5
- langchain_core/utils/loading.py +5 -1
- langchain_core/utils/mustache.py +24 -15
- langchain_core/utils/pydantic.py +32 -4
- langchain_core/utils/utils.py +24 -8
- langchain_core/vectorstores/base.py +7 -20
- langchain_core/vectorstores/in_memory.py +18 -12
- langchain_core/vectorstores/utils.py +18 -12
- langchain_core/version.py +1 -1
- langchain_core-0.3.76.dist-info/METADATA +77 -0
- langchain_core-0.3.76.dist-info/RECORD +174 -0
- langchain_core-0.3.75.dist-info/METADATA +0 -106
- langchain_core-0.3.75.dist-info/RECORD +0 -174
- {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/WHEEL +0 -0
- {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/entry_points.txt +0 -0
|
@@ -143,10 +143,7 @@ class CommaSeparatedListOutputParser(ListOutputParser):
|
|
|
143
143
|
|
|
144
144
|
@classmethod
|
|
145
145
|
def is_lc_serializable(cls) -> bool:
|
|
146
|
-
"""
|
|
147
|
-
|
|
148
|
-
Returns True.
|
|
149
|
-
"""
|
|
146
|
+
"""Return True as this class is serializable."""
|
|
150
147
|
return True
|
|
151
148
|
|
|
152
149
|
@classmethod
|
|
@@ -154,11 +151,11 @@ class CommaSeparatedListOutputParser(ListOutputParser):
|
|
|
154
151
|
"""Get the namespace of the langchain object.
|
|
155
152
|
|
|
156
153
|
Returns:
|
|
157
|
-
|
|
158
|
-
Default is ["langchain", "output_parsers", "list"].
|
|
154
|
+
``["langchain", "output_parsers", "list"]``
|
|
159
155
|
"""
|
|
160
156
|
return ["langchain", "output_parsers", "list"]
|
|
161
157
|
|
|
158
|
+
@override
|
|
162
159
|
def get_format_instructions(self) -> str:
|
|
163
160
|
"""Return the format instructions for the comma-separated list output."""
|
|
164
161
|
return (
|
|
@@ -166,6 +163,7 @@ class CommaSeparatedListOutputParser(ListOutputParser):
|
|
|
166
163
|
"eg: `foo, bar, baz` or `foo,bar,baz`"
|
|
167
164
|
)
|
|
168
165
|
|
|
166
|
+
@override
|
|
169
167
|
def parse(self, text: str) -> list[str]:
|
|
170
168
|
"""Parse the output of an LLM call.
|
|
171
169
|
|
|
@@ -213,15 +211,8 @@ class NumberedListOutputParser(ListOutputParser):
|
|
|
213
211
|
"""
|
|
214
212
|
return re.findall(self.pattern, text)
|
|
215
213
|
|
|
214
|
+
@override
|
|
216
215
|
def parse_iter(self, text: str) -> Iterator[re.Match]:
|
|
217
|
-
"""Parse the output of an LLM call.
|
|
218
|
-
|
|
219
|
-
Args:
|
|
220
|
-
text: The output of an LLM call.
|
|
221
|
-
|
|
222
|
-
Yields:
|
|
223
|
-
A match object for each part of the output.
|
|
224
|
-
"""
|
|
225
216
|
return re.finditer(self.pattern, text)
|
|
226
217
|
|
|
227
218
|
@property
|
|
@@ -235,6 +226,7 @@ class MarkdownListOutputParser(ListOutputParser):
|
|
|
235
226
|
pattern: str = r"^\s*[-*]\s([^\n]+)$"
|
|
236
227
|
"""The pattern to match a Markdown list item."""
|
|
237
228
|
|
|
229
|
+
@override
|
|
238
230
|
def get_format_instructions(self) -> str:
|
|
239
231
|
"""Return the format instructions for the Markdown list output."""
|
|
240
232
|
return "Your response should be a markdown list, eg: `- foo\n- bar\n- baz`"
|
|
@@ -250,15 +242,8 @@ class MarkdownListOutputParser(ListOutputParser):
|
|
|
250
242
|
"""
|
|
251
243
|
return re.findall(self.pattern, text, re.MULTILINE)
|
|
252
244
|
|
|
245
|
+
@override
|
|
253
246
|
def parse_iter(self, text: str) -> Iterator[re.Match]:
|
|
254
|
-
"""Parse the output of an LLM call.
|
|
255
|
-
|
|
256
|
-
Args:
|
|
257
|
-
text: The output of an LLM call.
|
|
258
|
-
|
|
259
|
-
Yields:
|
|
260
|
-
A match object for each part of the output.
|
|
261
|
-
"""
|
|
262
247
|
return re.finditer(self.pattern, text, re.MULTILINE)
|
|
263
248
|
|
|
264
249
|
@property
|
|
@@ -261,6 +261,9 @@ class PydanticOutputFunctionsParser(OutputFunctionsParser):
|
|
|
261
261
|
result: The result of the LLM call.
|
|
262
262
|
partial: Whether to parse partial JSON objects. Default is False.
|
|
263
263
|
|
|
264
|
+
Raises:
|
|
265
|
+
ValueError: If the pydantic schema is not valid.
|
|
266
|
+
|
|
264
267
|
Returns:
|
|
265
268
|
The parsed JSON object.
|
|
266
269
|
"""
|
|
@@ -231,6 +231,9 @@ class JsonOutputKeyToolsParser(JsonOutputToolsParser):
|
|
|
231
231
|
If False, the output will be the full JSON object.
|
|
232
232
|
Default is False.
|
|
233
233
|
|
|
234
|
+
Raises:
|
|
235
|
+
OutputParserException: If the generation is not a chat generation.
|
|
236
|
+
|
|
234
237
|
Returns:
|
|
235
238
|
The parsed tool calls.
|
|
236
239
|
"""
|
|
@@ -316,7 +319,9 @@ class PydanticToolsParser(JsonOutputToolsParser):
|
|
|
316
319
|
The parsed Pydantic objects.
|
|
317
320
|
|
|
318
321
|
Raises:
|
|
319
|
-
|
|
322
|
+
ValueError: If the tool call arguments are not a dict.
|
|
323
|
+
ValidationError: If the tool call arguments do not conform
|
|
324
|
+
to the Pydantic model.
|
|
320
325
|
"""
|
|
321
326
|
json_results = super().parse_result(result, partial=partial)
|
|
322
327
|
if not json_results:
|
|
@@ -54,6 +54,10 @@ class PydanticOutputParser(JsonOutputParser, Generic[TBaseModel]):
|
|
|
54
54
|
all the keys that have been returned so far.
|
|
55
55
|
Defaults to False.
|
|
56
56
|
|
|
57
|
+
Raises:
|
|
58
|
+
OutputParserException: If the result is not valid JSON
|
|
59
|
+
or does not conform to the pydantic model.
|
|
60
|
+
|
|
57
61
|
Returns:
|
|
58
62
|
The parsed pydantic object.
|
|
59
63
|
"""
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
"""String output parser."""
|
|
2
2
|
|
|
3
|
+
from typing_extensions import override
|
|
4
|
+
|
|
3
5
|
from langchain_core.output_parsers.transform import BaseTransformOutputParser
|
|
4
6
|
|
|
5
7
|
|
|
@@ -19,7 +21,8 @@ class StrOutputParser(BaseTransformOutputParser[str]):
|
|
|
19
21
|
def get_lc_namespace(cls) -> list[str]:
|
|
20
22
|
"""Get the namespace of the langchain object.
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Returns:
|
|
25
|
+
``["langchain", "schema", "output_parser"]``
|
|
23
26
|
"""
|
|
24
27
|
return ["langchain", "schema", "output_parser"]
|
|
25
28
|
|
|
@@ -28,6 +31,7 @@ class StrOutputParser(BaseTransformOutputParser[str]):
|
|
|
28
31
|
"""Return the output parser type for serialization."""
|
|
29
32
|
return "default"
|
|
30
33
|
|
|
34
|
+
@override
|
|
31
35
|
def parse(self, text: str) -> str:
|
|
32
36
|
"""Returns the input text with no changes."""
|
|
33
37
|
return text
|
|
@@ -15,6 +15,14 @@ from langchain_core.messages import BaseMessage
|
|
|
15
15
|
from langchain_core.output_parsers.transform import BaseTransformOutputParser
|
|
16
16
|
from langchain_core.runnables.utils import AddableDict
|
|
17
17
|
|
|
18
|
+
try:
|
|
19
|
+
from defusedxml import ElementTree # type: ignore[import-untyped]
|
|
20
|
+
from defusedxml.ElementTree import XMLParser # type: ignore[import-untyped]
|
|
21
|
+
|
|
22
|
+
_HAS_DEFUSEDXML = True
|
|
23
|
+
except ImportError:
|
|
24
|
+
_HAS_DEFUSEDXML = False
|
|
25
|
+
|
|
18
26
|
XML_FORMAT_INSTRUCTIONS = """The output should be formatted as a XML file.
|
|
19
27
|
1. Output should conform to the tags below.
|
|
20
28
|
2. If tags are not given, make them on your own.
|
|
@@ -50,17 +58,13 @@ class _StreamingParser:
|
|
|
50
58
|
parser is requested.
|
|
51
59
|
"""
|
|
52
60
|
if parser == "defusedxml":
|
|
53
|
-
|
|
54
|
-
from defusedxml.ElementTree import ( # type: ignore[import-untyped]
|
|
55
|
-
XMLParser,
|
|
56
|
-
)
|
|
57
|
-
except ImportError as e:
|
|
61
|
+
if not _HAS_DEFUSEDXML:
|
|
58
62
|
msg = (
|
|
59
63
|
"defusedxml is not installed. "
|
|
60
64
|
"Please install it to use the defusedxml parser."
|
|
61
65
|
"You can install it with `pip install defusedxml` "
|
|
62
66
|
)
|
|
63
|
-
raise ImportError(msg)
|
|
67
|
+
raise ImportError(msg)
|
|
64
68
|
parser_ = XMLParser(target=TreeBuilder())
|
|
65
69
|
else:
|
|
66
70
|
parser_ = None
|
|
@@ -136,9 +140,6 @@ class _StreamingParser:
|
|
|
136
140
|
"""Close the parser.
|
|
137
141
|
|
|
138
142
|
This should be called after all chunks have been parsed.
|
|
139
|
-
|
|
140
|
-
Raises:
|
|
141
|
-
xml.etree.ElementTree.ParseError: If the XML is not well-formed.
|
|
142
143
|
"""
|
|
143
144
|
# Ignore ParseError. This will ignore any incomplete XML at the end of the input
|
|
144
145
|
with contextlib.suppress(xml.etree.ElementTree.ParseError):
|
|
@@ -154,14 +155,15 @@ class XMLOutputParser(BaseTransformOutputParser):
|
|
|
154
155
|
Note this may not be perfect depending on the LLM implementation.
|
|
155
156
|
|
|
156
157
|
For example, with tags=["foo", "bar", "baz"]:
|
|
157
|
-
1. A well-formatted XML instance:
|
|
158
|
-
"<foo>\n <bar>\n <baz></baz>\n </bar>\n</foo>"
|
|
159
158
|
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
1. A well-formatted XML instance:
|
|
160
|
+
"<foo>\n <bar>\n <baz></baz>\n </bar>\n</foo>"
|
|
161
|
+
|
|
162
|
+
2. A badly-formatted XML instance (missing closing tag for 'bar'):
|
|
163
|
+
"<foo>\n <bar>\n </foo>"
|
|
162
164
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
3. A badly-formatted XML instance (unexpected 'tag' element):
|
|
166
|
+
"<foo>\n <tag>\n </tag>\n</foo>"
|
|
165
167
|
"""
|
|
166
168
|
encoding_matcher: re.Pattern = re.compile(
|
|
167
169
|
r"<([^>]*encoding[^>]*)>\n(.*)", re.MULTILINE | re.DOTALL
|
|
@@ -209,16 +211,14 @@ class XMLOutputParser(BaseTransformOutputParser):
|
|
|
209
211
|
# Imports are temporarily placed here to avoid issue with caching on CI
|
|
210
212
|
# likely if you're reading this you can move them to the top of the file
|
|
211
213
|
if self.parser == "defusedxml":
|
|
212
|
-
|
|
213
|
-
from defusedxml import ElementTree # type: ignore[import-untyped]
|
|
214
|
-
except ImportError as e:
|
|
214
|
+
if not _HAS_DEFUSEDXML:
|
|
215
215
|
msg = (
|
|
216
216
|
"defusedxml is not installed. "
|
|
217
217
|
"Please install it to use the defusedxml parser."
|
|
218
218
|
"You can install it with `pip install defusedxml`"
|
|
219
219
|
"See https://github.com/tiran/defusedxml for more details"
|
|
220
220
|
)
|
|
221
|
-
raise ImportError(msg)
|
|
221
|
+
raise ImportError(msg)
|
|
222
222
|
et = ElementTree # Use the defusedxml parser
|
|
223
223
|
else:
|
|
224
224
|
et = ET # Use the standard library parser
|
|
@@ -47,9 +47,6 @@ class ChatGeneration(Generation):
|
|
|
47
47
|
|
|
48
48
|
Returns:
|
|
49
49
|
The values of the object with the text attribute set.
|
|
50
|
-
|
|
51
|
-
Raises:
|
|
52
|
-
ValueError: If the message is not a string or a list.
|
|
53
50
|
"""
|
|
54
51
|
text = ""
|
|
55
52
|
if isinstance(self.message.content, str):
|
|
@@ -83,11 +80,18 @@ class ChatGenerationChunk(ChatGeneration):
|
|
|
83
80
|
def __add__(
|
|
84
81
|
self, other: Union[ChatGenerationChunk, list[ChatGenerationChunk]]
|
|
85
82
|
) -> ChatGenerationChunk:
|
|
86
|
-
"""Concatenate two
|
|
83
|
+
"""Concatenate two ``ChatGenerationChunk``s.
|
|
87
84
|
|
|
88
85
|
Args:
|
|
89
|
-
other: The other ChatGenerationChunk or list of
|
|
90
|
-
concatenate.
|
|
86
|
+
other: The other ``ChatGenerationChunk`` or list of ``ChatGenerationChunk``
|
|
87
|
+
to concatenate.
|
|
88
|
+
|
|
89
|
+
Raises:
|
|
90
|
+
TypeError: If other is not a ``ChatGenerationChunk`` or list of
|
|
91
|
+
``ChatGenerationChunk``.
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
A new ``ChatGenerationChunk`` concatenated from self and other.
|
|
91
95
|
"""
|
|
92
96
|
if isinstance(other, ChatGenerationChunk):
|
|
93
97
|
generation_info = merge_dicts(
|
|
@@ -116,7 +120,14 @@ class ChatGenerationChunk(ChatGeneration):
|
|
|
116
120
|
def merge_chat_generation_chunks(
|
|
117
121
|
chunks: list[ChatGenerationChunk],
|
|
118
122
|
) -> Union[ChatGenerationChunk, None]:
|
|
119
|
-
"""Merge a list of
|
|
123
|
+
"""Merge a list of ``ChatGenerationChunk``s into a single ``ChatGenerationChunk``.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
chunks: A list of ``ChatGenerationChunk`` to merge.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
A merged ``ChatGenerationChunk``, or None if the input list is empty.
|
|
130
|
+
"""
|
|
120
131
|
if not chunks:
|
|
121
132
|
return None
|
|
122
133
|
|
|
@@ -39,14 +39,15 @@ class Generation(Serializable):
|
|
|
39
39
|
|
|
40
40
|
@classmethod
|
|
41
41
|
def is_lc_serializable(cls) -> bool:
|
|
42
|
-
"""Return
|
|
42
|
+
"""Return True as this class is serializable."""
|
|
43
43
|
return True
|
|
44
44
|
|
|
45
45
|
@classmethod
|
|
46
46
|
def get_lc_namespace(cls) -> list[str]:
|
|
47
47
|
"""Get the namespace of the langchain object.
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
Returns:
|
|
50
|
+
``["langchain", "schema", "output"]``
|
|
50
51
|
"""
|
|
51
52
|
return ["langchain", "schema", "output"]
|
|
52
53
|
|
|
@@ -55,7 +56,17 @@ class GenerationChunk(Generation):
|
|
|
55
56
|
"""Generation chunk, which can be concatenated with other Generation chunks."""
|
|
56
57
|
|
|
57
58
|
def __add__(self, other: GenerationChunk) -> GenerationChunk:
|
|
58
|
-
"""Concatenate two
|
|
59
|
+
"""Concatenate two ``GenerationChunk``s.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
other: Another ``GenerationChunk`` to concatenate with.
|
|
63
|
+
|
|
64
|
+
Raises:
|
|
65
|
+
TypeError: If other is not a ``GenerationChunk``.
|
|
66
|
+
|
|
67
|
+
Returns:
|
|
68
|
+
A new ``GenerationChunk`` concatenated from self and other.
|
|
69
|
+
"""
|
|
59
70
|
if isinstance(other, GenerationChunk):
|
|
60
71
|
generation_info = merge_dicts(
|
|
61
72
|
self.generation_info or {},
|
|
@@ -91,7 +91,14 @@ class LLMResult(BaseModel):
|
|
|
91
91
|
return llm_results
|
|
92
92
|
|
|
93
93
|
def __eq__(self, other: object) -> bool:
|
|
94
|
-
"""Check for LLMResult equality by ignoring any metadata related to runs.
|
|
94
|
+
"""Check for ``LLMResult`` equality by ignoring any metadata related to runs.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
other: Another ``LLMResult`` object to compare against.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
True if the generations and ``llm_output`` are equal, False otherwise.
|
|
101
|
+
"""
|
|
95
102
|
if not isinstance(other, LLMResult):
|
|
96
103
|
return NotImplemented
|
|
97
104
|
return (
|
langchain_core/prompt_values.py
CHANGED
|
@@ -30,7 +30,7 @@ class PromptValue(Serializable, ABC):
|
|
|
30
30
|
|
|
31
31
|
@classmethod
|
|
32
32
|
def is_lc_serializable(cls) -> bool:
|
|
33
|
-
"""Return
|
|
33
|
+
"""Return True as this class is serializable."""
|
|
34
34
|
return True
|
|
35
35
|
|
|
36
36
|
@classmethod
|
|
@@ -38,7 +38,9 @@ class PromptValue(Serializable, ABC):
|
|
|
38
38
|
"""Get the namespace of the langchain object.
|
|
39
39
|
|
|
40
40
|
This is used to determine the namespace of the object when serializing.
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
``["langchain", "schema", "prompt"]``
|
|
42
44
|
"""
|
|
43
45
|
return ["langchain", "schema", "prompt"]
|
|
44
46
|
|
|
@@ -63,7 +65,9 @@ class StringPromptValue(PromptValue):
|
|
|
63
65
|
"""Get the namespace of the langchain object.
|
|
64
66
|
|
|
65
67
|
This is used to determine the namespace of the object when serializing.
|
|
66
|
-
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
``["langchain", "prompts", "base"]``
|
|
67
71
|
"""
|
|
68
72
|
return ["langchain", "prompts", "base"]
|
|
69
73
|
|
|
@@ -98,7 +102,9 @@ class ChatPromptValue(PromptValue):
|
|
|
98
102
|
"""Get the namespace of the langchain object.
|
|
99
103
|
|
|
100
104
|
This is used to determine the namespace of the object when serializing.
|
|
101
|
-
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
``["langchain", "prompts", "chat"]``
|
|
102
108
|
"""
|
|
103
109
|
return ["langchain", "prompts", "chat"]
|
|
104
110
|
|
langchain_core/prompts/base.py
CHANGED
|
@@ -101,16 +101,14 @@ class BasePromptTemplate(
|
|
|
101
101
|
def get_lc_namespace(cls) -> list[str]:
|
|
102
102
|
"""Get the namespace of the langchain object.
|
|
103
103
|
|
|
104
|
-
Returns
|
|
104
|
+
Returns:
|
|
105
|
+
``["langchain", "schema", "prompt_template"]``
|
|
105
106
|
"""
|
|
106
107
|
return ["langchain", "schema", "prompt_template"]
|
|
107
108
|
|
|
108
109
|
@classmethod
|
|
109
110
|
def is_lc_serializable(cls) -> bool:
|
|
110
|
-
"""Return
|
|
111
|
-
|
|
112
|
-
Returns True.
|
|
113
|
-
"""
|
|
111
|
+
"""Return True as this class is serializable."""
|
|
114
112
|
return True
|
|
115
113
|
|
|
116
114
|
model_config = ConfigDict(
|
|
@@ -212,7 +210,7 @@ class BasePromptTemplate(
|
|
|
212
210
|
if self.metadata:
|
|
213
211
|
config["metadata"] = {**config["metadata"], **self.metadata}
|
|
214
212
|
if self.tags:
|
|
215
|
-
config["tags"]
|
|
213
|
+
config["tags"] += self.tags
|
|
216
214
|
return self._call_with_config(
|
|
217
215
|
self._format_prompt_with_error_handling,
|
|
218
216
|
input,
|
|
@@ -341,9 +339,6 @@ class BasePromptTemplate(
|
|
|
341
339
|
|
|
342
340
|
Returns:
|
|
343
341
|
Dict: Dictionary representation of the prompt.
|
|
344
|
-
|
|
345
|
-
Raises:
|
|
346
|
-
NotImplementedError: If the prompt type is not implemented.
|
|
347
342
|
"""
|
|
348
343
|
prompt_dict = super().model_dump(**kwargs)
|
|
349
344
|
with contextlib.suppress(NotImplementedError):
|