python调用chatGPT接口
chatGPT调用接口实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #!/usr/bin/python3 # -*- coding: utf-8 -*- #chatGPT Python3版 import openai import os,json openai.api_key = "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" #api while True : prompt = input ( "\n问:" ) if prompt in [ "exit" , "EXIT" , "退出" ]: break else : # Generate a response response = openai.Completion.create( engine = "text-davinci-003" , prompt = prompt, max_tokens = 1024 , # n=1, # stop=None, temperature = 0.5 , top_p = 1.0 , frequency_penalty = 0.0 , presence_penalty = 0.0 , ) print ( "答:" , response.choices[ 0 ].text.strip()) |
2023年3月2日, OpenAI推出了基于“gpt-3.5-turbo”模型的全新API,其基础是支持ChatGPT的GPT 3.5模型,取代了此前的“text-davinci-003.”。新版接口文章见 使用Python调用新版ChatGPT接口
本文来自博客园,作者:方倍工作室,转载请注明原文链接:https://www.cnblogs.com/txw1958/p/17163238.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
2013-02-28 微信公众平台消息接口开发(23)图片识别之男人味/女人味指数