def generation_step_from_json(generation_step_json: Dict[str, Any]) -> GenerationStep: """Load generation step from JSON.""" generation_step_json = _convert_generation_step_keys_for_backwards_compatibility( generation_step_json ) kwargs = generation_step_json.pop("model_kwargs", None) gen_kwargs = generation_step_json.pop("model_gen_kwargs", None) return GenerationStep( model=object_from_json(generation_step_json.pop("model")), num_trials=generation_step_json.pop("num_trials"), min_trials_observed=generation_step_json.pop("min_trials_observed", 0), max_parallelism=(generation_step_json.pop("max_parallelism", None)), use_update=generation_step_json.pop("use_update", False), enforce_num_trials=generation_step_json.pop("enforce_num_trials", True), model_kwargs=_decode_callables_from_references(object_from_json(kwargs)) if kwargs else None, model_gen_kwargs=_decode_callables_from_references(object_from_json(gen_kwargs)) if gen_kwargs else None, index=generation_step_json.pop("index", -1), should_deduplicate=generation_step_json.pop("should_deduplicate") if "should_deduplicate" in generation_step_json else False, )
def generation_step_from_json( generation_step_json: Dict[str, Any]) -> GenerationStep: """Load generation step from JSON.""" return GenerationStep( model=object_from_json(generation_step_json.pop("model")), num_trials=generation_step_json.pop("num_trials"), min_trials_observed=generation_step_json.pop("min_trials_observed"), max_parallelism=generation_step_json.pop("max_parallelism"), use_update=generation_step_json.pop("use_update"), enforce_num_trials=generation_step_json.pop("enforce_num_trials"), model_kwargs=_decode_callables_from_references( object_from_json(generation_step_json.pop("model_kwargs"))) or None, model_gen_kwargs=_decode_callables_from_references( object_from_json(generation_step_json.pop("model_gen_kwargs"))) or None, index=generation_step_json.pop("index"), )