1

I have been trying to understand what is the suffix prompt in addition to the prefix prompt in Codex.

They have provided an example

def get_largest_prime_factor(n):
    if n < 2:
        return False
    def is_prime(n): >  for i in range(2, n): >  if n % i == 0: >  return False >  return True >     largest = 1
    for j in range(2, n + 1):
        if n % j == 0 and is_prime(j):
    return largest

From this example it is not clear to me how to create a suffix prompt?

What I understand is suffix prompt is for code insert model. My use case is also insert mode i.e., code needs to be updated in the middle of a code snippet.

Can anyone please provide a snippet showing how I can use the suffix prompt so that Codex works in the insert mode?

Rubén
  • 34,714
  • 9
  • 70
  • 166
Exploring
  • 2,493
  • 11
  • 56
  • 97

1 Answers1

-1

This python example worked for me.

import os
import openai

openai.api_key = os.getenv("OPENAI_API_KEY")

# Example per https://beta.openai.com/docs/guides/completion/inserting-text
prompt="I went to college at Boston University. After getting my degree, I decided to make a change. A big change!"
suffix="Now, I can’t get enough of the Pacific Ocean!"

# Use "suffix" parameter documented in
# https://beta.openai.com/docs/api-reference/completions/create#completions/create-suffix
response = openai.Completion.create(
            model="text-davinci-002",
            prompt=prompt,
            suffix=suffix,
            temperature=0.6
        )

# Print completion
print( response["choices"][0]["text"] )

# Typical output
# "I moved to California! I love the weather and all the new adventures it brings"
Qin AI
  • 1
  • Welcome to Stack Overflow. Code is a lot more helpful when it is accompanied by an explanation. Stack Overflow is about learning, not providing snippets to blindly copy and paste. Please [edit] your answer and explain how it answers the specific question being asked. See [answer]. – ChrisGPT was on strike Aug 14 '22 at 21:25