猫史档案馆


【Python作品分享】chatGPTpython版【作品秀】

用户:锦廷锦廷查看:0 回复:0 评论:0 创建时间:2023-02-25T19:04:57


【作品展示】

center_image

 

【作品介绍】

chatGPT实现了!

 

【作品源代码】

import openai
openai.api_key = 'sk-oZ7喵I4ryOdISYWerH9fT3BlbkFJ喵QMGalHEY6bxRfClmya'
def get_answer(question):
    response=openai.Completion.create(
        model='text-davinci-003',
        prompt=question,
        temperature=0.5,
        max_tokens=2048)
    return response.choices[0].text

def ask_nq():
    f=True
    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':
            answer=get_answer(question=quesq)
            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 页 / 共 0下一页