DS160123 New Code

Date:- 3/3/2023

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 ofresponse

response = completion.choice[0].text
#printing response
print(response)

3 Likes

@sms18680
Thank you for your valuable contribution.

3 Likes