diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 6e4ac7e98..961832a5f 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -30,8 +30,9 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install --upgrade setuptools - pip install --upgrade build + pip install --upgrade setuptools setuptools_scm[toml] build + - name: get setuptools-scm version + run: python -m setuptools_scm - name: Build package run: python -m build - name: Publish package diff --git a/ragas/exceptions.py b/ragas/exceptions.py new file mode 100644 index 000000000..3c631c3ec --- /dev/null +++ b/ragas/exceptions.py @@ -0,0 +1,11 @@ +from __future__ import annotations + + +class RagasException(Exception): + """ + Base exception class for ragas. + """ + + def __init__(self, message: str): + self.message = message + super().__init__(message) diff --git a/ragas/metrics/factual.py b/ragas/metrics/factual.py index eb944b523..82cbfb79e 100644 --- a/ragas/metrics/factual.py +++ b/ragas/metrics/factual.py @@ -16,6 +16,7 @@ PreTrainedModel, ) +from ragas.exceptions import RagasException from ragas.metrics import Metric from ragas.utils import device_check @@ -209,12 +210,16 @@ class Qsquare(Metric): include_nouns: bool = True save_results: bool = False - def __post_init__( - self, - ): - self.nlp = spacy.load(SPACY_MODEL) + def __post_init__(self): self.qa = QAGQ.from_pretrained(self.qa_model_name) self.qg = QAGQ.from_pretrained(self.qg_model_name) + try: + self.nlp = spacy.load(SPACY_MODEL) + except OSError: + raise RagasException( + f"Spacy model [{SPACY_MODEL}] not found. Please run " + "`python -m spacy download {SPACY_MODEL}` to install it." + ) @property def name(self):