1515from ragas .async_utils import apply_nest_asyncio , run
1616from ragas .callbacks import ChainType , new_group
1717from ragas .dataset_schema import MetricAnnotation , MultiTurnSample , SingleTurnSample
18+ from ragas .llms import BaseRagasLLM
1819from ragas .losses import BinaryMetricLoss , MSELoss
1920from ragas .metrics .validators import AllowedValuesType
2021from ragas .prompt import FewShotPydanticPrompt , PromptMixin
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