From 1db13e8a85a01ef1f5d9a24bf61f200c7bca242f Mon Sep 17 00:00:00 2001 From: William FH <13333726+hinthornw@users.noreply.github.com> Date: Sun, 16 Jul 2023 17:47:05 -0700 Subject: [PATCH] Fix chat example output mapper (#7808) Was only serializing when no key was provided --- .../smith/evaluation/string_run_evaluator.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/langchain/smith/evaluation/string_run_evaluator.py b/langchain/smith/evaluation/string_run_evaluator.py index 390589e859d..297e64407b5 100644 --- a/langchain/smith/evaluation/string_run_evaluator.py +++ b/langchain/smith/evaluation/string_run_evaluator.py @@ -200,19 +200,18 @@ class StringExampleMapper(Serializable): ) else: output = list(example.outputs.values())[0] - return { - "reference": self.serialize_chat_messages([output]) - if isinstance(output, dict) - and output.get("type") - and output.get("data") - else str(output) - } elif self.reference_key not in example.outputs: raise ValueError( f"Example {example.id} does not have reference key" f" {self.reference_key}." ) - return {"reference": str(example.outputs[self.reference_key])} + else: + output = example.outputs[self.reference_key] + return { + "reference": self.serialize_chat_messages([output]) + if isinstance(output, dict) and output.get("type") and output.get("data") + else str(output) + } def __call__(self, example: Example) -> Dict[str, str]: """Maps the Run and Example to a dictionary."""