Skip to content

Commit

Permalink
Add possibility to alter on_artifacts for a conversation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubno committed Nov 1, 2023
1 parent 2c36ab9 commit 0307f1c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libs/langchain/langchain/tools/e2b_data_analysis/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
CallbackManager,
)
from langchain.pydantic_v1 import BaseModel, Field, PrivateAttr
from langchain.tools import BaseTool, Tool
Expand Down Expand Up @@ -151,14 +152,21 @@ def uploaded_files_description(self) -> str:
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: CallbackManager = None,
) -> str:
python_code = add_last_line_print(python_code)
stdout, stderr, _ = self.session.run_python(python_code)
on_artifact = getattr(callbacks.metadata, "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)

Expand Down

0 comments on commit 0307f1c

Please sign in to comment.