文档API 参考📓 教程🧑‍🍳 食谱🤝 集成💜 Discord🎨 Studio
API 参考

DeepEval

DeepEval Haystack 集成

模块 haystack_integrations.components.evaluators.deepeval.evaluator

DeepEvalEvaluator

一个组件,使用 DeepEval 框架 根据特定指标评估输入。支持的指标由DeepEvalMetric.

使用示例

from haystack_integrations.components.evaluators.deepeval import DeepEvalEvaluator, DeepEvalMetric

evaluator = DeepEvalEvaluator(
    metric=DeepEvalMetric.FAITHFULNESS,
    metric_params={"model": "gpt-4"},
)
output = evaluator.run(
    questions=["Which is the most popular global sport?"],
    contexts=[
        [
            "Football is undoubtedly the world's most popular sport with"
            "major events like the FIFA World Cup and sports personalities"
            "like Ronaldo and Messi, drawing a followership of more than 4"
            "billion people."
        ]
    ],
    responses=["Football is the most popular sport with around 4 billion" "followers worldwide"],
)
print(output["results"])

DeepEvalEvaluator.__init__

def __init__(metric: Union[str, DeepEvalMetric],
             metric_params: Optional[Dict[str, Any]] = None)

构造一个新的 DeepEval 评估器。

参数:

  • metric:用于评估的指标。
  • metric_params:要传递给指标构造函数的参数。有关所需参数的更多详细信息,请参阅RagasMetric 类。

DeepEvalEvaluator.run

@component.output_types(results=List[List[Dict[str, Any]]])
def run(**inputs: Any) -> Dict[str, Any]

在提供的输入上运行 DeepEval 评估器。

参数:

  • inputs:要评估的输入。这些由正在计算的指标决定。有关更多信息,请参阅DeepEvalMetric

返回值:

一个字典,其中包含一个名为results 的条目,该条目包含一个嵌套的指标结果列表。每个输入可以有一个或多个结果,具体取决于指标。每个结果是一个包含以下键和值的字典:

  • name - 指标的名称。
  • score - 指标的分数。
  • explanation - 分数的可选说明。

DeepEvalEvaluator.to_dict

def to_dict() -> Dict[str, Any]

将组件序列化为字典。

引发:

  • DeserializationError:如果组件无法被序列化。

返回值:

包含序列化数据的字典。

DeepEvalEvaluator.from_dict

@classmethod
def from_dict(cls, data: Dict[str, Any]) -> "DeepEvalEvaluator"

从字典反序列化组件。

参数:

  • data: 要反序列化的字典。

返回值:

反序列化后的组件。

模块 haystack_integrations.components.evaluators.deepeval.metrics

DeepEvalMetric

DeepEval 支持的指标。

所有指标都需要一个model 参数,该参数指定用于评估的模型。有关支持模型的详细信息,请参阅 DeepEval 文档。

ANSWER_RELEVANCY

答案相关性。
输入 -questions: List[str], contexts: List[List[str]], responses: List[str]

FAITHFULNESS

忠实性。
输入 -questions: List[str], contexts: List[List[str]], responses: List[str]

CONTEXTUAL_PRECISION

上下文精确率。
输入 -questions: List[str], contexts: List[List[str]], responses: List[str], ground_truths: List[str]
地面真相是预期的响应。

CONTEXTUAL_RECALL

上下文召回率。
输入 -questions: List[str], contexts: List[List[str]], responses: List[str], ground_truths: List[str]
地面真相是预期的响应。\

CONTEXTUAL_RELEVANCE

上下文相关性。
输入 -questions: List[str], contexts: List[List[str]], responses: List[str]

DeepEvalMetric.from_str

@classmethod
def from_str(cls, string: str) -> "DeepEvalMetric"

从字符串创建指标类型。

参数:

  • string:要转换的字符串。

返回值:

指标。