classPostprocessorComponent(QueryComponent):"""Postprocessor component."""model_config=ConfigDict(arbitrary_types_allowed=True)postprocessor:SerializeAsAny[BaseNodePostprocessor]=Field(...,description="Postprocessor")defset_callback_manager(self,callback_manager:CallbackManager)->None:"""Set callback manager."""self.postprocessor.callback_manager=callback_managerdef_validate_component_inputs(self,input:Dict[str,Any])->Dict[str,Any]:"""Validate component inputs during run_component."""# make sure `nodes` is a list of nodesif"nodes"notininput:raiseValueError("Input must have key 'nodes'")nodes=input["nodes"]ifnotisinstance(nodes,list):raiseValueError("Input nodes must be a list")fornodeinnodes:ifnotisinstance(node,NodeWithScore):raiseValueError("Input nodes must be a list of NodeWithScore")# if query_str exists, make sure `query_str` is stringableif"query_str"ininput:input["query_str"]=validate_and_convert_stringable(input["query_str"])returninputdef_run_component(self,**kwargs:Any)->Any:"""Run component."""output=self.postprocessor.postprocess_nodes(kwargs["nodes"],query_str=kwargs.get("query_str"))return{"nodes":output}asyncdef_arun_component(self,**kwargs:Any)->Any:"""Run component (async)."""# NOTE: no native async for postprocessorreturnself._run_component(**kwargs)@propertydefinput_keys(self)->InputKeys:"""Input keys."""returnInputKeys.from_keys({"nodes"},optional_keys={"query_str"})@propertydefoutput_keys(self)->OutputKeys:"""Output keys."""returnOutputKeys.from_keys({"nodes"})