langchain-ai / langchain

🦜🔗 Build context-aware reasoning applications
https://python.langchain.com
MIT License
91.19k stars 14.49k forks source link

E2B DataAnalysisTool() function not working correctly #23392

Open sarthakkaushik opened 2 months ago

sarthakkaushik commented 2 months ago

Checked other resources

Example Code

!pip install --upgrade langchain e2b langchain-community

  1. Set up the environment variables for E2B and OpenAI API keys.
  2. Run the following python code:
from langchain_community.tools import E2BDataAnalysisTool
import os
from langchain.agents import AgentType, initialize_agent
from langchain_openai import ChatOpenAI

os.environ["E2B_API_KEY"] = "<E2B_API_KEY>"
os.environ["OPENAI_API_KEY"] = "<OPENAI_API_KEY>"

def save_artifact(artifact):
    print("New matplotlib chart generated:", artifact.name)
    file = artifact.download()
    basename = os.path.basename(artifact.name)
    with open(f"./charts/{basename}", "wb") as f:
        f.write(file)

e2b_data_analysis_tool = E2BDataAnalysisTool(
    env_vars={"MY_SECRET": "secret_value"},
    on_stdout=lambda stdout: print("stdout:", stdout),
    on_stderr=lambda stderr: print("stderr:", stderr),
    on_artifact=save_artifact,
)

Error Message and Stack Trace (if applicable)

Error Message

_ImportError: cannot import name 'DataAnalysis' from 'e2b' (c:\Users\sarthak kaushik\OneDrive\Desktop\Test_Project_Python\e2b\myenv\Lib\site-packages\e2b__init__.py)

The above exception was the direct cause of the following exception:

ImportError: Unable to import e2b, please install with pip install e2b_

Description

When trying to use the E2BDataAnalysisTool from the _langchain_community.tools_ module, I'm encountering an ImportError. The error suggests that the DataAnalysis class cannot be imported from the e2b package.

Expected Behavior: The E2BDataAnalysisTool should initialize without any import errors.

Additional Context I have already installed the e2b package as suggested in the error message, but the issue persists.

Possible Solution It seems that there might be a discrepancy between the expected structure of the e2b package and what's actually installed. Could there be a version mismatch or a change in the package structure that hasn't been reflected in the LangChain community tools?

System Info

System Information

OS: Windows OS Version: 10.0.19045 Python Version: 3.12.3

Package Information

langchain_core: 0.2.9 langchain: 0.2.5 langchain_community: 0.2.5 langsmith: 0.1.82 langchain_openai: 0.1.9 langchain_text_splitters: 0.2.1

praj98 commented 1 month ago

i am also facing the same issue please someone from langchain help us on this issue

jondoescoding commented 1 month ago

Facing the same issue.

sarthakkaushik commented 4 weeks ago

can some one please take this up and update the issue ?

isahers1 commented 1 week ago

Sorry for the delay, we are aware of the issue and are working on a fix for the near future

isaacwasserman commented 1 week ago

The E2B Python SDK has removed the DataAnalysis module, and created a separate SDK for this purpose: e2b-dev/code-interpreter. Also see e2b-dev/E2B#383. However, it doesn't appear to be a drop-in replacement, and some work will be necessary to migrate the E2BDataAnalysisTool() and associated documentation.