AgentGoalAccuracyWithoutReference 从不设置 output_type,因此 metric.train() 指令优化会以 ValueError 终止
import json, tempfile, os from ragas.config import InstructionConfig from ragas.llms.base import BaseRagasLLM from ragas.run_config import RunConfig from ragas.metrics._goal_accuracy import (AgentGoalAccuracyWithReference, AgentGoalAccuracyWithoutReference) class FakeLLM(BaseRagasLLM): run_config = RunConfig() def generate_text(self, *a, **k): raise NotImplementedError async def agenerate_text(self, *a, **k): raise NotImplementedError def is_finished(self, response): return True path = os.path.join(tempfile.mkdtemp(), "train.json") json.dump({"agent_goal_accuracy": [ { "metric_input": { "user_input": [ {"content": "book a flight to Paris", "type": "human"} ], "reference": "a flight to Paris is booked" }, "metric_output": 1.0, "prompts": {}, "is_accepted": True, "target": 1.0, } ], }, open(path, "w")) for cls in (AgentGoalAccuracyWithReference, AgentGoalAccuracyWithoutReference): m = cls(LLM=FakeLLM()) print(f"{cls.__name__}.output_type = {m.output_type!r}") try: m.train(path, instruction_config=InstructionConfig(LLM=FakeLLM())) except Exception as e: print(f" train() -> {type(e).__name__}: {e}") else: print(" train() -> completed")
内容来源: vibrantlabsai/ragas