GPT LangChain experimental agent - allow dangerous code

**题意:**GPT LangChain 实验性代理 - 允许危险代码

问题背景:

I'm creating a chatbot in VS Code where it will receive csv file through a prompt on Streamlit interface. However from the moment that file is loaded, it is showing a message with the following content:

ValueError: This agent relies on access to a python repl tool which can execute arbitrary code. This can be dangerous and requires a specially sandboxed environment to be safely used. Please read the security notice in the doc-string of this function. You must opt-in to use this functionality by setting allow_dangerous_code=True.For general security guidelines, please see: Security | 🦜️🔗 LangChain

Traceback

python 复制代码
File "c:\Users\  \langchain-ask-csv\.venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 589, in _run_script
    exec(code, module.__dict__)
File "C:\Users\ \langchain-ask-csv\main.py", line 46, in <module>
    main()
File "C:\Users\  \langchain-ask-csv\main.py", line 35, in main
    agent = create_csv_agent( OpenAI(), csv_file, verbose=True)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\
\langchain-ask-csv\.venv\Lib\site-packages\langchain_experimental\agents\agent_toolkits\csv\base.py", line 66, in create_csv_agent
    return create_pandas_dataframe_agent(llm, df, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\ T\langchain-ask-csv\.venv\Lib\site-packages\langchain_experimental\agents\agent_toolkits\pandas\base.py", line 248, in create_pandas_dataframe_agent
    raise ValueError(

Here's is part of the code where I'm passing the file:

python 复制代码
def main():
    load_dotenv()
    
    # Load the OpenAI API key from the environment variable
    if os.getenv("OPENAI_API_KEY") is None or os.getenv("OPENAI_API_KEY") == "":
        print("OPENAI_API_KEY is not set")
        exit(1)
    else:
        print("OPENAI_API_KEY is set")

    st.set_page_config(page_title="Ask your CSV")
    st.header("Ask your CSV 📈")

    csv_file = st.file_uploader("Upload a CSV file", type="csv")
    if csv_file is not None:

        agent = create_csv_agent( OpenAI(), csv_file, verbose=True)

        user_question = st.text_input("Ask a question about your CSV: ")
        
        if user_question is not None and user_question != "":
            with st.spinner(text="In progress..."):
                st.write(agent.run(user_question))
      

if __name__ == "__main__":
    main()

I checked the link given as suggestion and also tried to search on similar reports but haven't had success.

What might be wrong and how to fix it?

问题解决:

The referenced security notice is in langchain_experimental.agents.agent_toolkits.pandas.base.create_pandas_dataframe_agent --- 🦜🔗 LangChain 0.2.8.

Just do what the message tells you. Do a security analysis, create a sandbox environment for your thing to run in, and then add allow_dangerous_code=True to the arguments you pass to create_csv_agent, which just forwards the argument to create_pandas_dataframe_agent and run it in the sandbox.

相关推荐
大雨淅淅4 分钟前
【机器人】ROS2 机械臂控制(MoveIt2)从入门到实战
人工智能·python·神经网络·学习·算法·机器学习·机器人
可乐ea18 分钟前
【知识获取与分享社区项目 | 项目日记第 24 天】终章总结:从认证、发布、计数、Feed、搜索到 RAG:完整复盘一个知识社区后端系统
java·spring boot·redis·mysql·elasticsearch·ai·kafka
张哈大28 分钟前
MCP:重塑AI工具调用的统一标准,告别重复造轮子的时代
人工智能·python·ai·prompt
极光代码工作室29 分钟前
基于深度学习的智能图像识别平台
python·深度学习·机器学习·ai·系统设计
copyer_xyf34 分钟前
Python 文件基本操作
前端·后端·python
嘶哈哈哈36 分钟前
# SolidWorks 启动提示“无法获得下列许可 SOLIDWORKS Standard”的解决思路
python
一条咸鱼_SaltyFish38 分钟前
Agent 工程化避坑指南——从实践看常见反模式
ai·agent·ai编程·memory·obsidian·harness·llm-wiki
zh路西法42 分钟前
【rosbridge-websocket】跨网络的ROS1与ROS2通讯法(上)
linux·网络·c++·python·websocket·网络协议
圆弧YH43 分钟前
python→ Language
python
装不满的克莱因瓶1 小时前
掌握神经网络的模型结构
人工智能·python·深度学习·神经网络·机器学习·ai