chatGPT-如何解决拒绝访问的问题

到ChatGPT官网 登录
请添加图片描述
请添加图片描述

请添加图片描述
保存这个key
然后去google搜索colab
请添加图片描述

请添加图片描述

pip install openai
import openai

API_KEY = '你的OpenAIkey'    
openai.api_key = API_KEY
model_id = 'gpt-3.5-turbo'

def ChatGPT_conversation(conversation):
    response = openai.ChatCompletion.create(
        model=model_id,
        messages=conversation
    )
    # api_usage = response['usage']
    # print('Total token consumed: {0}'.format(api_usage['total_tokens']))
    # stop means complete
    # print(response['choices'][0].finish_reason)
    # print(response['choices'][0].index)
    conversation.append({'role': response.choices[0].message.role, 'content': response.choices[0].message.content})
    return conversation

conversation = []
conversation.append({'role': 'system', 'content': 'How may I help you?'})
conversation = ChatGPT_conversation(conversation)
print('{0}: {1}\n'.format(conversation[-1]['role'].strip(), conversation[-1]['content'].strip()))

while True:
    prompt = input('User:')
    conversation.append({'role': 'user', 'content': prompt})
    conversation = ChatGPT_conversation(conversation)
    print('{0}: {1}\n'.format(conversation[-1]['role'].strip(), conversation[-1]['content'].strip()))

直接使用chatBox

gitHub-chatBox

猜你喜欢

转载自blog.csdn.net/qq_43535469/article/details/130304310
今日推荐