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.

相关推荐
南方程序猴2 分钟前
Windows一键安装Codex所有环境
人工智能·gpt·ai·chatgpt·ai编程
吾AI科技12 分钟前
Agent的诞生(三):Skill —— 让模型掌握处理复杂流程的能力
ai·agent·智能体
智驾18 分钟前
API Error: 400 messages...... 解决方案
ai·claude·kimi
FIT2CLOUD飞致云26 分钟前
操作教程丨在千问办公中使用Cordys CRM Skills技能,落地AI CRM
ai·开源·crm·销售管理·cordys crm·千问办公
能年玲奈喝榴莲牛奶30 分钟前
使用AI编写-资产和漏洞管理系统
人工智能·python·网络安全·安全服务
DeepVisionary1 小时前
再观察小星火:当大厂分成“冰封“,国产轻模式创作者平台如何跑出加速度
python·自动化
gb42152871 小时前
python中unstructured库和langchain-unstructured库在解析pdf文件的时候的区别?
python·langchain·pdf
王莹月1 小时前
nano banana pro 怎么用?生图接口返回的图别直接存链接:nano banana pro / gpt-image-2 出图结果的落库与转存
gpt·ai·chatgpt·ai作画·aigc·agi
vx-程序开发2 小时前
django医院预约挂号系统---附源码23353
java·javascript·spring boot·python·eclipse·django·php
FIT2CLOUD飞致云2 小时前
修复安全漏洞及相关问题,MaxKB开源企业级智能体平台v2.10.5 LTS版本发布
人工智能·ai·开源·智能体·maxkb