Skip to content
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

Merged
merged 3 commits into from
Oct 3, 2023
Merged

fix(prompt): template path issue #607

merged 3 commits into from
Oct 3, 2023

Conversation

ArslanSaleem
Copy link
Collaborator

@ArslanSaleem ArslanSaleem commented Oct 3, 2023

Summary by CodeRabbit

Release Notes

  • New Feature: Enhanced the FileBasedPrompt class in pandasai/prompts/base.py to automatically find the closest template path if not provided. This improves usability by reducing the need for manual path specification.
  • Refactor: Updated the paths to template files in pandasai/prompts/correct_error_prompt.py and pandasai/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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 3, 2023

Walkthrough

This update enhances the flexibility of template path handling in the pandasai library. It introduces a mechanism to find the closest template if no specific path is provided, and updates the paths for templates in CorrectErrorPrompt and GeneratePythonCodePrompt classes.

Changes

File Path Summary
pandasai/prompts/base.py Introduced find_closest function for dynamic template path finding. If no template_path is provided, the closest template path is used. Added imports for os and pathlib modules.
pandasai/prompts/correct_error_prompt.py
pandasai/prompts/generate_python_code.py
Updated the paths to template files in CorrectErrorPrompt and GeneratePythonCodePrompt classes.

🐇💻

In the land of code where the shadows lie,

Paths were updated, no more sigh.

Templates found with ease and grace,

In every corner, in every space.

Celebrate now, for the changes are neat,

With CodeRabbit's touch, they're now complete! 🎉


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

@ArslanSaleem ArslanSaleem requested a review from gventuri October 3, 2023 10:25
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between d511037 and a38d26c.
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 the pandasai.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.

Comment on lines 79 to 86
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)

Copy link
Contributor

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-commenter
Copy link

Codecov Report

Merging #607 (a38d26c) into main (d511037) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ 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              
Files Coverage Δ
pandasai/prompts/base.py 81.63% <100.00%> (+0.78%) ⬆️
pandasai/prompts/correct_error_prompt.py 100.00% <100.00%> (ø)
pandasai/prompts/generate_python_code.py 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between a38d26c and f67e3bd.
Files selected for processing (1)
  • pandasai/prompts/base.py (2 hunks)
Additional comments (Suppressed): 1
pandasai/prompts/base.py (1)
  • 2-9: The os and pathlib modules have been imported for path manipulation. This is likely in preparation for the changes to how the template path is handled.

Comment on lines 79 to +86
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
)
Copy link
Contributor

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
+             )

@gventuri gventuri merged commit 42b8256 into main Oct 3, 2023
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants