开始使用免费开始使用

用于代码生成的输入-输出示例

您是一名项目经理,需要估算完成不同项目所需的时间。您的任务是开发一个 Python 函数,基于历史数据预测项目的预计完成时间。系统为您提供了一个名为 examples 的字符串,其中包含多个示例,展示了不同因素与项目完成时间之间的关系。每个示例都给出了这些因素的数值以及相应的预计完成时间。

OpenAI 包、get_response() 函数以及 examples 字符串均已为您预加载。

本练习是课程的一部分

使用 OpenAI API 的 Prompt Engineering

查看课程

练习说明

  • 设计一个提示词,要求模型根据提供的 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)
编辑并运行代码