跳到主要内容

使用LLM生成代码片段

背景

此提示通过使用/* <instruction> */注释提示LLM生成相应代码片段来测试LLM的代码生成能力。

提示

/*
询问用户的姓名并说“你好”
*/

代码/API

from openai import OpenAI
client = OpenAI()

response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": "/*\n询问用户的姓名并说\"你好\"\n*/"
}
],
temperature=1,
max_tokens=1000,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)

Reference