togethercomputer / together-python

The Official Python Client for Together's API
https://pypi.org/project/together/
Apache License 2.0
19 stars 4 forks source link

Fill-in-the-middle completion using the `suffix` argument is missing #109

Open NightMachinery opened 2 months ago

NightMachinery commented 2 months ago

OpenAI's completion API has a suffix parameter that allows one to supply the context after the completion to enable fill-in-the-middle completions:

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

response = client.completions.create(
    model="text-davinci-003",
    prompt=prompt,
    suffix=suffix,
    max_tokens=10
)
# response.choices[0].text should be name

This is not supported by together API:

TypeError: Completions.create() got an unexpected keyword argument 'suffix'
orangetin commented 2 months ago

hi @NightMachinery , our API does not support suffix as a parameter. Can I ask how this is different from just passing in prompt = prompt + suffix ?

NightMachinery commented 2 months ago

@orangetin Some models support fill-in-the-middle (FIM, infilling). E.g.,

The OpenAI way of doing FIM is passing the "suffix" as a suffix parameter to the legacy completion endpoint.

NightMachinery commented 2 months ago

Basically, normal completions only see the context before the completion. FIM also shows the context after the completion. For auto-complete models (like what Github Copilot does), showing the context after is vital.

Just appending the after context to the original prompt does not work.

Here is an example for better understanding. Suppose we want to complete <COMPLETE_HERE>:

print("My name<COMPLETE_HERE>)
# Name: Armin Hajat
openai_text_complete(
    model="gpt-3.5-turbo-instruct",
    prompt=r"""
    print("My name
    """,
    suffix=")\n# Name: Armin Hajat",
    max_tokens=100,
    temperature=0,
    # stop=["\n"],
)
 is Armin Hajat"

which when inserted instead of <COMPLETE_HERE> would become:

print("My name is Armin Hajat")
# Name: Armin Hajat
orangetin commented 2 months ago

thanks for the info! we will add this to our feature list