Cant Run csv_agent with a Conversation Chain

i am working on a chatbot that needs to analyze CSV files. Normally, I use Langchain and create a csv_agent like this

agent= create_csv_agent(
    ChatOpenAI(temperature=0, model='gpt-4'),
    'csv_pat.csv',
    verbose=True,
    )


agent.run("chat sentence about csv, e.g whats the best performing month, can you predict future sales based on data.")

However, I want to make the chatbot more advanced by enabling it to remember previous conversations. To achieve this, I tried using ConversationChain with the same agent setup, but it fails.

Here’s what I tried:

chain_agent = create_csv_agent(
    ChatOpenAI(temperature=0, model='gpt-4'),
    'file_path.csv',
    verbose=True,
    )


context_template = """The conversation is between person and Analyst chatbot. 
Current conversation:
{history}
Human: {input}
bot:"""


PROMPT = PromptTemplate(
    input_variables= ["history", "input"], template=context_template
)

conversation = ConversationChain(
    prompt=PROMPT,
    llm=chain_agent,
    verbose=True,
    memory=ConversationBufferMemory(ai_prefix="Analyst Bot")
)

TypeError: call() got an unexpected keyword argument ‘stop’

when I swap out chain_agent with ChatOpenAI below like this:

chain_agent = ChatOpenAI(temperature= 0, model_name= 'gpt-4')

The error goes away, but then the bot can’t analyze CSV files and suggests using a data analysis tool.

and the answer comes as following;

However, as a text-based bot, I’m unable to perform these operations directly. You can use a data analysis tool or programming language like Python or R to do this.

Any solutions you might know?

1 Like