From 7975e4e952deaee97d5a50ca2d737a1e049dfeb7 Mon Sep 17 00:00:00 2001 From: ArslanSaleem Date: Tue, 3 Oct 2023 15:21:10 +0500 Subject: [PATCH 1/2] fix: template path issue --- .../assets}/prompt-templates/correct_error_prompt.tmpl | 0 .../assets}/prompt-templates/generate_python_code.tmpl | 0 pandasai/prompts/base.py | 4 ++++ pandasai/prompts/correct_error_prompt.py | 2 +- pandasai/prompts/generate_python_code.py | 2 +- 5 files changed, 6 insertions(+), 2 deletions(-) rename {assets => pandasai/assets}/prompt-templates/correct_error_prompt.tmpl (100%) rename {assets => pandasai/assets}/prompt-templates/generate_python_code.tmpl (100%) diff --git a/assets/prompt-templates/correct_error_prompt.tmpl b/pandasai/assets/prompt-templates/correct_error_prompt.tmpl similarity index 100% rename from assets/prompt-templates/correct_error_prompt.tmpl rename to pandasai/assets/prompt-templates/correct_error_prompt.tmpl diff --git a/assets/prompt-templates/generate_python_code.tmpl b/pandasai/assets/prompt-templates/generate_python_code.tmpl similarity index 100% rename from assets/prompt-templates/generate_python_code.tmpl rename to pandasai/assets/prompt-templates/generate_python_code.tmpl diff --git a/pandasai/prompts/base.py b/pandasai/prompts/base.py index ba44a62f2..0231e9897 100644 --- a/pandasai/prompts/base.py +++ b/pandasai/prompts/base.py @@ -3,6 +3,8 @@ """ from abc import ABC, abstractmethod +from pandasai.helpers.path import find_closest + from ..exceptions import TemplateFileNotFoundError @@ -77,6 +79,8 @@ class FileBasedPrompt(AbstractPrompt): def __init__(self, **kwargs): if (template_path := kwargs.pop("path_to_template", None)) is not None: self._path_to_template = template_path + else: + self._path_to_template = find_closest(self._path_to_template) super().__init__(**kwargs) diff --git a/pandasai/prompts/correct_error_prompt.py b/pandasai/prompts/correct_error_prompt.py index 9b7fe8157..ff727a69c 100644 --- a/pandasai/prompts/correct_error_prompt.py +++ b/pandasai/prompts/correct_error_prompt.py @@ -22,4 +22,4 @@ class CorrectErrorPrompt(FileBasedPrompt): """Prompt to Correct Python code on Error""" - _path_to_template = "assets/prompt-templates/correct_error_prompt.tmpl" + _path_to_template = "pandasai/assets/prompt-templates/correct_error_prompt.tmpl" diff --git a/pandasai/prompts/generate_python_code.py b/pandasai/prompts/generate_python_code.py index d9b103c72..9b5846f77 100644 --- a/pandasai/prompts/generate_python_code.py +++ b/pandasai/prompts/generate_python_code.py @@ -39,7 +39,7 @@ def analyze_data(dfs: list[{engine_df_name}]) -> dict: class GeneratePythonCodePrompt(FileBasedPrompt): """Prompt to generate Python code""" - _path_to_template = "assets/prompt-templates/generate_python_code.tmpl" + _path_to_template = "pandasai/assets/prompt-templates/generate_python_code.tmpl" def __init__(self, **kwargs): default_import = "import pandas as pd" From f67e3bd1af0e1f72d000f033815dedf7d6ae7f6f Mon Sep 17 00:00:00 2001 From: ArslanSaleem Date: Tue, 3 Oct 2023 16:01:34 +0500 Subject: [PATCH 2/2] fix: outside directory example --- pandasai/prompts/base.py | 9 ++++++--- pandasai/prompts/correct_error_prompt.py | 2 +- pandasai/prompts/generate_python_code.py | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pandasai/prompts/base.py b/pandasai/prompts/base.py index 0231e9897..6dcf513bf 100644 --- a/pandasai/prompts/base.py +++ b/pandasai/prompts/base.py @@ -2,8 +2,8 @@ In order to better handle the instructions, this prompt module is written. """ from abc import ABC, abstractmethod - -from pandasai.helpers.path import find_closest +import os +from pathlib import Path from ..exceptions import TemplateFileNotFoundError @@ -80,7 +80,10 @@ def __init__(self, **kwargs): if (template_path := kwargs.pop("path_to_template", None)) is not None: self._path_to_template = template_path else: - self._path_to_template = find_closest(self._path_to_template) + current_dir_path = Path(__file__).parent + self._path_to_template = os.path.join( + current_dir_path, "..", self._path_to_template + ) super().__init__(**kwargs) diff --git a/pandasai/prompts/correct_error_prompt.py b/pandasai/prompts/correct_error_prompt.py index 13c2e5495..4985bedf0 100644 --- a/pandasai/prompts/correct_error_prompt.py +++ b/pandasai/prompts/correct_error_prompt.py @@ -22,4 +22,4 @@ class CorrectErrorPrompt(FileBasedPrompt): """Prompt to Correct Python code on Error""" - _path_to_template = "pandasai/assets/prompt-templates/correct_error_prompt.tmpl" + _path_to_template = "assets/prompt-templates/correct_error_prompt.tmpl" diff --git a/pandasai/prompts/generate_python_code.py b/pandasai/prompts/generate_python_code.py index a89ad6d96..61855a17c 100644 --- a/pandasai/prompts/generate_python_code.py +++ b/pandasai/prompts/generate_python_code.py @@ -39,7 +39,7 @@ def analyze_data(dfs: list[{engine_df_name}]) -> dict: class GeneratePythonCodePrompt(FileBasedPrompt): """Prompt to generate Python code""" - _path_to_template = "pandasai/assets/prompt-templates/generate_python_code.tmpl" + _path_to_template = "assets/prompt-templates/generate_python_code.tmpl" def __init__(self, **kwargs): default_import = "import pandas as pd"