@@ -20,26 +20,43 @@ class NumericMetric(SimpleLLMMetric, NumericValidator):
2020
2121 This class is used for metrics that output numeric scores within a
2222 defined range, such as 0.0 to 1.0 for similarity scores or 1-10 ratings.
23+ Uses the instructor library for structured LLM outputs.
2324
2425 Attributes
2526 ----------
2627 allowed_values : Union[Tuple[float, float], range]
2728 The valid range for metric outputs. Can be a tuple of (min, max) floats
2829 or a range object. Default is (0.0, 1.0).
30+ llm : Optional[BaseRagasLLM]
31+ The language model instance for evaluation. Can be created using llm_factory().
32+ prompt : Optional[Union[str, Prompt]]
33+ The prompt template for the metric. Should contain placeholders for
34+ evaluation inputs that will be formatted at runtime.
2935
3036 Examples
3137 --------
3238 >>> from ragas.metrics import NumericMetric
33- >>> from ragas.llms import LangchainLLMWrapper
34- >>> from langchain_openai import ChatOpenAI
39+ >>> from ragas.llms import llm_factory
40+ >>> from openai import OpenAI
41+ >>>
42+ >>> # Create an LLM instance
43+ >>> client = OpenAI(api_key="your-api-key")
44+ >>> llm = llm_factory("gpt-4o-mini", client=client)
3545 >>>
3646 >>> # Create a custom numeric metric with 0-10 range
37- >>> llm = LangchainLLMWrapper(ChatOpenAI())
3847 >>> metric = NumericMetric(
3948 ... name="quality_score",
4049 ... llm=llm,
50+ ... prompt="Rate the quality of this response on a scale of 0-10: {response}",
4151 ... allowed_values=(0.0, 10.0)
4252 ... )
53+ >>>
54+ >>> # Score with the metric
55+ >>> result = metric.score(
56+ ... llm=llm,
57+ ... response="This is a great response!"
58+ ... )
59+ >>> print(result.value) # Output: a float between 0.0 and 10.0
4360 """
4461
4562 allowed_values : t .Union [t .Tuple [float , float ], range ] = (0.0 , 1.0 )
0 commit comments