Repository: gventuri/pandas-ai
File: pandasai/agent/__init__.py (Python)

Code before:
        )

    def chat(self, query: str, output_type: Optional[str] = None):
        """
        Simulate a chat interaction with the assistant on Dataframe.
        """
        try:
            self._memory.add(query, True)
            conversation = self._get_conversation()
            result = self._lake.chat(
                query, output_type=output_type, start_conversation=conversation
            )
            self._memory.add(result, False)
            return result
        except Exception as exception:
            return (
                "Unfortunately, I was not able to get your answers, "
                "because of the following error:\n"
                f"\n{exception}\n"
            )

    def _get_clarification_prompt(self) -> Prompt:
        """
        Create a clarification prompt with relevant variables.
        """
        prompt = ClarificationQuestionPrompt()
        prompt.set_var("dfs", self._lake.dfs)
        prompt.set_var("conversation", self._get_conversation())
        return prompt

    def clarification_questions(self) -> ClarificationResponse:
        """
        Generate clarification questions based on the data
        """
        try:
            prompt = self._get_clarification_prompt()
            result = self._lake.llm.call(prompt)
            self.logger.log(
                f"""Clarification Questions:  {result}
                """
            )
            questions: list[str] = json.loads(result)
            return ClarificationResponse(
                success=True, questions=questions[:3], message=result
            )
        except Exception as exception:
            return ClarificationResponse(
                False,
                [],
                "Unfortunately, I was not able to get your clarification questions, "
                "because of the following error:\n"

Review comment (suggestion):
Let's pass these as arguments instead (both dfs and conversation). Since we'll pass these as arguments, we won't need the `_get_clarification_prompt` method anymore

Code after:
        """
        Generate clarification questions based on the data
        """
        prompt = ClarificationQuestionPrompt(
            self._lake.dfs, self._lake._memory.get_conversation()
        )

        result = self._lake.llm.call(prompt)
        self._logger.log(
            f"""Clarification Questions:  {result}
            """
        )
        questions: list[str] = json.loads(result)
        return questions[:3]

    def start_new_conversation(self):
        """
        Clears the previous conversation
        """
        self._lake._memory.clear()

    def explain(self) -> str:
        """
        Returns the explanation of the code how it reached to the solution
        """
        try:
            prompt = ExplainPrompt(
                self._lake._memory.get_conversation(),
                self._lake.last_code_executed,
            )
            response = self._lake.llm.call(prompt)
            self._logger.log(
                f"""Explaination:  {response}
                """
            )
            return response
        except Exception as exception:
            return (
                "Unfortunately, I was not able to explain, "
                "because of the following error:\n"
                f"\n{exception}\n"
            )