开始使用免费开始使用

One-shot chain-of-thought 提示

当您需要对给定集合中的偶数求和时,首先要找出这些偶数,然后再相加。您可以通过一个或多个示例把这种做法教给语言模型,它在处理新集合时就会按这一策略操作。

本练习的目标是教会模型如何在集合 {9, 10, 13, 4, 2} 上执行该步骤,然后要求模型在新集合 {15, 13, 82, 7, 14} 上完成相同操作。这展示了如何通过 one-shot 提示来进行 chain-of-thought 提示。

已为您预加载 OpenAI 包和 get_response() 函数。

本练习是课程的一部分

使用 OpenAI API 的 Prompt Engineering

查看课程

练习说明

  • 定义一个 example,教模型如何在集合 {9, 10, 13, 4, 2} 上对偶数求和。
  • 定义一个与 example 类似的 question,让模型在新集合 {15, 13, 82, 7, 14} 上进行推理。
  • 创建最终的提示。

交互式实操练习

通过完成这段示例代码来试试这个练习。

client = OpenAI(api_key="")

# Define the example 
example = """Q: Sum the even numbers in the following set: ____.
             A: Even numbers: ____. Adding them: ____+____+____=____"""

# Define the question
question = """Q: ____ 
              A:"""

# Create the final prompt
prompt = ____
response = get_response(prompt)
print(response)
编辑并运行代码