猫史档案馆


【Python作品分享】chatGPTpython2.0【作品秀】

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


【作品展示】

center_image

 

【作品介绍】

新增记忆功能。

 

【作品源代码】

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


回复

上一页1 页 / 共 1下一页
ZetaOidZetaOid

 

点赞0


评论


mornwindmornwind

直接把账号发出来是吧()

点赞0


评论


月光之树月光之树

你这api key怎么有一个喵

点赞0


评论


月光之树月光之树

这api该不会中间的哪个喵是 sb

点赞1


评论