-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.py
34 lines (26 loc) · 824 Bytes
/
index.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
#!/usr/bin/env python3
# Import modules
import openai
import os
from dotenv import load_dotenv
load_dotenv()
# Set up the OpenAI API client
openai.api_key = os.getenv('OPENAI_API_KEY')
# Set up the model and prompt
model_engine = "text-davinci-003"
# Set response until otherwise cancelled
prompt = input("🤖 How can I help you?\n")
while prompt.lower() not in ("no", "n", "no!", "you can't", "you cant", "nothing"):
# Generate a response
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
response = completion.choices[0].text
print(f'🤖 {response}')
prompt = input("🤖 What else can I help you with?\n")
print("🤖...")