Create your own ChatGPT with python -Md. Fatin Hasnat
xxxxxxxxxx
1# import openai library
import openai
# Set up the OpenAI API client
openai.api_key = "your secret api key"
# this loop will let us ask questions continuously and behave like ChatGPT
while True:
# Set up the model and prompt
model_engine = "text-davinci-003"
prompt = input('Enter new prompt: ')
if 'exit' in prompt or 'quit' in prompt:
break
# Generate a response
completion = openai.Completion.create(
engine=model_engine,
prompt=prompt,
max_tokens=1024,
n=1,
stop=None,
temperature=0.5,
)
# extracting useful part of response
response = completion.choices[0].text
# printing response
print(response)
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
Create your own ChatGPT with python -Md. Fatin Hasnat