Skip to content

Commit

Permalink
docs: fixs docs build
Browse files Browse the repository at this point in the history
  • Loading branch information
gventuri committed Oct 7, 2023
1 parent bc7ebf2 commit 93996fb
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 44 deletions.
3 changes: 2 additions & 1 deletion pandasai/prompts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base import AbstractPrompt, FileBasedPrompt
from .base import AbstractPrompt
from .file_based_prompt import FileBasedPrompt
from .correct_error_prompt import CorrectErrorPrompt
from .generate_python_code import GeneratePythonCodePrompt

Expand Down
38 changes: 0 additions & 38 deletions pandasai/prompts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
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


class AbstractPrompt(ABC):
Expand Down Expand Up @@ -78,37 +74,3 @@ def __str__(self):

def validate(self, output: str) -> bool:
return isinstance(output, str)


class FileBasedPrompt(AbstractPrompt):
"""Base class for prompts supposed to read template content from a file.
`_path_to_template` attribute has to be specified.
"""

_path_to_template: str

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
)

super().__init__(**kwargs)

@property
def template(self) -> str:
try:
with open(self._path_to_template) as fp:
return fp.read()
except FileNotFoundError:
raise TemplateFileNotFoundError(
self._path_to_template, self.__class__.__name__
)
except IOError as exc:
raise RuntimeError(
f"Failed to read template file '{self._path_to_template}': {exc}"
)
2 changes: 1 addition & 1 deletion pandasai/prompts/clarification_questions_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import json
from typing import List
import pandas as pd
from .base import FileBasedPrompt
from .file_based_prompt import FileBasedPrompt


class ClarificationQuestionPrompt(FileBasedPrompt):
Expand Down
2 changes: 1 addition & 1 deletion pandasai/prompts/correct_error_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Correct the python code and return a new python code that fixes the above mentioned error. Do not generate the same code again.
""" # noqa: E501

from .base import FileBasedPrompt
from .file_based_prompt import FileBasedPrompt


class CorrectErrorPrompt(FileBasedPrompt):
Expand Down
2 changes: 1 addition & 1 deletion pandasai/prompts/explain_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
mentioning technical details or mentioning the libraries used?
"""
from .base import FileBasedPrompt
from .file_based_prompt import FileBasedPrompt


class ExplainPrompt(FileBasedPrompt):
Expand Down
39 changes: 39 additions & 0 deletions pandasai/prompts/file_based_prompt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import os
from pathlib import Path

from ..exceptions import TemplateFileNotFoundError
from .base import AbstractPrompt


class FileBasedPrompt(AbstractPrompt):
"""Base class for prompts supposed to read template content from a file.
`_path_to_template` attribute has to be specified.
"""

_path_to_template: str

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
)

super().__init__(**kwargs)

@property
def template(self) -> str:
try:
with open(self._path_to_template) as fp:
return fp.read()
except FileNotFoundError:
raise TemplateFileNotFoundError(
self._path_to_template, self.__class__.__name__
)
except IOError as exc:
raise RuntimeError(
f"Failed to read template file '{self._path_to_template}': {exc}"
)
2 changes: 1 addition & 1 deletion pandasai/prompts/generate_python_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def analyze_data(dfs: list[{engine_df_name}]) -> dict:
""" # noqa: E501


from .base import FileBasedPrompt
from .file_based_prompt import FileBasedPrompt


class GeneratePythonCodePrompt(FileBasedPrompt):
Expand Down
2 changes: 1 addition & 1 deletion pandasai/prompts/rephase_query_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from typing import List

import pandas as pd
from .base import FileBasedPrompt
from .file_based_prompt import FileBasedPrompt


class RephraseQueryPrompt(FileBasedPrompt):
Expand Down

0 comments on commit 93996fb

Please sign in to comment.