ChatGeneration¶
基于对话生成文本。
ChatGeneration
是一个预定义的任务,它将 messages
定义为输入,generation
定义为输出。此任务用于基于对话生成文本。model_name
也作为输出的一部分返回,以便增强它。
输入 & 输出列¶
graph TD
subgraph Dataset
subgraph Columns
ICOL0[messages]
end
subgraph New columns
OCOL0[generation]
OCOL1[model_name]
end
end
subgraph ChatGeneration
StepInput[Input Columns: messages]
StepOutput[Output Columns: generation, model_name]
end
ICOL0 --> StepInput
StepOutput --> OCOL0
StepOutput --> OCOL1
StepInput --> StepOutput
输入¶
- messages (
List[Dict[Literal["role", "content"], str]]
): 用于生成后续补全的消息。
输出¶
-
generation (
str
): 助手生成的文本。 -
model_name (
str
): 用于生成文本的模型名称。
示例¶
从 OpenAI chat 格式的对话生成文本¶
from distilabel.steps.tasks import ChatGeneration
from distilabel.models import InferenceEndpointsLLM
# Consider this as a placeholder for your actual LLM.
chat = ChatGeneration(
llm=InferenceEndpointsLLM(
model_id="mistralai/Mistral-7B-Instruct-v0.2",
)
)
chat.load()
result = next(
chat.process(
[
{
"messages": [
{"role": "user", "content": "How much is 2+2?"},
]
}
]
)
)
# result
# [
# {
# 'messages': [{'role': 'user', 'content': 'How much is 2+2?'}],
# 'model_name': 'mistralai/Mistral-7B-Instruct-v0.2',
# 'generation': '4',
# }
# ]