How do I create a custom prompt for create_pandas_dataframe_agent ? #14756
Replies: 4 comments 4 replies
-
🤖 Hey @monkeydust! I'm Dosu, an AI bot here to assist you with your queries and issues related to the LangChain repository. I'm more than happy to help you while we wait for a human maintainer. Let's get started on solving your issue, shall we? To add a custom template to the Here is an example of how you can do this: from langchain_experimental.agents.agent_toolkits.pandas.base import create_pandas_dataframe_agent
from langchain.agents.types import AgentType
from langchain.schema.language_model import BaseLanguageModel
import pandas as pd
# Assuming you have a language model instance
llm = BaseLanguageModel()
# Create a pandas DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
# Define your custom prefix and suffix
custom_prefix = "This is my custom prefix. "
custom_suffix = " This is my custom suffix."
# Create the pandas dataframe agent
agent = create_pandas_dataframe_agent(
llm=llm,
df=df,
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
prefix=custom_prefix,
suffix=custom_suffix,
include_df_in_prompt=True,
number_of_head_rows=5
) In this example, the You can find more details about this in the LangChain codebase at libs/experimental/langchain_experimental/agents/agent_toolkits/pandas/base.py. If you want to create an agent in LangChain that accepts both a "dataframe" and "user_input" as input variables, you can modify the I hope this helps! If you have any other questions, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
-
@dosu-bot |
Beta Was this translation helpful? Give feedback.
-
I'm building an AI assistant where the non-data science user needs to ask a question to a dataset. The way I found it was to first do a It turns out that I would like to create a Note: I tried using the prefix |
Beta Was this translation helpful? Give feedback.
-
Hi all, Just to let you know the used prompts for PREFIX = """Answer the following questions as best you can. You have access to the following tools:"""
FORMAT_INSTRUCTIONS = """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 [{tool_names}]
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"""
SUFFIX = """Begin!
Question: {input}
Thought:{agent_scratchpad}""" As you said, you can only pass custom instructions through the prefix or suffix. Everything is concatenated together so it shouldn't be a problem. The best way to add humain context is to pass it through the suffix as it will be the first instruction. |
Beta Was this translation helpful? Give feedback.
-
I want to add my own template to this create_pandas_dataframe_agent to provide human context on the dataframe it is using.
How can do that?
Txs
Beta Was this translation helpful? Give feedback.
All reactions