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: added a spacy check before installation #22

Merged
merged 4 commits into from
May 14, 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
5 changes: 3 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions ragas/exceptions.py
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 9 additions & 4 deletions ragas/metrics/factual.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
PreTrainedModel,
)

from ragas.exceptions import RagasException
from ragas.metrics import Metric
from ragas.utils import device_check

Expand Down Expand Up @@ -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):
Expand Down