Skip to content

Commit

Permalink
Add possibility to pass on_artifacts for a specific conversation (lan…
Browse files Browse the repository at this point in the history
…gchain-ai#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
    },
)
```
  • Loading branch information
jakubno authored and xieqihui committed Nov 21, 2023
1 parent dcd84c3 commit f090330
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions libs/langchain/langchain/tools/e2b_data_analysis/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManager,
CallbackManagerForToolRun,
)
from langchain.pydantic_v1 import BaseModel, Field, PrivateAttr
Expand Down Expand Up @@ -151,14 +152,26 @@ 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: 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)

Expand Down

0 comments on commit f090330

Please sign in to comment.