bench-answer-generator
GitHub生成基准测试问题的模型答案,配合评估器使用。通过LLM服务将数据框中的问题转换为标准答案,支持多种评估类型和提示模板配置,用于统一基准评测流程。
Trigger Scenarios
Install
npx skills add OpenDCAI/DataFlow-WebUI --skill bench-answer-generator -g -y
SKILL.md
Frontmatter
{
"name": "bench-answer-generator",
"description": "Reference documentation for the BenchAnswerGenerator operator. Covers the constructor, full run() signature, actual generation behavior, and integration notes for unified bench evaluation pipelines.\nUse when: generating model answers from benchmark question rows before passing the dataframe into UnifiedBenchDatasetEvaluator."
}
BenchAnswerGenerator Operator Reference
BenchAnswerGenerator generates model answers from a benchmark dataframe and is designed to align with UnifiedBenchDatasetEvaluator.
1. Import
from dataflow.operators.core_text import BenchAnswerGenerator
2. Constructor
BenchAnswerGenerator(
eval_type="key2_qa",
llm_serving=llm,
prompt_template=FormatStrPrompt(f_str_template="Question: {question}\nAnswer:"),
system_prompt="You are a helpful assistant specialized in generating answers to questions.",
allow_overwrite=False,
force_generate=False,
)
| Parameter | Required | Default | Description |
|---|---|---|---|
eval_type |
No | "key2_qa" |
Evaluation type |
llm_serving |
Yes | None |
LLM service object implementing generate_from_input(...) |
prompt_template |
No | FormatStrPrompt |
Prompt object used to build prompts. In practice, pass a FormatStrPrompt(...) instance, None, or a DIYPromptABC subclass instance |
system_prompt |
No | "You are a helpful assistant specialized in generating answers to questions." |
System prompt forwarded to the serving layer when supported |
allow_overwrite |
No | False |
Whether to overwrite an existing output column |
force_generate |
No | False |
Whether to force generation for some types that are skipped by default |
Important prompt_template Note
Although the source code sets the default value to FormatStrPrompt, that
default is the class object itself, not an instance.
In normal usage, you usually want to pass a FormatStrPrompt(...) instance so
you can explicitly control the prompt text. None is also supported and makes
the operator fall back to its built-in prompt builder.
Use one of these patterns instead:
from dataflow.prompts.core_text import FormatStrPrompt
prompt_template=FormatStrPrompt(
f_str_template="Question: {question}\nAnswer:"
)
or
prompt_template=None
When prompt_template is a FormatStrPrompt instance, the current source may
pass these fields into build_prompt(...):
eval_typequestioncontextchoiceschoices_text
For key2_qa and key2_q_ma, the practical required field is question.
For key3_q_choices_a and key3_q_choices_as, the practical required fields
are question and choices. If you want cleaner formatting for choice tasks,
prefer {choices_text} over {choices}.
Supported eval_type Values
| eval_type | Default behavior in current source |
|---|---|
key1_text_score |
Skips generation |
key2_qa |
Generates |
key2_q_ma |
Generates |
key3_q_choices_a |
Skips generation by default |
key3_q_choices_as |
Generates |
key3_q_a_rejected |
Skips generation |
If force_generate=True, the current implementation generates for all types
except key1_text_score.
3. run() Signature
op.run(
storage=self.storage.step(),
input_text_key=None,
input_question_key=None,
input_target_key=None,
input_targets_key=None,
input_choices_key=None,
input_label_key=None,
input_labels_key=None,
input_better_key=None,
input_rejected_key=None,
input_context_key=None,
output_key="generated_ans",
)
# returns: [output_key] or []
| Parameter | Required | Default | Description |
|---|---|---|---|
storage |
Yes | None | Current operator-step storage object |
input_text_key |
No | None |
Declared for evaluator API alignment; not used in current run() implementation |
input_question_key |
Conditionally required | None |
Required whenever generation is actually performed |
input_target_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_targets_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_choices_key |
Conditionally required | None |
Required for key3_q_choices_a and key3_q_choices_as when generation is performed |
input_label_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_labels_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_better_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_rejected_key |
No | None |
Declared for API alignment; not used in current run() implementation |
input_context_key |
No | None |
Optional context column name |
output_key |
No | "generated_ans" |
Output column written back into the dataframe |
4. Actual Execution Logic
The current implementation behaves as follows:
- Read the dataframe from
storage. - Decide whether generation is needed by calling
_need_generation(eval_type). - If generation is not needed, write the dataframe back unchanged and return
[]. - If
output_keyalready exists andallow_overwrite=False, write the dataframe back unchanged and return[]. - Require
input_question_keyto exist whenever generation is performed. - For
key3_q_choices_aandkey3_q_choices_as, also requireinput_choices_key. - If
input_context_keyis provided and exists, normalize it into a prompt context string. - Build one prompt per row using
prompt_template.build_prompt(...)when available; otherwise fall back to an internal prompt template. - Call
llm_serving.generate_from_input(...). - Write the generated answers into
dataframe[output_key], persist viastorage.write(df), and return[output_key].
5. Important Rules
- In the current source,
key3_q_choices_adoes not generate by default. It is skipped unlessforce_generate=True. - In the current source,
key1_text_scorenever generates, even ifforce_generate=True. input_question_keyis the only mandatory input column for generated question-answer flows in the current implementation.- The declared parameters
input_text_key,input_target_key,input_targets_key,input_label_key,input_labels_key,input_better_key, andinput_rejected_keyare currently exposed for API compatibility, but they are not consumed insiderun(). - If
input_choices_keyis present but a row contains an empty or invalid value, the implementation substitutes[""]instead of failing that row. - The return value is a list: usually
[output_key]on success, or[]when skipped.
6. Typical Usage
from dataflow.operators.core_text import BenchAnswerGenerator
from dataflow.prompts.core_text import FormatStrPrompt
prompt_template = FormatStrPrompt(
f_str_template="Context: {context}\nQuestion: {question}\nAnswer:"
)
generator = BenchAnswerGenerator(
eval_type="key2_qa",
llm_serving=self.llm_serving,
prompt_template=prompt_template,
allow_overwrite=False,
)
generator.run(
storage=self.storage.step(),
input_question_key="question",
input_context_key="context",
output_key="generated_ans",
)
Version History
- 2e95d40 Current 2026-08-27 09:03


