打造具體且精準的提示詞
在上一個練習中,你已經產生了能補完給定 story 的文字。團隊對成果很滿意,不過他們希望你能遵守特定的長度與風格準則。你現在的任務是撰寫更具體的提示詞,來控制產生故事的這些面向。
OpenAI 套件、get_response() 函式,以及相同的 story 變數都已經為你載入。
本練習屬於課程
使用 OpenAI API 的提示工程
練習說明
- 撰寫一個提示詞:以 僅兩段 的長度,並以 Shakespeare 的風格,來補完給定的
story;請使用 f-string,並以三個反引號(```)界定story。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Create a request to complete the story
prompt = ____
# Get the generated response
response = ____
print("\n Original story: \n", story)
print("\n Generated story: \n", response)