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 的提示工程
練習說明
- 定義一個
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)