Fix chat example output mapper (#7808)

Was only serializing when no key was provided
This commit is contained in:
William FH 2023-07-16 17:47:05 -07:00 committed by GitHub
parent c58d35765d
commit 1db13e8a85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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."""