langchain-core 0.3.74__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 +18 -41
- langchain_core/_api/deprecation.py +20 -7
- 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 +2 -3
- langchain_core/callbacks/base.py +11 -4
- langchain_core/callbacks/file.py +13 -2
- langchain_core/callbacks/manager.py +129 -78
- langchain_core/callbacks/usage.py +4 -2
- langchain_core/chat_history.py +10 -12
- langchain_core/document_loaders/base.py +34 -9
- langchain_core/document_loaders/langsmith.py +3 -0
- langchain_core/documents/base.py +36 -11
- langchain_core/documents/compressor.py +9 -6
- 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 +7 -10
- langchain_core/indexing/in_memory.py +23 -3
- langchain_core/language_models/__init__.py +3 -2
- langchain_core/language_models/base.py +64 -39
- langchain_core/language_models/chat_models.py +130 -42
- langchain_core/language_models/fake_chat_models.py +10 -11
- langchain_core/language_models/llms.py +49 -17
- langchain_core/load/dump.py +5 -7
- 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 -16
- 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/modifier.py +1 -1
- langchain_core/messages/system.py +2 -6
- langchain_core/messages/tool.py +36 -16
- langchain_core/messages/utils.py +198 -87
- 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 +8 -1
- langchain_core/output_parsers/pydantic.py +4 -0
- langchain_core/output_parsers/string.py +5 -1
- langchain_core/output_parsers/transform.py +2 -2
- langchain_core/output_parsers/xml.py +23 -22
- 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 +88 -61
- 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 +842 -567
- langchain_core/runnables/branch.py +15 -20
- langchain_core/runnables/config.py +11 -17
- langchain_core/runnables/configurable.py +34 -19
- langchain_core/runnables/fallbacks.py +24 -17
- langchain_core/runnables/graph.py +47 -40
- 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 +56 -59
- langchain_core/runnables/passthrough.py +47 -24
- langchain_core/runnables/retry.py +10 -6
- langchain_core/runnables/router.py +10 -9
- langchain_core/runnables/schema.py +2 -0
- langchain_core/runnables/utils.py +51 -89
- langchain_core/stores.py +13 -25
- langchain_core/structured_query.py +3 -7
- 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 +26 -3
- langchain_core/tracers/_streaming.py +6 -7
- 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 +41 -28
- langchain_core/tracers/langchain.py +12 -3
- langchain_core/tracers/langchain_v1.py +10 -2
- langchain_core/tracers/log_stream.py +57 -18
- 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 +49 -30
- 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.74.dist-info/METADATA +0 -108
- langchain_core-0.3.74.dist-info/RECORD +0 -174
- {langchain_core-0.3.74.dist-info → langchain_core-0.3.76.dist-info}/WHEEL +0 -0
- {langchain_core-0.3.74.dist-info → langchain_core-0.3.76.dist-info}/entry_points.txt +0 -0
|
@@ -63,6 +63,9 @@ def beta(
|
|
|
63
63
|
addendum : str, optional
|
|
64
64
|
Additional text appended directly to the final message.
|
|
65
65
|
|
|
66
|
+
Returns:
|
|
67
|
+
A decorator which can be used to mark functions or classes as beta.
|
|
68
|
+
|
|
66
69
|
Examples:
|
|
67
70
|
|
|
68
71
|
.. code-block:: python
|
|
@@ -144,59 +147,33 @@ def beta(
|
|
|
144
147
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
|
145
148
|
warn_if_direct_instance
|
|
146
149
|
)
|
|
147
|
-
return
|
|
150
|
+
return obj
|
|
148
151
|
|
|
149
152
|
elif isinstance(obj, property):
|
|
150
|
-
# note(erick): this block doesn't seem to be used?
|
|
151
153
|
if not _obj_type:
|
|
152
154
|
_obj_type = "attribute"
|
|
153
155
|
wrapped = None
|
|
154
156
|
_name = _name or obj.fget.__qualname__
|
|
155
157
|
old_doc = obj.__doc__
|
|
156
158
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
self,
|
|
162
|
-
fget: Union[Callable[[Any], Any], None] = None,
|
|
163
|
-
fset: Union[Callable[[Any, Any], None], None] = None,
|
|
164
|
-
fdel: Union[Callable[[Any], None], None] = None,
|
|
165
|
-
doc: Union[str, None] = None,
|
|
166
|
-
) -> None:
|
|
167
|
-
super().__init__(fget, fset, fdel, doc)
|
|
168
|
-
self.__orig_fget = fget
|
|
169
|
-
self.__orig_fset = fset
|
|
170
|
-
self.__orig_fdel = fdel
|
|
171
|
-
|
|
172
|
-
def __get__(
|
|
173
|
-
self, instance: Any, owner: Union[type, None] = None
|
|
174
|
-
) -> Any:
|
|
175
|
-
if instance is not None or owner is not None:
|
|
176
|
-
emit_warning()
|
|
177
|
-
return self.fget(instance)
|
|
178
|
-
|
|
179
|
-
def __set__(self, instance: Any, value: Any) -> None:
|
|
180
|
-
if instance is not None:
|
|
181
|
-
emit_warning()
|
|
182
|
-
return self.fset(instance, value)
|
|
159
|
+
def _fget(instance: Any) -> Any:
|
|
160
|
+
if instance is not None:
|
|
161
|
+
emit_warning()
|
|
162
|
+
return obj.fget(instance)
|
|
183
163
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
164
|
+
def _fset(instance: Any, value: Any) -> None:
|
|
165
|
+
if instance is not None:
|
|
166
|
+
emit_warning()
|
|
167
|
+
obj.fset(instance, value)
|
|
188
168
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
169
|
+
def _fdel(instance: Any) -> None:
|
|
170
|
+
if instance is not None:
|
|
171
|
+
emit_warning()
|
|
172
|
+
obj.fdel(instance)
|
|
193
173
|
|
|
194
|
-
def finalize(
|
|
174
|
+
def finalize(_wrapper: Callable[..., Any], new_doc: str) -> Any:
|
|
195
175
|
"""Finalize the property."""
|
|
196
|
-
return
|
|
197
|
-
fget=obj.fget, fset=obj.fset, fdel=obj.fdel, doc=new_doc
|
|
198
|
-
)
|
|
199
|
-
|
|
176
|
+
return property(fget=_fget, fset=_fset, fdel=_fdel, doc=new_doc)
|
|
200
177
|
else:
|
|
201
178
|
_name = _name or obj.__qualname__
|
|
202
179
|
if not _obj_type:
|
|
@@ -129,11 +129,14 @@ def deprecated(
|
|
|
129
129
|
package: str, optional
|
|
130
130
|
The package of the deprecated object.
|
|
131
131
|
|
|
132
|
+
Returns:
|
|
133
|
+
A decorator to mark a function or class as deprecated.
|
|
134
|
+
|
|
132
135
|
Examples:
|
|
133
136
|
|
|
134
137
|
.. code-block:: python
|
|
135
138
|
|
|
136
|
-
@deprecated(
|
|
139
|
+
@deprecated("1.4.0")
|
|
137
140
|
def the_function_to_deprecate():
|
|
138
141
|
pass
|
|
139
142
|
|
|
@@ -225,7 +228,7 @@ def deprecated(
|
|
|
225
228
|
obj.__init__ = functools.wraps(obj.__init__)( # type: ignore[misc]
|
|
226
229
|
warn_if_direct_instance
|
|
227
230
|
)
|
|
228
|
-
return
|
|
231
|
+
return obj
|
|
229
232
|
|
|
230
233
|
elif isinstance(obj, FieldInfoV1):
|
|
231
234
|
wrapped = None
|
|
@@ -358,7 +361,8 @@ def deprecated(
|
|
|
358
361
|
# Modify the docstring to include a deprecation notice.
|
|
359
362
|
if (
|
|
360
363
|
_alternative
|
|
361
|
-
and _alternative.
|
|
364
|
+
and _alternative.rsplit(".", maxsplit=1)[-1].lower()
|
|
365
|
+
== _alternative.rsplit(".", maxsplit=1)[-1]
|
|
362
366
|
):
|
|
363
367
|
_alternative = f":meth:`~{_alternative}`"
|
|
364
368
|
elif _alternative:
|
|
@@ -366,8 +370,8 @@ def deprecated(
|
|
|
366
370
|
|
|
367
371
|
if (
|
|
368
372
|
_alternative_import
|
|
369
|
-
and _alternative_import.
|
|
370
|
-
== _alternative_import.
|
|
373
|
+
and _alternative_import.rsplit(".", maxsplit=1)[-1].lower()
|
|
374
|
+
== _alternative_import.rsplit(".", maxsplit=1)[-1]
|
|
371
375
|
):
|
|
372
376
|
_alternative_import = f":meth:`~{_alternative_import}`"
|
|
373
377
|
elif _alternative_import:
|
|
@@ -471,7 +475,7 @@ def warn_deprecated(
|
|
|
471
475
|
if not message:
|
|
472
476
|
message = ""
|
|
473
477
|
package_ = (
|
|
474
|
-
package or name.split(".")[0].replace("_", "-")
|
|
478
|
+
package or name.split(".", maxsplit=1)[0].replace("_", "-")
|
|
475
479
|
if "." in name
|
|
476
480
|
else "LangChain"
|
|
477
481
|
)
|
|
@@ -490,7 +494,7 @@ def warn_deprecated(
|
|
|
490
494
|
message += f" and will be removed {removal}"
|
|
491
495
|
|
|
492
496
|
if alternative_import:
|
|
493
|
-
alt_package = alternative_import.split(".")[0].replace("_", "-")
|
|
497
|
+
alt_package = alternative_import.split(".", maxsplit=1)[0].replace("_", "-")
|
|
494
498
|
if alt_package == package_:
|
|
495
499
|
message += f". Use {alternative_import} instead."
|
|
496
500
|
else:
|
|
@@ -544,6 +548,15 @@ def rename_parameter(
|
|
|
544
548
|
is passed to *func*, a DeprecationWarning is emitted, and its value is
|
|
545
549
|
used, even if *new* is also passed by keyword.
|
|
546
550
|
|
|
551
|
+
Args:
|
|
552
|
+
since: The version in which the parameter was renamed.
|
|
553
|
+
removal: The version in which the old parameter will be removed.
|
|
554
|
+
old: The old parameter name.
|
|
555
|
+
new: The new parameter name.
|
|
556
|
+
|
|
557
|
+
Returns:
|
|
558
|
+
A decorator indicating that a parameter was renamed.
|
|
559
|
+
|
|
547
560
|
Example:
|
|
548
561
|
|
|
549
562
|
.. code-block:: python
|
langchain_core/_api/path.py
CHANGED
|
@@ -12,7 +12,15 @@ SEPARATOR = os.sep
|
|
|
12
12
|
def get_relative_path(
|
|
13
13
|
file: Union[Path, str], *, relative_to: Path = PACKAGE_DIR
|
|
14
14
|
) -> str:
|
|
15
|
-
"""Get the path of the file as a relative path to the package directory.
|
|
15
|
+
"""Get the path of the file as a relative path to the package directory.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
file: The file path to convert.
|
|
19
|
+
relative_to: The base path to make the file path relative to.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
The relative path as a string.
|
|
23
|
+
"""
|
|
16
24
|
if isinstance(file, str):
|
|
17
25
|
file = Path(file)
|
|
18
26
|
return str(file.relative_to(relative_to))
|
|
@@ -24,7 +32,16 @@ def as_import_path(
|
|
|
24
32
|
suffix: Optional[str] = None,
|
|
25
33
|
relative_to: Path = PACKAGE_DIR,
|
|
26
34
|
) -> str:
|
|
27
|
-
"""Path of the file as a LangChain import exclude langchain top namespace.
|
|
35
|
+
"""Path of the file as a LangChain import exclude langchain top namespace.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
file: The file path to convert.
|
|
39
|
+
suffix: An optional suffix to append to the import path.
|
|
40
|
+
relative_to: The base path to make the file path relative to.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
The import path as a string.
|
|
44
|
+
"""
|
|
28
45
|
if isinstance(file, str):
|
|
29
46
|
file = Path(file)
|
|
30
47
|
path = get_relative_path(file, relative_to=relative_to)
|
langchain_core/_import_utils.py
CHANGED
|
@@ -17,6 +17,13 @@ def import_attr(
|
|
|
17
17
|
module_name: The name of the module to import from. If None, the attribute
|
|
18
18
|
is imported from the package itself.
|
|
19
19
|
package: The name of the package where the module is located.
|
|
20
|
+
|
|
21
|
+
Raises:
|
|
22
|
+
ImportError: If the module cannot be found.
|
|
23
|
+
AttributeError: If the attribute does not exist in the module or package.
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
The imported attribute.
|
|
20
27
|
"""
|
|
21
28
|
if module_name == "__module__" or module_name is None:
|
|
22
29
|
try:
|
langchain_core/agents.py
CHANGED
|
@@ -14,13 +14,15 @@ Agents use language models to choose a sequence of actions to take.
|
|
|
14
14
|
|
|
15
15
|
A basic agent works in the following manner:
|
|
16
16
|
|
|
17
|
-
1. Given a prompt an agent uses an LLM to request an action to take
|
|
17
|
+
1. Given a prompt an agent uses an LLM to request an action to take
|
|
18
|
+
(e.g., a tool to run).
|
|
18
19
|
2. The agent executes the action (e.g., runs the tool), and receives an observation.
|
|
19
|
-
3. The agent returns the observation to the LLM, which can then be used to generate
|
|
20
|
+
3. The agent returns the observation to the LLM, which can then be used to generate
|
|
21
|
+
the next action.
|
|
20
22
|
4. When the agent reaches a stopping condition, it returns a final return value.
|
|
21
23
|
|
|
22
24
|
The schemas for the agents themselves are defined in langchain.agents.agent.
|
|
23
|
-
"""
|
|
25
|
+
"""
|
|
24
26
|
|
|
25
27
|
from __future__ import annotations
|
|
26
28
|
|
|
@@ -84,7 +86,8 @@ class AgentAction(Serializable):
|
|
|
84
86
|
def get_lc_namespace(cls) -> list[str]:
|
|
85
87
|
"""Get the namespace of the langchain object.
|
|
86
88
|
|
|
87
|
-
|
|
89
|
+
Returns:
|
|
90
|
+
``["langchain", "schema", "agent"]``
|
|
88
91
|
"""
|
|
89
92
|
return ["langchain", "schema", "agent"]
|
|
90
93
|
|
|
@@ -153,14 +156,15 @@ class AgentFinish(Serializable):
|
|
|
153
156
|
|
|
154
157
|
@classmethod
|
|
155
158
|
def is_lc_serializable(cls) -> bool:
|
|
156
|
-
"""Return
|
|
159
|
+
"""Return True as this class is serializable."""
|
|
157
160
|
return True
|
|
158
161
|
|
|
159
162
|
@classmethod
|
|
160
163
|
def get_lc_namespace(cls) -> list[str]:
|
|
161
164
|
"""Get the namespace of the langchain object.
|
|
162
165
|
|
|
163
|
-
|
|
166
|
+
Returns:
|
|
167
|
+
``["langchain", "schema", "agent"]``
|
|
164
168
|
"""
|
|
165
169
|
return ["langchain", "schema", "agent"]
|
|
166
170
|
|
|
@@ -253,7 +253,7 @@ class ContextSet(RunnableSerializable):
|
|
|
253
253
|
"""
|
|
254
254
|
if key is not None:
|
|
255
255
|
kwargs[key] = value
|
|
256
|
-
super().__init__(
|
|
256
|
+
super().__init__(
|
|
257
257
|
keys={
|
|
258
258
|
k: _coerce_set_value(v) if v is not None else None
|
|
259
259
|
for k, v in kwargs.items()
|
|
@@ -344,8 +344,7 @@ class Context:
|
|
|
344
344
|
chain = (
|
|
345
345
|
Context.setter("input")
|
|
346
346
|
| {
|
|
347
|
-
"context": RunnablePassthrough()
|
|
348
|
-
| Context.setter("context"),
|
|
347
|
+
"context": RunnablePassthrough() | Context.setter("context"),
|
|
349
348
|
"question": RunnablePassthrough(),
|
|
350
349
|
}
|
|
351
350
|
| PromptTemplate.from_template("{context} {question}")
|
langchain_core/callbacks/base.py
CHANGED
|
@@ -922,7 +922,7 @@ class BaseCallbackManager(CallbackManagerMixin):
|
|
|
922
922
|
self.inheritable_metadata = inheritable_metadata or {}
|
|
923
923
|
|
|
924
924
|
def copy(self) -> Self:
|
|
925
|
-
"""
|
|
925
|
+
"""Return a copy of the callback manager."""
|
|
926
926
|
return self.__class__(
|
|
927
927
|
handlers=self.handlers.copy(),
|
|
928
928
|
inheritable_handlers=self.inheritable_handlers.copy(),
|
|
@@ -947,11 +947,18 @@ class BaseCallbackManager(CallbackManagerMixin):
|
|
|
947
947
|
|
|
948
948
|
.. code-block:: python
|
|
949
949
|
|
|
950
|
-
from langchain_core.callbacks.manager import
|
|
950
|
+
from langchain_core.callbacks.manager import (
|
|
951
|
+
CallbackManager,
|
|
952
|
+
trace_as_chain_group,
|
|
953
|
+
)
|
|
951
954
|
from langchain_core.callbacks.stdout import StdOutCallbackHandler
|
|
952
955
|
|
|
953
|
-
manager = CallbackManager(
|
|
954
|
-
|
|
956
|
+
manager = CallbackManager(
|
|
957
|
+
handlers=[StdOutCallbackHandler()], tags=["tag2"]
|
|
958
|
+
)
|
|
959
|
+
with trace_as_chain_group(
|
|
960
|
+
"My Group Name", tags=["tag1"]
|
|
961
|
+
) as group_manager:
|
|
955
962
|
merged_manager = group_manager.merge(manager)
|
|
956
963
|
print(merged_manager.handlers)
|
|
957
964
|
# [
|
langchain_core/callbacks/file.py
CHANGED
|
@@ -49,7 +49,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
49
49
|
mode: The file open mode. Defaults to ``'a'`` (append).
|
|
50
50
|
color: Default color for text output. Defaults to ``None``.
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
.. note::
|
|
53
53
|
When not used as a context manager, a deprecation warning will be issued
|
|
54
54
|
on first use. The file will be opened immediately in ``__init__`` and closed
|
|
55
55
|
in ``__del__`` or when ``close()`` is called explicitly.
|
|
@@ -65,6 +65,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
65
65
|
filename: Path to the output file.
|
|
66
66
|
mode: File open mode (e.g., ``'w'``, ``'a'``, ``'x'``). Defaults to ``'a'``.
|
|
67
67
|
color: Default text color for output. Defaults to ``None``.
|
|
68
|
+
|
|
68
69
|
"""
|
|
69
70
|
self.filename = filename
|
|
70
71
|
self.mode = mode
|
|
@@ -82,9 +83,10 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
82
83
|
Returns:
|
|
83
84
|
The FileCallbackHandler instance.
|
|
84
85
|
|
|
85
|
-
|
|
86
|
+
.. note::
|
|
86
87
|
The file is already opened in ``__init__``, so this just marks that
|
|
87
88
|
the handler is being used as a context manager.
|
|
89
|
+
|
|
88
90
|
"""
|
|
89
91
|
self._file_opened_in_context = True
|
|
90
92
|
return self
|
|
@@ -101,6 +103,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
101
103
|
exc_type: Exception type if an exception occurred.
|
|
102
104
|
exc_val: Exception value if an exception occurred.
|
|
103
105
|
exc_tb: Exception traceback if an exception occurred.
|
|
106
|
+
|
|
104
107
|
"""
|
|
105
108
|
self.close()
|
|
106
109
|
|
|
@@ -113,6 +116,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
113
116
|
|
|
114
117
|
This method is safe to call multiple times and will only close
|
|
115
118
|
the file if it's currently open.
|
|
119
|
+
|
|
116
120
|
"""
|
|
117
121
|
if hasattr(self, "file") and self.file and not self.file.closed:
|
|
118
122
|
self.file.close()
|
|
@@ -133,6 +137,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
133
137
|
|
|
134
138
|
Raises:
|
|
135
139
|
RuntimeError: If the file is closed or not available.
|
|
140
|
+
|
|
136
141
|
"""
|
|
137
142
|
global _GLOBAL_DEPRECATION_WARNED # noqa: PLW0603
|
|
138
143
|
if not self._file_opened_in_context and not _GLOBAL_DEPRECATION_WARNED:
|
|
@@ -163,6 +168,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
163
168
|
serialized: The serialized chain information.
|
|
164
169
|
inputs: The inputs to the chain.
|
|
165
170
|
**kwargs: Additional keyword arguments that may contain ``'name'``.
|
|
171
|
+
|
|
166
172
|
"""
|
|
167
173
|
name = (
|
|
168
174
|
kwargs.get("name")
|
|
@@ -178,6 +184,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
178
184
|
Args:
|
|
179
185
|
outputs: The outputs of the chain.
|
|
180
186
|
**kwargs: Additional keyword arguments.
|
|
187
|
+
|
|
181
188
|
"""
|
|
182
189
|
self._write("\n> Finished chain.", end="\n")
|
|
183
190
|
|
|
@@ -192,6 +199,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
192
199
|
color: Color override for this specific output. If ``None``, uses
|
|
193
200
|
``self.color``.
|
|
194
201
|
**kwargs: Additional keyword arguments.
|
|
202
|
+
|
|
195
203
|
"""
|
|
196
204
|
self._write(action.log, color=color or self.color)
|
|
197
205
|
|
|
@@ -213,6 +221,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
213
221
|
observation_prefix: Optional prefix to write before the output.
|
|
214
222
|
llm_prefix: Optional prefix to write after the output.
|
|
215
223
|
**kwargs: Additional keyword arguments.
|
|
224
|
+
|
|
216
225
|
"""
|
|
217
226
|
if observation_prefix is not None:
|
|
218
227
|
self._write(f"\n{observation_prefix}")
|
|
@@ -232,6 +241,7 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
232
241
|
``self.color``.
|
|
233
242
|
end: String appended after the text. Defaults to ``""``.
|
|
234
243
|
**kwargs: Additional keyword arguments.
|
|
244
|
+
|
|
235
245
|
"""
|
|
236
246
|
self._write(text, color=color or self.color, end=end)
|
|
237
247
|
|
|
@@ -246,5 +256,6 @@ class FileCallbackHandler(BaseCallbackHandler):
|
|
|
246
256
|
color: Color override for this specific output. If ``None``, uses
|
|
247
257
|
``self.color``.
|
|
248
258
|
**kwargs: Additional keyword arguments.
|
|
259
|
+
|
|
249
260
|
"""
|
|
250
261
|
self._write(finish.log, color=color or self.color, end="\n")
|