From 5f039169e408dcaa0721d6a873f582c5e1ea295e Mon Sep 17 00:00:00 2001 From: Gabriele Venturi Date: Wed, 13 Dec 2023 23:53:01 +0100 Subject: [PATCH] fix: clarification questions now work with vertex ai --- pandasai/agent/__init__.py | 1 + .../clarification_questions_prompt.tmpl | 14 ++++++-------- pandasai/prompts/clarification_questions_prompt.py | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pandasai/agent/__init__.py b/pandasai/agent/__init__.py index 71924ed87..7fb6e538e 100644 --- a/pandasai/agent/__init__.py +++ b/pandasai/agent/__init__.py @@ -139,6 +139,7 @@ def clarification_questions(self, query: str) -> List[str]: f"""Clarification Questions: {result} """ ) + result = result.replace("```json", "").replace("```", "") questions: list[str] = json.loads(result) return questions[:3] diff --git a/pandasai/assets/prompt_templates/clarification_questions_prompt.tmpl b/pandasai/assets/prompt_templates/clarification_questions_prompt.tmpl index 240023d0f..268b5a7d2 100644 --- a/pandasai/assets/prompt_templates/clarification_questions_prompt.tmpl +++ b/pandasai/assets/prompt_templates/clarification_questions_prompt.tmpl @@ -1,4 +1,3 @@ - You are provided with the following pandas DataFrames: {dataframes} @@ -7,14 +6,13 @@ You are provided with the following pandas DataFrames: {conversation} -Based on the conversation, are there any clarification questions that a senior data scientist would ask about the query "{query}"? - -It is extremely important that you follow the following guidelines when generating clarification questions: -- Ask questions a non technical person could answer. Do not include technical terms, do not ask for questions that require knowledge about how the dataframes are structured or about a specific column. +Find the clarification questions that could be asked to a senior data scientist would ask about the query "{query}"? - Only ask for questions related to the query if the query is not clear or ambiguous and that cannot be deduced from the context. -- Return a maximum of 3 questions. The lower the number of questions, the better. -- If no meaningful clarification questions can be asked, return an empty array. +- Return up to 3 questions. + +Example: +['Question 1', 'Question 2'] -Return the JSON array of the clarification questions. +Return a JSON list of the clarification questions strings. Json: \ No newline at end of file diff --git a/pandasai/prompts/clarification_questions_prompt.py b/pandasai/prompts/clarification_questions_prompt.py index 19b43b02d..cf957a4e9 100644 --- a/pandasai/prompts/clarification_questions_prompt.py +++ b/pandasai/prompts/clarification_questions_prompt.py @@ -35,6 +35,7 @@ def setup( def validate(self, output) -> bool: try: + output = output.replace("```json", "").replace("```", "") json_data = json.loads(output) return isinstance(json_data, List) except json.JSONDecodeError: