-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (26 loc) · 979 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
import openai
api = "<API KEY HERE>"
openai.api_key = api
def main():
messages = [
{"role":"system","content":"You are a coding assistant. you will answer questions about programming an how to make, fix and debug stuff."},
{"role":"user","content":"please introduce yourself"}
]
while True:
print("AI thinking...")
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages
)
if 'choices' in response:
message = response["choices"][0]["message"]["content"]
messages.append({"role": "assistant", "content": message})
print(f"AI: {message}\n")
elif 'error' in response:
print("Error:", response['error']['message'])
else:
print("Unknown error occurred.")
i = input("YOU: ")
messages.append({"role": "user", "content": i})
if __name__ == "__main__":
main()