Skip to content

Instantly share code, notes, and snippets.

@trecno
Created November 20, 2021 19:23
Show Gist options
  • Save trecno/b7c61f1cb65d6c294428f9a2a69a5ba3 to your computer and use it in GitHub Desktop.
Save trecno/b7c61f1cb65d6c294428f9a2a69a5ba3 to your computer and use it in GitHub Desktop.
import openai
openai.api_key = "API-KEY"
conversation = "Human: Hello, who are you?\nAI: I am an AI created by OpenAI. How can I help you today?"
print(conversation)
i = 1
while (i != 0):
question = input("Human: ")
conversation += "\nHuman:" + question + "\nAI:"
response = openai.Completion.create(
engine = "davinci",
prompt = conversation,
temperature = 0.9,
max_tokens = 150,
top_p = 1,
frequency_penalty = 0,
presence_penalty = 0.6,
stop = ["\n", " Human:", " AI:"]
)
answer = response.choices[0].text.strip()
conversation += answer
print("AI: " + answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment