-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
37 lines (27 loc) · 910 Bytes
/
main.py
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
26
27
28
29
30
31
32
33
34
35
36
37
import openai
# Setting API key
# You can obtain your key via
# https://platform.openai.com/account/api-keys
openai.api_key = ""
# ChatGPT Context
context = {"role": "system",
"content": "Hello World!"}
messages = [context]
# Colors
GREEN = "\033[92m"
RESET = "\033[0m"
while True:
print(GREEN + ">> How can I help you?" + RESET + " (exit)")
content = input(": ")
# Ending the loop
if content == "exit":
exit("Bye")
# Append
messages.append({"role": "user", "content": content})
# Setting up the response
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages)
response_content = response.choices[0].message.content
# Append
messages.append({"role": "assistant", "content": response_content})
# Printing response
print(f"{GREEN}>> {response_content} \n")