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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pandasai/prompts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
In order to better handle the instructions, this prompt module is written.
"""
from abc import ABC, abstractmethod
import os
from pathlib import Path

from ..exceptions import TemplateFileNotFoundError

Expand Down Expand Up @@ -77,6 +79,11 @@ 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:
current_dir_path = Path(__file__).parent
self._path_to_template = os.path.join(
current_dir_path, "..", self._path_to_template
)
Comment on lines 79 to +86
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
+             )


super().__init__(**kwargs)

Expand Down