Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the template and adding customzation in pandas_dataframe_agent/csv agent #1

Open
m-ali-awan opened this issue Jun 14, 2023 · 1 comment

Comments

@m-ali-awan
Copy link

Hi ,
Thanks for veery helping notebooks

Hope all of you are doing great.

I am developing a chatbot/question-answer agent using GPT-4 on pandas dataframe in langchain. I am able to make it work with following code:

gpt4_agent = create_pandas_dataframe_agent(
    ChatOpenAI(temperature=0,
               openai_api_key=OPENAI_API_KEY,
               model_name = 'gpt-4'),[sub_listing_df,company_df], verbose=True
)

But, I think that I can make it more optimized by changing some paramters, and especially prompt template: Here is the prompt template being used by default:

display(Markdown(gpt4_agent.agent.llm_chain.prompt.template))
----------------------
You are working with {num_dfs} pandas dataframes in Python named df1, df2, etc. You should use the tools below to answer the question posed of you:

python_repl_ast: A Python shell. Use this to execute python commands. Input should be a valid python command. When using this tool, sometimes output is abbreviated - make sure it does not look abbreviated before using it in your answer.

Use the following format:

Question: the input question you must answer Thought: you should always think about what to do Action: the action to take, should be one of [python_repl_ast] Action Input: the input to the action Observation: the result of the action ... (this Thought/Action/Action Input/Observation can repeat N times) Thought: I now know the final answer Final Answer: the final answer to the original input question

This is the result of print(df.head()) for each dataframe: {dfs_head}

Begin! Question: {input} {agent_scratchpad}

How can I change the prompt template?

Thanks for any help

@m-ali-awan
Copy link
Author

I have tried following:

template = """We are scraping data from a Vehicle Damage Estimating Software. First input is Vehicle Make Model Year, Type, and respective Part and Operation.
            Then we have to choose from possible options to reach that specific part. I will provide you with received Options, you have to tell me which to choose, 
            So we can reach to respective part info
Just output single option, and not folllowing sequence.

Begin! Question: {input} {agent_scratchpad}"""

gpt4_agent = create_pandas_dataframe_agent(
    ChatOpenAI(temperature=0,
               openai_api_key=OPENAI_API_KEY,
               model_name = 'gpt-4'),
    [sub_listing_df,company_df], verbose=True,
    chain_type_kwargs={
        'prompt': PromptTemplate(template=template,input_variables=['input','agent_scratchpad'])
    }
    )

But it is not changing the agent prompt template

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant