Skip to content

Commit

Permalink
improved error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Mohsin Shah <[email protected]>
  • Loading branch information
mohsinposts committed Jan 29, 2024
1 parent 2ecd91d commit 854f2f9
Showing 1 changed file with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@
try:
from interpret_text.generative.lime_tools.explainers import \
LocalExplanationSentenceEmbedder
except ImportError as e:
print("Could not import LocalExplanationSentenceEmbedder: ", e)
interpret_text_explainers_installed = True
except ImportError:
interpret_text_explainers_installed = False

try:
from interpret_text.generative.model_lib.openai_tooling import ChatOpenAI
except ImportError as e:
print("Could not import ChatOpenAI: ", e)
interpret_text_openai_tooling_installed = True
except ImportError:
interpret_text_openai_tooling_installed = False

try:
from sentence_transformers import SentenceTransformer
except ImportError as e:
print("Could not import SentenceTransformer: ", e)
sentence_transformers_installed = True
except ImportError:
sentence_transformers_installed = False


CONTEXT = QuestionAnsweringFields.CONTEXT
Expand Down Expand Up @@ -152,6 +155,27 @@ def compute(self):
self._explanation = [explainer_start(eval_examples),
explainer_end(eval_examples)]
elif self._task_type == ModelTask.GENERATIVE_TEXT:
if not interpret_text_explainers_installed:
error = (
"The required module"
"'interpret_text.generative.lime_tools.explainers' "
"is not installed."
)
raise RuntimeError(error)
if not interpret_text_openai_tooling_installed:
error = (
"The required module"
"'interpret_text.generative.model_lib.openai_tooling' "
"is not installed."
)
raise RuntimeError(error)
if not sentence_transformers_installed:
error = (
"The required package"
"'sentence_transformers' "
"is not installed."
)
raise RuntimeError(error)
context = self._evaluation_examples[CONTEXT]
questions = self._evaluation_examples[QUESTIONS]
eval_examples = []
Expand Down

0 comments on commit 854f2f9

Please sign in to comment.