開始使用免費開始

用於程式碼生成的輸入—輸出範例

你身為專案經理,需要估算完成不同專案所需的時間。你的任務是開發一個 Python 函式,能根據歷史資料預測專案的預估完成時間。系統提供了一組在 examples 字串中的範例,說明不同因素如何與專案完成時間相關。每個範例都包含各因素的數值,以及對應的預估完成時間。

OpenAI 套件與 get_response() 函式,以及 examples 字串都已為你預先載入。

本練習屬於課程

使用 OpenAI API 的提示工程

檢視課程

練習說明

  • 撰寫一個提示詞,要求模型根據提供的 examples 推斷將輸入對應到輸出的 Python 函式。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

client = OpenAI(api_key="")

examples="""input = [10, 5, 8] -> output = 23
input = [5, 2, 4] -> output = 11
input = [2, 1, 3] -> output = 6
input = [8, 4, 6] -> output = 18
"""

# Craft a prompt that asks the model for the function
prompt = ____

response = get_response(prompt)
print(response)
編輯並執行程式碼