import openai
# 본인이 발급받은 OpenAI API 키
openai.api_key = 'YOUR_OPENAI_API_KEY'
def chat_with_gpt3(prompt):
response = openai.Completion.create(
engine="davinci",
prompt=prompt,
max_tokens=150
)
return response.choices[0].text.strip()
if __name__ == "__main__":
while True:
user_input = input("You: ")
if user_input.lower() in ['quit', 'exit']:
break
response = chat_with_gpt3(f"You: {user_input}\nChatGPT: ")
print(f"ChatGPT: {response}")