-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Erros with langchain CSV agent and Pandas agent #17448
Comments
🤖 Hey @Khawlao, great to see you diving into the depths of LangChain again! Running into a bit of a snag, I see? Let's unravel this thread together. 🧵 Based on the context provided, it seems like the issue you're encountering is related to the agent type you're using. The valid agent type that can be used with the Here is an example of how to create an instance of from langchain_openai import OpenAIFunctionsAgent, ChatOpenAI
agent = OpenAIFunctionsAgent(
llm=ChatOpenAI(temperature=0, model="gpt-4"), prompt=prompt, tools=tools
) You can find this in the templates/csv-agent/csv_agent/agent.py file in the LangChain repository. Regarding the If you're still encountering issues, could you please provide more details about the context in which you're calling Sources
|
@dosubot the openAI functions agent doesnt work : ImportError: cannot import name 'OpenAIFunctionsAgent' from 'langchain_openai'. I am not calling completions.create() in my code. |
🤖 Based on the error messages you provided, it seems like there might be a mismatch between the The Here's the relevant part of the def create_react_agent(
llm: BaseLanguageModel,
tools: Sequence[BaseTool],
prompt: Optional[str] = None,
agent_type: Optional[AgentType] = None,
**kwargs: Any,
) -> ReactAgent:
...
missing_vars = set()
if "tools" not in kwargs:
missing_vars.add("tools")
if "tool_names" not in kwargs:
missing_vars.add("tool_names")
if missing_vars:
raise ValueError(f"Prompt missing required variables: {missing_vars}")
... As for the Regarding the If you're still encountering these issues, could you please provide more information about how you're setting up and using the Sources
|
@dosubot I am using the create_csv_agent : agent = create_csv_agent( |
🤖 Based on the error messages you're encountering, it seems like there might be a mismatch between the agent type you're trying to use and the language model or the prompt you're using. The error The error Here's an example of how to create a compatible prompt: from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
prompt = ChatPromptTemplate.from_messages(
[
("system", "You are a helpful assistant"),
MessagesPlaceholder("chat_history", optional=True),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
]
) In this example, the As for the Finally, it calls the Please ensure that the language model you're using is compatible with the Sources
|
@dosubot I resolved the issue, it's in the base code of the create_csv_agent, agent.py, I had to remove the tools as the input for create_react_agent function. |
🤖 I'm glad to hear that you were able to resolve the issue with the The error The error It's always a good idea to ensure that you're using the latest version of LangChain. You can update LangChain by running Regarding the If you continue to encounter issues, I recommend checking the LangChain GitHub repository for any recent changes that might affect your code. You can also check the LangChain documentation for any updates or changes to the API. I hope this helps! If you have any other questions or need further clarification, please don't hesitate to ask. Sources
|
Checked other resources
Example Code
from langchain.agents.agent_types import AgentType
from langchain_experimental.agents.agent_toolkits.csv.base import create_csv_agent
from langchain_openai import OpenAI
from langchain_community.embeddings import HuggingFaceInferenceAPIEmbeddings
from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe_agent
agent = create_csv_agent(
llm ,
'train.csv',
agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
)
agent.run("how many rows are there?")¨
f=pd.read_csv('train.csv',delimiter=';',encoding='Latin-1')
print(df.head())
agent = create_pandas_dataframe_agent(llm, df, agent_type="openai-tools", verbose=True)
agent.invoke(
{
"input": "What's the correlation between age and fare? is that greater than the correlation between fare and survival?"
}
)
**## Output ##
return func(*args, kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'tools'
and when changing the LLM or agent type i get this error: in create_react_agent
raise ValueError(f"Prompt missing required variables: {missing_vars}")
ValueError: Prompt missing required variables: {'tools', 'tool_names'}
Error Message and Stack Trace (if applicable)
line 26, in
agent = create_csv_agent(llm ,'train.csv',agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\LocalCache\local-packages\Python311\site-packages\langchain_experimental\agents\agent_toolkits\csv\base.py", line 66, in create_csv_agent
return create_pandas_dataframe_agent(llm, df, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain_experimental\agents\agent_toolkits\pandas\base.py", line 264, in create_pandas_dataframe_agent
runnable=create_react_agent(llm, tools, prompt), # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\langchain\agents\react\agent.py", line 97, in create_react_agent
raise ValueError(f"Prompt missing required variables: {missing_vars}")
ValueError: Prompt missing required variables: {'tool_names', 'tools'}
Description
I am trying to use the CSV agent to query my CSV but I keep getting the error: TypeError: Completions.create() got an unexpected keyword argument 'tools' ( for agent type = openai tools) and I tried a different agent type and I am having this error ValueError: Prompt missing required variables: {'tools', 'tool_names'}
(i followed the example from the documentation)
if anyone has an idea how to fix this or encountered this issue before please reach out!
System Info
OS: Windows
OS Version: 10.0.19045
Python Version: 3.11.8 (tags/v3.11.8:db85d51, Feb 6 2024, 22:03:32) [MSC v.1937 64 bit (AMD64)]
The text was updated successfully, but these errors were encountered: