跳到内容

PrepareExamples

Helper step to create examples from query and answers pairs used as Few Shots in APIGen.

输入和输出列

graph TD
    subgraph Dataset
        subgraph Columns
            ICOL0[query]
            ICOL1[answers]
        end
        subgraph New columns
            OCOL0[examples]
        end
    end

    subgraph PrepareExamples
        StepInput[Input Columns: query, answers]
        StepOutput[Output Columns: examples]
    end

    ICOL0 --> StepInput
    ICOL1 --> StepInput
    StepOutput --> OCOL0
    StepInput --> StepOutput

输入

  • query (str): 用于生成示例的查询。

  • answers (str): 查询的答案。

输出

  • examples (str): 格式化的示例。

示例

为 APIGen 生成示例

from distilabel.steps.tasks.apigen.utils import PrepareExamples

prepare_examples = PrepareExamples()
result = next(prepare_examples.process(
    [
        {
            "query": ['I need the area of circles with radius 2.5, 5, and 7.5 inches, please.', 'Can you provide the current locations of buses and trolleys on route 12?'],
            "answers": ['[{"name": "circle_area", "arguments": {"radius": 2.5}}, {"name": "circle_area", "arguments": {"radius": 5}}, {"name": "circle_area", "arguments": {"radius": 7.5}}]', '[{"name": "bus_trolley_locations", "arguments": {"route": "12"}}]']
        }
    ]
)
# result
# [{'examples': '## Query:\nI need the area of circles with radius 2.5, 5, and 7.5 inches, please.\n## Answers:\n[{"name": "circle_area", "arguments": {"radius": 2.5}}, {"name": "circle_area", "arguments": {"radius": 5}}, {"name": "circle_area", "arguments": {"radius": 7.5}}]\n\n## Query:\nCan you provide the current locations of buses and trolleys on route 12?\n## Answers:\n[{"name": "bus_trolley_locations", "arguments": {"route": "12"}}]'}, {'examples': '## Query:\nI need the area of circles with radius 2.5, 5, and 7.5 inches, please.\n## Answers:\n[{"name": "circle_area", "arguments": {"radius": 2.5}}, {"name": "circle_area", "arguments": {"radius": 5}}, {"name": "circle_area", "arguments": {"radius": 7.5}}]\n\n## Query:\nCan you provide the current locations of buses and trolleys on route 12?\n## Answers:\n[{"name": "bus_trolley_locations", "arguments": {"route": "12"}}]'}]