Skip to content

Commit b79406a

Browse files
committed
fix: lint and format issues
1 parent 0984999 commit b79406a

5 files changed

Lines changed: 17 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ preview = false
117117

118118
[tool.pyright]
119119
include = ["src/ragas"]
120-
excludeTypeshedPaths = ["@types/*"]
120+
exclude = ["@types/*"]
121121
pythonVersion = "3.9"
122122
pythonPlatform = "All"
123123
typeCheckingMode = "basic"

src/ragas/config.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,3 @@ class InstructionConfig(BaseModel):
3434
optimizer_config: t.Dict[str, t.Any] = Field(
3535
default_factory=lambda: DEFAULT_OPTIMIZER_CONFIG
3636
)
37-
38-
39-
InstructionConfig.model_rebuild()

src/ragas/evaluation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def main():
169169

170170
client = OpenAI()
171171
llm = llm_factory("gpt-4o-mini", client=client)
172-
metric.llm = llm
172+
metric.llm = t.cast(t.Optional[BaseRagasLLM], llm)
173173
llm_changed.append(i)
174174
if isinstance(metric, MetricWithEmbeddings) and metric.embeddings is None:
175175
if embeddings is None:

src/ragas/metrics/_nv_metrics.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from langchain_core.prompt_values import StringPromptValue
1010

1111
from ragas.dataset_schema import SingleTurnSample
12+
from ragas.llms.base import BaseRagasLLM
1213
from ragas.metrics.base import MetricType, MetricWithLLM, SingleTurnMetric
1314

1415
logger = logging.getLogger(__name__)
@@ -115,7 +116,7 @@ async def _single_turn_ascore(
115116
sentence_true=sample.reference,
116117
)
117118
)
118-
req0 = self.llm.agenerate_text(
119+
req0 = t.cast(BaseRagasLLM, self.llm).agenerate_text(
119120
formatted_prompt,
120121
n=1,
121122
temperature=0.10,
@@ -138,7 +139,7 @@ async def _single_turn_ascore(
138139
sentence_true=sample.response,
139140
)
140141
)
141-
req1 = self.llm.agenerate_text(
142+
req1 = t.cast(BaseRagasLLM, self.llm).agenerate_text(
142143
formatted_prompt,
143144
n=1,
144145
temperature=0.10,
@@ -255,7 +256,7 @@ async def _single_turn_ascore(
255256
context="\n".join(sample.retrieved_contexts),
256257
)
257258
)
258-
req = self.llm.agenerate_text(
259+
req = t.cast(BaseRagasLLM, self.llm).agenerate_text(
259260
formatted_prompt,
260261
n=1,
261262
temperature=0.1,
@@ -274,7 +275,7 @@ async def _single_turn_ascore(
274275
context="\n".join(sample.retrieved_contexts),
275276
)
276277
)
277-
req = self.llm.agenerate_text(
278+
req = t.cast(BaseRagasLLM, self.llm).agenerate_text(
278279
formatted_prompt,
279280
n=1,
280281
temperature=0.1,
@@ -389,7 +390,7 @@ async def _single_turn_ascore(
389390
response=sample.response,
390391
)
391392
)
392-
req = self.llm.agenerate_text(
393+
req = t.cast(BaseRagasLLM, self.llm).agenerate_text(
393394
formatted_prompt,
394395
n=1,
395396
temperature=0.1,
@@ -408,7 +409,7 @@ async def _single_turn_ascore(
408409
response=sample.response,
409410
)
410411
)
411-
req = self.llm.agenerate_text(
412+
req = t.cast(BaseRagasLLM, self.llm).agenerate_text(
412413
formatted_prompt,
413414
n=1,
414415
temperature=0.1,

src/ragas/metrics/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from ragas.async_utils import apply_nest_asyncio, run
1616
from ragas.callbacks import ChainType, new_group
1717
from ragas.dataset_schema import MetricAnnotation, MultiTurnSample, SingleTurnSample
18+
from ragas.llms import BaseRagasLLM
1819
from ragas.losses import BinaryMetricLoss, MSELoss
1920
from ragas.metrics.validators import AllowedValuesType
2021
from ragas.prompt import FewShotPydanticPrompt, PromptMixin
@@ -28,8 +29,6 @@
2829
from ragas.config import DemonstrationConfig, InstructionConfig
2930
from ragas.dataset import Dataset
3031
from ragas.embeddings import BaseRagasEmbedding, BaseRagasEmbeddings
31-
from ragas.llms import BaseRagasLLM
32-
from ragas.llms.base import InstructorBaseRagasLLM
3332
from ragas.metrics.result import MetricResult
3433
from ragas.prompt.simple_prompt import Prompt
3534

@@ -232,11 +231,12 @@ class MetricWithLLM(Metric, PromptMixin):
232231
233232
Attributes
234233
----------
235-
llm : Optional[BaseRagasLLM | InstructorBaseRagasLLM]
236-
The language model used for the metric.
234+
llm : Optional[BaseRagasLLM]
235+
The language model used for the metric. Both BaseRagasLLM and InstructorBaseRagasLLM
236+
are accepted at runtime via duck typing (both have compatible methods).
237237
"""
238238

239-
llm: t.Optional[t.Union[BaseRagasLLM, "InstructorBaseRagasLLM"]] = None
239+
llm: t.Optional[BaseRagasLLM] = None
240240
output_type: t.Optional[MetricOutputType] = None
241241

242242
def init(self, run_config: RunConfig) -> None:
@@ -257,7 +257,9 @@ def init(self, run_config: RunConfig) -> None:
257257
raise ValueError(
258258
f"Metric '{self.name}' has no valid LLM provided (self.llm is None). Please instantiate the metric with an LLM to run."
259259
)
260-
self.llm.set_run_config(run_config)
260+
# Only BaseRagasLLM has set_run_config method, not InstructorBaseRagasLLM
261+
if isinstance(self.llm, BaseRagasLLM):
262+
self.llm.set_run_config(run_config)
261263

262264
def _optimize_instruction(
263265
self,

0 commit comments

Comments
 (0)