Replies: 1 comment
-
🤖 Hello, Based on your request, it seems you want to create a conversational chatbot that can analyze and discuss CSV data, and also has the ability to remember and reference previous conversations. To achieve this, you can modify the class MemoryAgentExecutor(AgentExecutor):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.memory = []
def execute(self, text: str) -> str:
response = super().execute(text)
self.memory.append((text, response))
return response
def recall(self, text: str) -> Optional[str]:
for question, answer in reversed(self.memory):
if text in question:
return answer
return None
def create_csv_agent(
llm: BaseLanguageModel,
path: Union[str, IOBase, List[Union[str, IOBase]]],
pandas_kwargs: Optional[dict] = None,
**kwargs: Any,
) -> MemoryAgentExecutor:
"""Create csv agent by loading to a dataframe and using pandas agent."""
try:
import pandas as pd
except ImportError:
raise ImportError(
"pandas package not found, please install with `pip install pandas`"
)
_kwargs = pandas_kwargs or {}
if isinstance(path, (str, IOBase)):
df = pd.read_csv(path, **_kwargs)
elif isinstance(path, list):
df = []
for item in path:
if not isinstance(item, (str, IOBase)):
raise ValueError(f"Expected str or file-like object, got {type(path)}")
df.append(pd.read_csv(item, **_kwargs))
else:
raise ValueError(f"Expected str, list, or file-like object, got {type(path)}")
return MemoryAgentExecutor(llm, df, **kwargs) In this modification, a new class This modification should allow your chatbot to remember and reference previous conversations. 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.
Uh oh!
There was an error while loading. Please reload this page.
-
@dosu-bot
i want to create a conversational chatbot that is aware of the exisiting chat and it can anlayze and talk with me about the csv i have tried to use the create_csv_agent() function but the problem is that agent cannot be conversation and it doesn't have a memory where i can ask any question its' answer is in the chat it doesn't remember or doesn't store the conversation and take it as an input or something, could someone please provide me how could i achieve this chatbot
Beta Was this translation helpful? Give feedback.
All reactions