Task¶
本节包含 distilabel
任务的 API 参考。
有关 Task
如何工作的更多信息和一些示例,请查看 教程 - 任务 页面。
base
¶
_Task
¶
基类:_Step
, ABC
_Task 是一个抽象类,它实现了 _Step
接口,并添加了 format_input
和 format_output
方法来格式化任务的输入和输出。它还添加了一个 llm
属性,用作生成输出的 LLM。
属性
名称 | 类型 | 描述 |
---|---|---|
llm |
LLM
|
用于生成任务输出的 |
group_generations |
bool
|
是否将每个输入生成的 |
add_raw_output |
RuntimeParameter[bool]
|
是否在输出的 |
num_generations |
RuntimeParameter[int]
|
每个输入要生成的代数。 |
源代码在 src/distilabel/steps/tasks/base.py
中
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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
is_global
property
¶
扩展 is_global
属性,如果任务正在使用离线批量生成功能,则返回 True
,否则返回父类属性的值。offline_batch_generation
需要一次接收所有输入,因此对于 _BatchManager
来说,这是一个全局步骤。
返回
类型 | 描述 |
---|---|
bool
|
任务是否为全局步骤。 |
load()
¶
unload()
¶
impute_step_outputs(step_output)
¶
如果 LLM 未能生成响应,则推定任务的输出。
源代码在 src/distilabel/steps/tasks/base.py
中
format_output(output, input=None)
abstractmethod
¶
用于格式化任务输出的抽象方法。它需要接收一个字符串形式的输出,并生成一个包含任务输出的 Python 字典。此外,还会接收用于生成输出的 input
,以防需要正确解析输出。
源代码在 src/distilabel/steps/tasks/base.py
中
get_structured_output()
¶
返回默认情况下实现结构化输出的任务,必须由 Task
的子类覆盖。当实现时,应该是一个 json 模式,用于强制 LLM 的响应,以便更容易解析。
源代码在 src/distilabel/steps/tasks/base.py
中
print(sample_input=None)
¶
使用 rich
库将示例输入打印到控制台。用于可视化任务提示的辅助方法。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
sample_input
|
可选[ChatType]
|
要打印的示例输入。如果未提供,将使用 |
None
|
示例
打印 URIAL 提示
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: │ │
│ ╰───────────────────────────────────────────────────────────────────────────────────────────╯ │
╰───────────────────────────────────────────────────────────────────────────────────────────────╯
源代码在 src/distilabel/steps/tasks/base.py
中
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 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
Task
¶
Task 是一个类,它实现了 _Task
抽象类,并添加了 Step
接口,用作管道中的步骤。
属性
名称 | 类型 | 描述 |
---|---|---|
llm |
LLM
|
用于生成任务输出的 |
group_generations |
bool
|
是否将每个输入生成的 |
num_generations |
RuntimeParameter[int]
|
每个输入要生成的代数。 |
源代码在 src/distilabel/steps/tasks/base.py
中
format_input(input)
abstractmethod
¶
用于格式化任务输入的抽象方法。它需要接收一个 Python 字典形式的输入,并生成一个类似 OpenAI chat 的字典列表。
源代码在 src/distilabel/steps/tasks/base.py
中
process(inputs)
¶
处理任务的输入并使用 LLM 生成输出。
参数
名称 | 类型 | 描述 | 默认 |
---|---|---|---|
inputs
|
StepInput
|
包含任务输入的 Python 字典列表。 |
必需 |
产出
类型 | 描述 |
---|---|
StepOutput
|
包含任务输出的 Python 字典列表。 |