Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import csv
|
| 3 |
import io
|
| 4 |
-
# Changed LLM import to HuggingFaceEndpoint
|
| 5 |
from langchain_community.llms import HuggingFaceEndpoint
|
| 6 |
-
from langchain_community
|
|
|
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
import os
|
| 9 |
|
|
@@ -59,10 +59,13 @@ def query_agent(uploaded_file_content: bytes, query: str, hf_api_token: str) ->
|
|
| 59 |
)
|
| 60 |
|
| 61 |
# 3. Create the Pandas DataFrame Agent
|
|
|
|
|
|
|
| 62 |
agent = create_pandas_dataframe_agent(
|
| 63 |
llm,
|
| 64 |
df,
|
| 65 |
verbose=True,
|
|
|
|
| 66 |
# Include a system prompt to guide the agent's behavior
|
| 67 |
agent_kwargs={
|
| 68 |
"system_message": (
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import csv
|
| 3 |
import io
|
|
|
|
| 4 |
from langchain_community.llms import HuggingFaceEndpoint
|
| 5 |
+
# FIX: Changed import path from langchain_community to langchain_experimental
|
| 6 |
+
from langchain_experimental.agents import create_pandas_dataframe_agent
|
| 7 |
from dotenv import load_dotenv
|
| 8 |
import os
|
| 9 |
|
|
|
|
| 59 |
)
|
| 60 |
|
| 61 |
# 3. Create the Pandas DataFrame Agent
|
| 62 |
+
# CRITICAL SECURITY NOTE: Must set allow_dangerous_code=True
|
| 63 |
+
# as LangChain now requires an explicit opt-in for code execution agents.
|
| 64 |
agent = create_pandas_dataframe_agent(
|
| 65 |
llm,
|
| 66 |
df,
|
| 67 |
verbose=True,
|
| 68 |
+
allow_dangerous_code=True, # Added to prevent runtime ValueError
|
| 69 |
# Include a system prompt to guide the agent's behavior
|
| 70 |
agent_kwargs={
|
| 71 |
"system_message": (
|