File size: 662 Bytes
f90c66a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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()