Upload instructions.py with huggingface_hub
Browse files12234456788910111213141516171819202122232425262728102930313233343517363738202139404142434445from abc import abstractmethodfrom typing import Dictfrom typing import Any, Dict, Optional
from .artifact import Artifactfrom .collections import ListCollectionfrom .dataclass import NonPositionalFieldfrom .operator import StreamInstanceOperator
class Instruction(Artifact):class 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 instance
instance["instruction"] = self.get_instruction(instance)
return instance
@abstractmethod def __call__(self) -> str: def get_instruction(self, instance: Dict[str, object]) -> str: pass
class TextualInstruction(Instruction): text: str
def __call__(self) -> str: def get_instruction(self, instance: Dict[str, object]) -> str: return self.text
def __repr__(self): return self.text
class EmptyInstruction(Instruction): def get_instruction(self, instance: Dict[str, object]) -> str: return ""
class InstructionsList(ListCollection):instructions.py+28-7