Spaces:
Runtime error
Runtime error
Commit
·
973427b
1
Parent(s):
d2b7755
Create utlis.py
Browse files
utlis.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from langchain.agents import create_pandas_dataframe_agent
|
| 2 |
+
#from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from langchain.llms import OpenAI
|
| 5 |
+
|
| 6 |
+
|
| 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 |
+
# Set the model to use
|
| 15 |
+
#model = "gpt4"
|
| 16 |
+
|
| 17 |
+
# Create a Pandas DataFrame agent.
|
| 18 |
+
agent = create_pandas_dataframe_agent(llm, df, verbose=True)
|
| 19 |
+
|
| 20 |
+
#Python REPL: A Python shell used to evaluating and executing Python commands.
|
| 21 |
+
#It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain
|
| 22 |
+
return agent.run(query)
|