使用 LLM 生成代码片段
背景
此提示通过使用注释 /* <指令> */
向 LLM 提供程序细节,测试其代码生成能力,并要求它生成相应的代码片段。
提示
/*
Ask the user for their name and say "Hello"
*/
代码 / API
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "/*\nAsk the user for their name and say \"Hello\"\n*/"
}
],
temperature=1,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
参考
- 提示工程指南(在新标签页中打开) (2023 年 3 月 16 日)