使用 OpenAI API 的 Prompt Engineering
Fouad Trad
Machine Learning Engineer


prompt = "Compose a travel blog"
print(get_response(prompt))
Title: 探索冰岛迷人风光
Introduction: 欢迎来到我的旅行博客!今天,我很高兴与您分享在冰岛迷人景色中的难忘旅程。
Day 1: 雷克雅未克——迷人的首都 [...]
Day 2: 黄金圈——大自然的奇观 [...]
Day 3: 南岸——冰与火之旅 [...]
Day 4: 冰河湖——冰封仙境 [...]
Day 5: 蓝湖——放松的收官 [...]
prompt = """Compose a travel blog as follows:
Step 1: Introduce the destination.
Step 2: Share personal adventures during the trip.
Step 3: Summarize the journey.
"""
print(get_response(prompt))
Title: 探索巴塞罗那迷人的街道Step 1: 介绍目的地。 欢迎来到巴塞罗那,这座充满活力的城市坐落于西班牙迷人的地中海海岸 [...]Step 2: 分享旅途中的个人经历。 漫步在哥特区狭窄曲折的街道上,我在每个转角都发现了隐藏的宝藏。 [...]Step 3: 总结行程。 当我的巴塞罗那之旅接近尾声时,我不禁为那些美妙的经历和回忆而心怀感激 [...]

待检验的典型解答
calculator = """
def add(a, b):
return a + b
def subtract(a, b):
return a - b
def multiply(a, b):
return a * b
def divide(a, b):
return a / b
"""
prompt = f"""Determine if the code delimited
by triple backticks is correct or not.
Answer by yes or no.
```{calculator}```"""
print(get_response(prompt))
Yes
prompt = f"""Determine the correctness of the code delimited by triple backticks
as follows:
Step 1: Check the code correctness in each function.
Step 2: Verify if the divide function handles the case when dividing by 0.
Code: ```{calculator}```"""
print(get_response(prompt))
该代码看起来是正确的。它定义了四个函数:add、subtract、multiply 和 divide。每个函数都执行相应的数学运算并返回结果。但它没有处理除以 0 的情况,这会导致 ZeroDivisionError。
步骤

步骤

样本(Shots)

使用 OpenAI API 的 Prompt Engineering