使用变体调整提示#

实验性功能

这是一个实验性功能,可能会随时更改。了解更多更多

为了更好地理解这部分内容,请先阅读快速开始运行和评估流程

什么是变体以及我们为什么应该关心#

为了帮助用户更高效地调整提示,我们引入了变体概念,它可以帮助您测试模型在不同条件下的行为,例如不同的措辞、格式、上下文、温度或top-k,比较并找到最佳提示和配置,以最大化模型的准确性、多样性或连贯性。

使用不同的变体节点创建运行#

在这个例子中,我们使用了流程 web-classification,它的节点 summarize_text_content 有两个变体:variant_0variant_1。它们之间的区别在于输入参数:

...
nodes:
- name: summarize_text_content
  use_variants: true
...
node_variants:
  summarize_text_content:
    default_variant_id: variant_0
    variants:
      variant_0:
        node:
          type: llm
          source:
            type: code
            path: summarize_text_content.jinja2
          inputs:
            deployment_name: text-davinci-003
            max_tokens: '128'
            temperature: '0.2'
            text: ${fetch_text_content_from_url.output}
          provider: AzureOpenAI
          connection: open_ai_connection
          api: completion
          module: promptflow.tools.aoai
      variant_1:
        node:
          type: llm
          source:
            type: code
            path: summarize_text_content__variant_1.jinja2
          inputs:
            deployment_name: text-davinci-003
            max_tokens: '256'
            temperature: '0.3'
            text: ${fetch_text_content_from_url.output}
          provider: AzureOpenAI
          connection: open_ai_connection
          api: completion
          module: promptflow.tools.aoai

你可以在flow.dag.yaml中查看整个流程定义。

现在我们将创建一个变体运行,使用节点 summarize_text_content 的变体 variant_1。 假设您在工作目录 /examples/flows/standard 中。

注意我们传递了--variant来指定应该运行哪个节点的变体。

pf run create --flow web-classification --data web-classification/data.jsonl --variant '${summarize_text_content.variant_1}' --column-mapping url='${data.url}' --stream --name my_first_variant_run
from promptflow.client import PFClient

pf = PFClient()  # get a promptflow client
flow = "web-classification"
data= "web-classification/data.jsonl"

# use the variant1 of the summarize_text_content node.
variant_run = pf.run(
    flow=flow,
    data=data,
    variant="${summarize_text_content.variant_1}",  # use variant 1.
    column_mapping={"url": "${data.url}"},
)

pf.stream(variant_run)

img img

在创建变体运行后,您可以像评估标准流程运行一样,使用评估流程来评估变体运行。

下一步#

了解更多关于: