Langchain custom tool - passing DataFrame as function parameter #15041
Replies: 2 comments 2 replies
-
🤖 Hey @soumalya2007! Nice to see you around again. Looks like you're diving deep into LangChain, that's awesome! In LangChain, you can pass a DataFrame as a parameter to a user-defined function within a custom tool by using the Here is an example of how you can do this: from langchain.tools import BaseTool
from langchain_experimental.tools.python.tool import PythonAstREPLTool
import pandas as pd
# Define your DataFrame
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
# Define your custom tool with the DataFrame as a local variable
custom_tool = PythonAstREPLTool(locals={"df": df})
# Now, you can use 'df' within your custom tool In the provided context, you can see this being done in the tools = [PythonAstREPLTool(locals={"df": df})] + list(extra_tools) In this line, You can find more details about the 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.
-
hey @soumalya2007, I am working on similar problem. Did you find the solution? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have an user defined function where DataFrame is being passed as parameters. If I need to call this in a custom tool , what will be the way?
Can you cite an example?
Beta Was this translation helpful? Give feedback.
All reactions