Upload formats.py with huggingface_hub
Browse files17 unmodified lines181920212223242526272829303132333435363 unmodified lines40414243444546474849505117 unmodified linesinput_output_separator: str = "\n"demo_separator: str = "\n\n"suffix: str = ""def single_source_str(self, source):return self.input_prefix + source + self.input_output_separator + self.output_prefixdef format(self, instance, demos_instances=[]):source = self.prefixquery_str = self.single_source_str(instance["source"])if "instruction" in instance:instruction = instance.pop("instruction")source += self.instruction_prefix + instruction + self.demo_separatorfor demo_instance in demos_instances:demo_str = (self.single_source_str(demo_instance["source"])3 unmodified lines)if self.size_limiter is not None:if not self.size_limiter.check(source + demo_str + query_str + instance["target"]):continuesource += demo_strsource += query_strsource += self.suffixreturn source17 unmodified lines181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465663 unmodified lines7071727374757677787980818217 unmodified linesinput_output_separator: str = "\n"demo_separator: str = "\n\n"suffix: str = ""add_instruction_at_start: bool = Trueadd_instruction_after_demos: bool = Falsedef single_source_str(self, source):return (self.input_prefix+ source+ self.input_output_separator+ self.output_prefix)def single_source_str_with_instruction(self, source, instruction):return (self.input_prefix+ instruction+ self.demo_separator+ source+ self.input_output_separator+ self.output_prefix)def format(self, instance, demos_instances=None):if demos_instances is None:demos_instances = []source = self.prefixinstruction = ""if "instruction" in instance:instruction = instance.pop("instruction")assert ("instruction" != None), f"instruction field can not be none : {instance}"if self.add_instruction_at_start and instruction != "":source += self.instruction_prefix + instruction + self.demo_separatorif self.add_instruction_after_demos and instruction != "":query_str = self.single_source_str_with_instruction(instance["source"], instruction)else:query_str = self.single_source_str(instance["source"])for demo_instance in demos_instances:demo_str = (self.single_source_str(demo_instance["source"])3 unmodified lines)if self.size_limiter is not None:if not self.size_limiter.check(source + demo_str + query_str + instance["target"]):continuesource += demo_strsource += query_strsource += self.suffixreturn source
formats.py+37-6