Task¶
This section contains the API reference for the distilabel
tasks.
For more information on how the Task
works and see some examples, check the Tutorial - Task page.
base
¶
_Task
¶
Bases: _Step
, ABC
_Task is an abstract class that implements the _Step
interface and adds the
format_input
and format_output
methods to format the inputs and outputs of the
task. It also adds a llm
attribute to be used as the LLM to generate the outputs.
Attributes:
Name | Type | Description |
---|---|---|
llm |
LLM
|
the |
group_generations |
bool
|
whether to group the |
add_raw_output |
RuntimeParameter[bool]
|
whether to include a field with the raw output of the LLM in the
|
num_generations |
RuntimeParameter[int]
|
The number of generations to be produced per input. |
Source code in src/distilabel/steps/tasks/base.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
is_global: bool
property
¶
Extends the is_global
property to return True
if the task is using the
offline batch generation feature, otherwise it returns the value of the parent
class property. offline_batch_generation
requires to receive all the inputs
at once, so for the _BatchManager
this is a global step.
Returns:
Type | Description |
---|---|
bool
|
Whether the task is a global step or not. |
load()
¶
unload()
¶
impute_step_outputs(step_output)
¶
Imputes the outputs of the task in case the LLM failed to generate a response.
Source code in src/distilabel/steps/tasks/base.py
format_output(output, input=None)
abstractmethod
¶
Abstract method to format the outputs of the task. It needs to receive an output
as a string, and generates a Python dictionary with the outputs of the task. In
addition the input
used to generate the output is also received just in case it's
needed to be able to parse the output correctly.
Source code in src/distilabel/steps/tasks/base.py
get_structured_output()
¶
Returns the structured output for a task that implements one by default,
must be overriden by subclasses of Task
. When implemented, should be a json
schema that enforces the response from the LLM so that it's easier to parse.
Source code in src/distilabel/steps/tasks/base.py
print(sample_input=None)
¶
Prints a sample input to the console using the rich
library.
Helper method to visualize the prompt of the task.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sample_input
|
Optional[ChatType]
|
A sample input to be printed. If not provided, a default will be
generated using the |
None
|
Examples:
Print the URIAL prompt:
from distilabel.steps.tasks import URIAL
from distilabel.models.llms.huggingface import InferenceEndpointsLLM
# Consider this as a placeholder for your actual LLM.
urial = URIAL(
llm=InferenceEndpointsLLM(
model_id="meta-llama/Meta-Llama-3.1-70B-Instruct",
),
)
urial.load()
urial.print()
╭─────────────────────────────────────── Prompt: URIAL ────────────────────────────────────────╮
│ ╭────────────────────────────────────── User Message ───────────────────────────────────────╮ │
│ │ # Instruction │ │
│ │ │ │
│ │ Below is a list of conversations between a human and an AI assistant (you). │ │
│ │ Users place their queries under "# User:", and your responses are under "# Assistant:". │ │
│ │ You are a helpful, respectful, and honest assistant. │ │
│ │ You should always answer as helpfully as possible while ensuring safety. │ │
│ │ Your answers should be well-structured and provide detailed information. They should also │ │
│ │ have an engaging tone. │ │
│ │ Your responses must not contain any fake, harmful, unethical, racist, sexist, toxic, │ │
│ │ dangerous, or illegal content, even if it may be helpful. │ │
│ │ Your response must be socially responsible, and thus you can refuse to answer some │ │
│ │ controversial topics. │ │
│ │ │ │
│ │ │ │
│ │ # User: │ │
│ │ │ │
│ │ <PLACEHOLDER_INSTRUCTION> │ │
│ │ │ │
│ │ # Assistant: │ │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ │
╰───────────────────────────────────────────────────────────────────────────────────────────────╯
Source code in src/distilabel/steps/tasks/base.py
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
|
Task
¶
Task is a class that implements the _Task
abstract class and adds the Step
interface to be used as a step in the pipeline.
Attributes:
Name | Type | Description |
---|---|---|
llm |
the |
|
group_generations |
whether to group the |
|
num_generations |
The number of generations to be produced per input. |
Source code in src/distilabel/steps/tasks/base.py
format_input(input)
abstractmethod
¶
Abstract method to format the inputs of the task. It needs to receive an input as a Python dictionary, and generates an OpenAI chat-like list of dicts.
Source code in src/distilabel/steps/tasks/base.py
process(inputs)
¶
Processes the inputs of the task and generates the outputs using the LLM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
StepInput
|
A list of Python dictionaries with the inputs of the task. |
required |
Yields:
Type | Description |
---|---|
StepOutput
|
A list of Python dictionaries with the outputs of the task. |