到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
本文转载自: https://blog.csdn.net/qq_43535469/article/details/130304310
版权归原作者 彭同学她同桌 所有, 如有侵权,请联系我们删除。
版权归原作者 彭同学她同桌 所有, 如有侵权,请联系我们删除。