File size: 776 Bytes
f9a586a
 
 
 
 
 
 
 
 
 
 
 
 
c1bfd08
5467bd1
f9a586a
 
c8d18cb
f9a586a
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from langchain.agents import create_pandas_dataframe_agent
#from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
import pandas as pd
from langchain.llms import OpenAI



def query_agent(data, query):

    # Parse the CSV file and create a Pandas DataFrame from its contents.
    df = pd.read_csv(data)
    
    llm = OpenAI()
    # Set the model to use
    model = "gpt-4-32k" 
    
    # Create a Pandas DataFrame agent.
    agent = create_pandas_dataframe_agent(llm, df, model= model, verbose=True)

    #Python REPL: A Python shell used to evaluating and executing Python commands. 
    #It takes python code as input and outputs the result. The input python code can be generated from another tool in the LangChain
    return agent.run(query)