Skip to main content

AlpacaItem

class AlpacaItem(BaseModel):
Represents an instruction-response item in the Alpaca format. Appropripate for both cases where input field is empty, or populated. Provides parsing from string format using the class method from_string(). Parameters:
  • instruction (str): The instruction/question/prompt
  • input (str): Input context or examples (put empty string if none)
  • output (str): The response/answer to the instruction

no_section_markers

def no_section_markers(cls, value: str):
Ensures fields don’t contain section markers like ’### Response:‘

from_string

def from_string(cls, text: str):
Creates an AlpacaItem from a formatted string. Parameters:
  • text: String in either of these formats: With input: ### Instruction: {instruction} ### Input: {input} ### Response: {response} Without input: ### Instruction: {instruction} ### Response: {response}
Returns: AlpacaItem: Parsed instance

to_string

def to_string(self):
Returns: str: Formatted string representation with sections markers