用户:锦廷查看:0 回复:4 评论:0 创建时间:2023-02-26T09:30:33
【作品展示】

【作品介绍】
新增记忆功能。
【作品源代码】
import openai
openai.api_key = 'sk-oZ7喵I4ryOdISYWerH9fT3BlbkFJ喵QMGalHEY6bxRfClmya'
def get_answer(history):
response=openai.Completion.create(
model='text-davinci-003',
prompt='\n'.join(history),
temperature=0.5,
max_tokens=2048)
return response.choices[0].text
def ask_nq():
f=True
history=[]
print()
aa ='\033[1; 31mChatGPT: I am a robot,I can answer yours question!if you want to quit input,please:quit\033[0m'
print(aa)
print()
while(f==True):
quesq=input()
if quesq!='quit':
history.append(quesq)
answer=get_answer(history)
answer=answer[2:]
print(f'\033[1;31mChatGPT: {answer}\033[0m')
print()
else:
f=False
print('\033[1;31mChatGPT:goodbye!\033[0m')
ask_nq()
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn