Spaces:
Runtime error
Runtime error
import openai | |
import os | |
from dotenv import load_dotenv | |
openai.api_key = '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' | |
message_history = [] | |
def chat(userInput, role = 'user'): | |
message_history.append({'role': role, 'content': userInput}) | |
completion = openai.ChatCompletion.create( | |
model = 'gpt-3.5-turbo', | |
messages = message_history | |
) | |
replContent = completion.choices[0].message.content | |
print(replContent) | |
message_history.append({'role': 'assistant', 'content': replContent }) | |
return replContent | |
for i in range(2): | |
userInput = input('> :') | |
print(userInput) | |
print() | |
chat(userInput) | |
print() | |