窝牛号

OpenAI官方发布ChatGPT API接口gpt-3.5-turbo,python可直接调用

上期图文教程,我们介绍了ChatGPT的注册使用过程,并且介绍了GPT-3代API接口的开发代码实现过程,由于ChatGPT一直使用的是ChatGPT-3.5代接口,且我们在官网上面使用的也是ChatGPT-3.5代接口,大家对3.5代接口都十分认同,上期介绍的ChatGPT-3代API虽然可以实现问答对话,但是大家希望是否可以使用官方的接口来实现强大的ChatGPT功能。关于如何注册,如何获取API key,上期图文我们也进行了详细的分享。

本期,我们介绍一下openai刚刚公布的ChatGPT的API接口gpt-3.5-turbo。首先其gpt-3.5-turbo接口API是官方刚刚发布的gpt-3.5-turbo API接口,针对第三代接口进行了速度与精度方面的优化,其官方也是建议开发者使用gpt-3.5-turbo API接口,且价格是3代API 接口的十分之一的价格。我们首先介绍一下openai发布的gpt-3.5-turbo API如何使用requests库进行调用。

import requests 34;YOUR KEYS& The text prompt you want to generate a response input_prompt = input(&34;) prompt = input_prompt 39;s API url = &34; 34;Content-Type&34;application/json&34;Authorization&34;Bearer {api_key}&34;model&34;gpt-3.5-turbo&34;messages&34;role&34;user&34;content&34;max_tokens&34;temperature&34;frequency_penalty&34;presence_penalty& Make the API request response = requests.post(url, headers=headers, json=data) Extract the generated text from the response generated_text = response.json()[&39;][0][&39;][&39;] print(generated_text) else: 34;Request failed with status code 额{response.status_code}&34;https://api.openai.com/v1/chat/completions&34;role&34;system&34;content&34;You are a helpful assistant.&34;role&34;user&34;content&34;Who won the world series in 2020?&34;role&34;assistant&34;content&34;The Los Angeles Dodgers won the World Series in 2020.&34;role&34;user&34;content&34;Where was it played?&39;id&39;chatcmpl-6p9XYPYSTTRi0xEviKjjilqrWU2Ve&39;object&39;chat.completion&39;created&39;model&39;gpt-3.5-turbo&39;usage&39;prompt_tokens&39;completion_tokens&39;total_tokens&39;choices&39;message&39;role&39;assistant&39;content&39;The 2020 World Series was played in Arlington, Texas at the Globe Life Field, which was the new home stadium for the Texas Rangers.&39;finish_reason&39;stop&39;index&39;choices&39;message&39;content&39;sk-keys&39;Q:&39;quit&39;gpt-3.5-turbo&34;role&34;user&34;content&39;***********GPT-3.5 Open AI**************&39;choices&39;message&39;content&39;gpt-3.5-turbo&34;role&34;user&34;content":prompt}],

以上,便是我们介绍的ChatGPT 官方API接口gpt-3.5-turbo,当然openAI除了ChatGPT这样的NLP领域任务外,还有类似DALL-E的AI绘画模型,且官方开源的whisper,可以识别99种语音的识别系统,不仅可以语音转文字,还可以自动翻译等。

本站所发布的文字与图片素材为非商业目的改编或整理,版权归原作者所有,如侵权或涉及违法,请联系我们删除

窝牛号 wwww.93ysy.com   沪ICP备2021036305号-1