-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(prompt): template path issue #607
Conversation
WalkthroughThis update enhances the flexibility of template path handling in the Changes
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (3)
- pandasai/prompts/base.py (2 hunks)
- pandasai/prompts/correct_error_prompt.py (1 hunks)
- pandasai/prompts/generate_python_code.py (1 hunks)
Files skipped from review due to trivial changes (1)
- pandasai/prompts/generate_python_code.py
Additional comments (Suppressed): 2
pandasai/prompts/correct_error_prompt.py (1)
- 22-25: The change in the path of the template file seems to be correct, assuming that the
pandasai
directory is the root directory for your project. However, please verify if this new path is accurate and the template file exists at this location.- _path_to_template = "assets/prompt-templates/correct_error_prompt.tmpl" + _path_to_template = "pandasai/assets/prompt-templates/correct_error_prompt.tmpl"pandasai/prompts/base.py (1)
- 3-10: The import statement for
find_closest
from thepandasai.helpers.path
module has been added. This function is used to find the closest match for a given path, which can be useful when dealing with file paths in a flexible manner.
pandasai/prompts/base.py
Outdated
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) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor of the FileBasedPrompt
class has been updated. If no path_to_template
argument is provided, the find_closest
function is now used to determine the closest template path. This change enhances the flexibility of the class by allowing it to handle cases where the exact template path may not be known or provided.
However, there's a potential issue here. The find_closest
function is called on self._path_to_template
before it's initialized which could lead to an AttributeError. You should initialize self._path_to_template
before calling find_closest
.
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 = "default/path"
self._path_to_template = find_closest(self._path_to_template)
super().__init__(**kwargs)
Codecov Report
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. @@ Coverage Diff @@
## main #607 +/- ##
==========================================
+ Coverage 83.48% 83.50% +0.01%
==========================================
Files 55 55
Lines 2689 2691 +2
==========================================
+ Hits 2245 2247 +2
Misses 444 444
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Files selected for processing (1)
- pandasai/prompts/base.py (2 hunks)
Additional comments (Suppressed): 1
pandasai/prompts/base.py (1)
- 2-9: The
os
andpathlib
modules have been imported for path manipulation. This is likely in preparation for the changes to how the template path is handled.
def __init__(self, **kwargs): | ||
if (template_path := kwargs.pop("path_to_template", None)) is not None: | ||
self._path_to_template = template_path | ||
else: | ||
current_dir_path = Path(__file__).parent | ||
self._path_to_template = os.path.join( | ||
current_dir_path, "..", self._path_to_template | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor of the FileBasedPrompt
class has been updated to handle cases where the path_to_template
argument is not provided. In such cases, it sets _path_to_template
to a path relative to the current file's directory. This change improves the flexibility of the class by allowing it to locate the template file even when an absolute path is not provided.
- if (template_path := kwargs.pop("path_to_template", None)) is not None:
- self._path_to_template = template_path
+ if (template_path := kwargs.pop("path_to_template", None)) is not None:
+ self._path_to_template = template_path
+ else:
+ current_dir_path = Path(__file__).parent
+ self._path_to_template = os.path.join(
+ current_dir_path, "..", self._path_to_template
+ )
Summary by CodeRabbit
Release Notes
FileBasedPrompt
class inpandasai/prompts/base.py
to automatically find the closest template path if not provided. This improves usability by reducing the need for manual path specification.pandasai/prompts/correct_error_prompt.py
andpandasai/prompts/generate_python_code.py
. The new paths reflect the updated location of the template files, ensuring that the prompts can access the necessary templates correctly.