Skip to content

universal

Classes:

Name Description
ChatRoleStrings

Role strings of a chat prompt.

ChatSchemaMapper

Maps samples from an arbitrary dataset to a universal schema for building an LLM chat prompt.

SchemaMapper

Maps samples from an arbitrary dataset to a universal schema for building an LLM prompt.

ChatRoleStrings dataclass

Role strings of a chat prompt.

Added in version 0.77.0.

Attributes:

Name Type Description
ASSISTANT_ROLE Final[str]

The assistant role.

SYSTEM_ROLE Final[str]

The system role.

USER_ROLE Final[str]

The user role.

ASSISTANT_ROLE class-attribute instance-attribute

ASSISTANT_ROLE: Final[str] = 'assistant'

The assistant role.

SYSTEM_ROLE class-attribute instance-attribute

SYSTEM_ROLE: Final[str] = 'system'

The system role.

USER_ROLE class-attribute instance-attribute

USER_ROLE: Final[str] = 'user'

The user role.

ChatSchemaMapper dataclass

Bases: SchemaMapper

Maps samples from an arbitrary dataset to a universal schema for building an LLM chat prompt.

Either define a subclass for easier reuse, or use this directly.

Examples:

>>> sample = {
...     "question": "What is the capital of France?",
...     "response": "Paris",
...     "system_prompt": "Answer the following question:",
... }
>>> mapper = ChatSchemaMapper(
...     instruction_key="question",
...     response_key="response",
...     system_prompt_key="system_prompt",
... )
>>> mapped_sample = mapper(sample)
>>> mapped_sample
[{'role': 'system', 'content': 'Answer the following question:'}, {'role': 'user', 'content': 'What is the capital of France?'}, {'role': 'assistant', 'content': 'Paris'}]

Added in version 0.77.0.

Classes:

Name Description
Schema

Universal schema for building an LLM chat prompt.

Attributes:

Name Type Description
instruction_key str

The dataset key/column corresponding to the input.

response_key str | None

An optional dataset key/column corresponding to the expected model response to the instruction.

system_prompt_key str | None

An optional dataset key/column corresponding to the system prompt for the model.

instruction_key instance-attribute

instruction_key: str

The dataset key/column corresponding to the input.

response_key instance-attribute

response_key: str | None

An optional dataset key/column corresponding to the expected model response to the instruction.

system_prompt_key instance-attribute

system_prompt_key: str | None

An optional dataset key/column corresponding to the system prompt for the model.

Schema

Bases: Schema

Universal schema for building an LLM chat prompt.

Added in version 0.77.0.

Attributes:

Name Type Description
content str

The content of the message.

role str

The role of the message.

content instance-attribute

content: str

The content of the message.

role instance-attribute

role: str

The role of the message.

SchemaMapper dataclass

Bases: ABC

Maps samples from an arbitrary dataset to a universal schema for building an LLM prompt.

Added in version 0.77.0. Base class for `InstructionSchemaMapper` and `ChatSchemaMapper`.

Classes:

Name Description
Schema

Base schema for building an LLM prompt.

Attributes:

Name Type Description
instruction_key str

The dataset key/column corresponding to the input.

instruction_key instance-attribute

instruction_key: str

The dataset key/column corresponding to the input.

Schema

Bases: TypedDict

Base schema for building an LLM prompt.