原篇文章通过Hook方式收配微信,非web和谈无账号限制不封号。名目代码彻底开源,果为须要将步调注入微信,杀毒软件可能会误报,封锁便可,如若不安心,可以查察开源代码,源代码编译便可。开源名目地址如下:
快捷初步前置条件
拆置运用 pip install openai pip install wxchat打开微信客户端,弹出控制台音讯,则效劳启动乐成
效劳已启动, 端口号1: 10086, 端口号2: 10010
编写python代码,接管微信音讯,发送到chatgpt,并主动回复音讯。
import openai, re from wxchat import WeixinClient, MsgType, Message openai.api_key = "填入你的apikey" def get_response(text: str) -> [str]: response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": text}]) return [choice["message"]["content"] for choice in response["choices"]] if __name__ == '__main__': client = WeixinClient("192.168.0.104") profile = client.login() @client.message(wxid="wxid_.*", msgtype=MsgType.TEXT) def friend_message(message: Message): reply = get_response(message.content) for msg in reply: client.send_text(message.wxid, msg) @client.message(wxid=".*@chatroom", msgtype=MsgType.TEXT, at_users=[profile.wxid]) def chatroom_message(message: Message): content = re.sub(r"\s*@\S+?\s*(:| |$)", "", message.content) reply = get_response(content) for msg in reply: client.send_text(message.wxid, msg) client.run_forever()那样一个chatgpt呆板人就作好啦,很简略吧。你可以通过摰友向呆板人发送音讯,也可以正在群聊中艾特呆板人发送音讯,获与chatgpt回复。假如有问题,请查察B站教程视频