Generate Code Snippet

使用LLMs生成代码片段

背景

此提示通过使用/* */在注释中提供程序的详细信息,测试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
)

参考