openAIchatGPTapi调用方法
1。申请key
可以在openai官网申请
2。安装openaiAPK我是使用的pythonpipinstallopenai
3。调用apiimportopenaiopenai。apikeyskxxx分三种角色system、assistant、usersystem的作用是设定助手的行为,可以填入chatgptpromptsuser是最终的用户输入assistant是当chatGPT忘记了上下文,就可以用来存储先前的响应,给chatGPT提供所需的行为实例responseopenai。ChatCompletion。create(modelgpt3。5turbo,messages〔{role:user,content:怎么申请visa信用卡}〕)print(response〔choices〕〔0〕〔message〕〔content〕)响应的格式{id:chatcmpl6p9XYPYSTTRi0xEviKjjilqrWU2Ve,object:chat。completion,created:1677649420,model:gpt3。5turbo,usage:{prompttokens:56,completiontokens:31,totaltokens:87},choices:〔{message:{role:assistant,content:The2020WorldSerieswasplayedinArlington,TexasattheGlobeLifeField,whichwasthenewhomestadiumfortheTexasRangers。},finishreason:stop,index:0}〕}
4。api调用计费情况
刚开始会有免费试用阶段到6月1号
申请成为付费用户,需要添加信用卡
差不多7。5万字2美元,价格还可以