-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
43 lines (33 loc) · 1.05 KB
/
app.py
File metadata and controls
43 lines (33 loc) · 1.05 KB
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
38
39
40
41
42
43
#single response chatbot using boltiot chatgpt api key
from boltiotai import openai
import os
import sys
print("Assistant: Hello! How can I assist you today?")
question=input("User: ")
while(True):
openai.api_key = os.environ['OPENAI_API_KEY']
if openai.api_key == "":
sys.stderr.write("""
You haven't set up your API key yet.
If you don't have an API key yet, visit:
https://platform.openai.com/signup
1. Make an account or sign in
2. Click "View API Keys" from the top right menu.
3. Click "Create new secret key"
Then, open the Secrets Tool and add OPENAI_API_KEY as a secret.
""")
exit(1)
response = openai.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{
"role": "system",
"content": "You are a helpful assistant."
}, {
"role": "user",
"content": question
}
]
)
output = response['choices'][0]['message']['content']
print("Assistant: ",output)
question=input("User: ")