Upload instructions.py with huggingface_hub
Browse files123456789101112131415161718192021222324from abc import abstractmethodfrom typing import Dictfrom .artifact import Artifactfrom .collections import ListCollectionclass Instruction(Artifact):@abstractmethoddef __call__(self) -> str:passclass TextualInstruction(Instruction):text: strdef __call__(self) -> str:return self.textdef __repr__(self):return self.textclass InstructionsList(ListCollection):123456789101112131415161718192021222324252627282930313233343536373839404142434445from abc import abstractmethodfrom typing import Any, Dict, Optionalfrom .collections import ListCollectionfrom .dataclass import NonPositionalFieldfrom .operator import StreamInstanceOperatorclass Instruction(StreamInstanceOperator):"""The role of instruction is to add instruction to every instance.Meaning the instruction is taking the instance and generating instruction field for it."""skip_rendered_instance: bool = NonPositionalField(default=True)def process(self, instance: Dict[str, Any], stream_name: Optional[str] = None) -> Dict[str, Any]:if self.skip_rendered_instance:if "instruction" in instance:return instanceinstance["instruction"] = self.get_instruction(instance)return instance@abstractmethoddef get_instruction(self, instance: Dict[str, object]) -> str:passclass TextualInstruction(Instruction):text: strdef get_instruction(self, instance: Dict[str, object]) -> str:return self.textclass EmptyInstruction(Instruction):def get_instruction(self, instance: Dict[str, object]) -> str:return ""class InstructionsList(ListCollection):
instructions.py+28-7