使用 f-string 的分隔提示
你是一家充滿活力的新創公司的初階開發者,該公司利用 AI 來產生內容。公司相信這項技術能徹底改變說故事的方式,而你也很期待參與其中。今天,你的任務是使用 f-string 與分隔提示,為一篇故事產生續寫內容。
OpenAI 套件、get_response() 函式,以及變數 story 都已為你預先載入。
本練習屬於課程
使用 OpenAI API 的提示工程
練習說明
- 建立一個提示,要求補完變數
story(以字串形式提供給你):使用 f-string,並以三個反引號(```)將story分隔,將其內容傳入提示。 - 取得產生的回覆。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
client = OpenAI(api_key="")
# Create a prompt that completes the story
prompt = ____
# Get the generated response
response = ____
print("\n Original story: \n", story)
print("\n Generated story: \n", response)