Spaces:
Sleeping
Sleeping
kiransathyatiger
commited on
Commit
•
947ca10
1
Parent(s):
2db9519
Upload utils.py
Browse files
utils.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##from langchain.agents import create_pandas_dataframe_agent #This import has been recently replaced by the below
|
2 |
+
from langchain_experimental.agents import create_pandas_dataframe_agent
|
3 |
+
import pandas as pd
|
4 |
+
#from langchain.llms import OpenAI
|
5 |
+
#New import from langchain, which replaces the above
|
6 |
+
from langchain_openai import OpenAI
|
7 |
+
|
8 |
+
def query_agent(data, query):
|
9 |
+
|
10 |
+
# Parse the CSV file and create a Pandas DataFrame from its contents.
|
11 |
+
df = pd.read_csv(data)
|
12 |
+
|
13 |
+
llm = OpenAI()
|
14 |
+
|
15 |
+
# Create a Pandas DataFrame agent.
|
16 |
+
agent = create_pandas_dataframe_agent(llm, df, verbose=True)
|
17 |
+
|
18 |
+
#Python REPL: A Python shell used to evaluating and executing Python commands.
|
19 |
+
#It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain
|
20 |
+
return agent.invoke(query)
|