-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (26 loc) · 831 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
import os
from decouple import config
import openai
openai.api_key = config("OPENAI_API_KEY")
messages = [
{"role": "system", "content": "You are an intelligent assistance"}
]
while True:
try:
user_query = input("User : ")
if user_query:
messages.append(
{"role": "user", "content": user_query},
)
chat_response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
reply = chat_response.choices[0].message.content
print(f"ChatGPT Response => {reply}")
messages.append(
{"role": "assistant", "content": reply}
)
except Exception as err:
print("An error occurred with error message => ", err)
exit('AI is stopping now...')