0.完成效果
1.准备材料
a.pysimplegui 推荐学习可以看这个视频python图形界面开发教程:第四课:使用PySimpleGUI如何设定模板主题_哔哩哔哩_bilibili
b.openaikey 需要外国号码注册SMS-Activate是在线接受短信的虚拟号码服务,充值后个人推荐选择菲律宾接受验证码,美国的真机被限制,印尼特别慢。注意号码区号
c.梯子个人使用神灯(有没有便宜的推荐啊..sad)
2.打包成exe
对了那个openai的key需要拷贝到电脑的环境变量,(openai网页/developer/Api key)
附上代码
import os import openai def getresponse(input): messages = [] messages.append({"role": "user", "content": input},) chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=messages) return chat_completion.choices[0].message.content Messageall="" MessageRebot="ChatGPT( ̄_ ̄)\n" MessageUser="ZHEKUN( ´ ▽ `)\n" import PySimpleGUI as sg layout=[[sg.ML(default_text="", border_width=0, reroute_cprint=True, do_not_clear=False, size=(70,16))], [sg.I(tooltip="输入内容",key="sendinfo",size=(58,20),focus=True),sg.B("发送",key="send",size=(10))]] window=sg.Window("ChatPPT",layout,icon="res\icon2.ico") while True: event,values=window.read() if event==None: break if event=="send": Messagesend = MessageUser+values["sendinfo"]+"\n" Messagerecive= MessageRebot+"\n" Messagerecive= MessageRebot+getresponse(values["sendinfo"])+"\n" Messageall=Messageall+Messagesend+Messagerecive sg.cprint(Messageall) window["sendinfo"].update("") window.close() #cmd>> python -m pip install pysimplegui-exemaker #cmd>> python -m pysimplegui-exemaker.pysimplegui-exemaker
标签:代码,30,Messageall,window,pysimplegui,sendinfo,key,chatgpt,sg From: https://www.cnblogs.com/zhangzhekun/p/17301031.html