一、代码部分
import itchat
import openai
from itchat.content import TEXT
openai.api_key = "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"
def askbot(question,who):
completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": question}] )
a = completion.choices[0].message.content
b = who
return completion.choices[0].message.content
@itchat.msg_register(TEXT) # 注册处理文本信息
def wxreply(msg):
itchat.send(askbot(msg.text,msg.User.NickName), toUserName=msg.FromUserName)
itchat.login(enableCmdQR=2)
itchat.run()
效果如下
二.itchat相关依赖。解压至lib路径即可使用
三.项目要在美国或其他服务器内运行
这里推荐这个。链接:衡天云