mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 21:33:51 +00:00
Add possibility to pass on_artifacts for a specific conversation (#12687)
Possibility to pass on_artifacts to a conversation. It can be then achieved by adding this way: ```python result = agent.run( input=message.text, metadata={ "on_artifact": CALLBACK_FUNCTION }, ) ```
This commit is contained in:
parent
0378662e1d
commit
ada3d2cbd1
@ -9,6 +9,7 @@ from typing import IO, TYPE_CHECKING, Any, Callable, List, Optional, Type
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForToolRun,
|
||||
CallbackManager,
|
||||
CallbackManagerForToolRun,
|
||||
)
|
||||
from langchain.pydantic_v1 import BaseModel, Field, PrivateAttr
|
||||
@ -151,14 +152,26 @@ class E2BDataAnalysisTool(BaseTool):
|
||||
return "\n".join(lines)
|
||||
|
||||
def _run(
|
||||
self, python_code: str, run_manager: Optional[CallbackManagerForToolRun] = None
|
||||
self,
|
||||
python_code: str,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
callbacks: Optional[CallbackManager] = None,
|
||||
) -> str:
|
||||
python_code = add_last_line_print(python_code)
|
||||
stdout, stderr, _ = self.session.run_python(python_code)
|
||||
|
||||
if callbacks is not None:
|
||||
on_artifact = getattr(callbacks.metadata, "on_artifact", None)
|
||||
else:
|
||||
on_artifact = None
|
||||
|
||||
stdout, stderr, artifacts = self.session.run_python(
|
||||
python_code, on_artifact=on_artifact
|
||||
)
|
||||
|
||||
out = {
|
||||
"stdout": stdout,
|
||||
"stderr": stderr,
|
||||
"artifacts": list(map(lambda artifact: artifact.name, artifacts)),
|
||||
}
|
||||
return json.dumps(out)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user