开放AI GPT API:如何在中间完成(fill-in-the-middle)?

mkh04yzy  于 9个月前  发布在  其他
关注(0)|答案(1)|浏览(828)

在此公告中:https://openai.com/blog/gpt-3-edit-insert,一种插入模式,可以让你在文本中间完成。我如何通过Open AI GPT模型的完成API来完成它?
例如,在代码完成的情况下(Github Copilot目前正在做):

def say_hello():
    print('hi', name)

字符串
应在括号内使用name参数完成:

def say_hello(name):
    print('hi', name)

bf1o4zei

bf1o4zei1#

正如insertion instruction guide解释的那样,我们可以使用suffix参数来提供位于您想要插入新补全的位置之后的文本。

prompt = "def say_hello("
suffix = """):
  print('hi', name)"""

response = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt=prompt,
    suffix=suffix,
    max_tokens=32
)
print(response.choices[0].text) # should be 'name'

字符串

相关问题