GithubHelp home page GithubHelp logo

lich0821 / wechatrobot Goto Github PK

View Code? Open in Web Editor NEW
944.0 17.0 206.0 13.19 MB

微信机器人,接入Gemini、ChatGPT、ChatGLM、讯飞星火、Tigerbot;成语接龙、天气预报、新闻摘要、定时任务。

License: MIT License

Python 100.00%
chatgpt python wechat chatglm gemini xunfei

wechatrobot's Introduction

WeChatRobot

一个基于 WeChatFerry 的微信机器人示例。

📖 文档 📺 视频教程 🙋 FAQ 🚨【微信机器人】沙雕行为合集
碲矿 赞赏
后台回复 WCF 加群交流 如果你觉得有用

Quick Start

  1. 遇到问题先看看上面的文档、教程和 FAQ。
    • 按照步骤来,版本保持一致,少走弯路。
    • 按照步骤来,版本保持一致,少走弯路。
    • 按照步骤来,版本保持一致,少走弯路。
  2. 安装 Python>=3.9(Python 12 需要自己编译依赖,慎选),例如 3.10.11
  3. 安装微信 3.9.2.23,下载地址在 这里;也可以从 WeChatSetup 找到。
  4. 克隆项目
git clone https://github.com/lich0821/WeChatRobot.git

# 如果网络原因打不开,可以科学上网,或者使用gitee
git clone https://gitee.com/lch0821/WeChatRobot.git

如果觉得克隆复杂,也可以直接下载 最新版 到本地解压。

  1. 安装依赖
# 升级 pip
python -m pip install -U pip
# 安装必要依赖
pip install -r requirements.txt
# ChatGLM 还需要安装一个 kernel
ipython kernel install --name chatglm3 --user
  1. 运行

我们需要运行两次 main.py 第一次是生成配置文件 config.yaml, 第二次是真正跑你的机器人。 直接运行程序会自动拉起微信,如果微信未打开,会自动打开微信;如果版本不对,也会有提示;其他报错,请进群交流。

下面代码为第一次运行:第一次运行 main.py 会在 WeChatRobot 目录下生成一个 config.yaml 文件,参照修改配置进行修改。

其中 chatgpt、tigerbot、chatglm 和 xinghuo_web 是四种模型的配置信息,你需要配置它们的参数,不知道的可以加群交流。

python main.py

# 需要停止按 Ctrl+C

启动之后,可以正常接收消息但不会响应群消息。参考下方 修改配置 进行配置,以便响应特定群聊。

下面代码为第二次运行:你可以通过命令行参数选择模型,默认是不选择,这样你配置了什么参数就跑什么模型。正因如此你需要配置前面所说四种模型中的至少一种(当然也可以都配置,想跑那个模型就选什么参数), 然后就可以开始使用你的机器人了。

python main.py

# 需要停止按 Ctrl+C

如果你配置了多个模型(不需要将其他配置注释或者移除),下面的内容才对你有帮助否则略过,通过 python main.py -h 通过参数可以选择要跑的模型。

# 查看帮助
python main.py -h
#optional arguments:
#  -h, --help            show this help message and exit
#  -c C, --chat_model C  选择要使用的AI模型,默认不选择,可选参数:1. tigerbot 模型 2. chatgpt 模型 3. 讯飞星火模型 4. chatglm 模型
# 例: 我想运行选择chatgpt的机器人
python main.py -c 2

# 需要停止按 Ctrl+C

python main.py -c C 其中参数 C 可选择如下所示

  1. tigerbot 模型
  2. chatgpt 模型
  3. 讯飞星火模型
  4. chatglm 模型
  1. 停止

不要那么粗暴,温柔点儿;

不要直接关闭窗口,温柔点儿。

输入:Ctrl+C。否则,会出现各种奇怪问题。

修改配置

ℹ️ 修改配置后,需要重新启动,以便让配置生效。

配置文件 config.yaml 是运行程序后自动从模板复制过来的,功能默认关闭。

响应被 @ 消息

为了响应群聊消息,需要添加相应的 roomId

第一次运行的时候,可以在手机上往需要响应的群里发消息,打印的消息中方括号里的就是;多个群用 , 分隔。

groups:
  enable: [] # 允许响应的群 roomId,大概长这样:2xxxxxxxxx3@chatroom, 多个群用 `,` 分隔

配置 AI 模型

为了使用 AI 模型,需要对相应模型并进行配置。

使用 ChatGLM 见注意事项 README.MD

chatgpt:  # -----chatgpt配置这行不填-----
  key:  # 填写你 ChatGPT 的 key
  api: https://api.openai.com/v1  # 如果你不知道这是干嘛的,就不要改
  proxy:  # 如果你在国内,你可能需要魔法,大概长这样:http://域名或者IP地址:端口号
  prompt: 你是智能聊天机器人,你叫 wcferry  # 根据需要对角色进行设定

chatglm:  # -----chatglm配置这行不填-----
  key: sk-012345678901234567890123456789012345678901234567 # 这个应该不用动
  api: http://localhost:8000/v1  # 根据自己的chatglm地址修改
  proxy:  # 如果你在国内,你可能需要魔法,大概长这样:http://域名或者IP地址:端口号
  prompt: 你是智能聊天机器人,你叫小薇  # 根据需要对角色进行设定
  file_path: C:/Pictures/temp  #设定生成图片和代码使用的文件夹路径

tigerbot:  # -----tigerbot配置这行不填-----
  key:  # key
  model:  # tigerbot-7b-sft

# 抓取方式详见文档:https://www.bilibili.com/read/cv27066577
xinghuo_web:  # -----讯飞星火web模式api配置这行不填-----
  cookie:  # cookie
  fd:  # fd
  GtToken:  # GtToken
  prompt: 你是智能聊天机器人,你叫 wcferry。请用这个角色回答我的问题  # 根据需要对角色进行设定

bard: # -----bard配置这行不填-----
  api_key: # api-key 创建地址:https://ai.google.dev/pricing,创建后复制过来即可
  model_name: gemini-pro # 新模型上线后可以选择模型
  proxy: http://127.0.0.1:7890  # 如果你在国内,你可能需要魔法,大概长这样:http://域名或者IP地址:端口号
  # 提示词尽可能用英文,bard对中文提示词的效果不是很理想,下方提示词为英语老师的示例,请按实际需要修改,默认设置的提示词为谷歌创造的AI大语言模型
  # I want you to act as a spoken English teacher and improver. I will speak to you in English and you will reply to me in English to practice my spoken English. I want you to keep your reply neat, limiting the reply to 100 words. I want you to strictly correct my grammar mistakes, typos, and factual errors. I want you to ask me a question in your reply. Now let's start practicing, you could ask me a question first. Remember, I want you to strictly correct my grammar mistakes, typos, and factual errors.
  prompt: You am a large language model, trained by Google.

HTTP

如需要使用 HTTP 接口,请参考:

wechatrobot's People

Contributors

aki66938 avatar jnchen avatar leesonchen avatar lich0821 avatar mr-mihu avatar n0nes avatar noobhumiliator avatar touero avatar yanlang0123 avatar yudong521 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

wechatrobot's Issues

[🐛BUG] go版本调用/ai ,程序报错闪退

描述这个 bug
对 bug 作一个清晰简明的描述:

  • 想做什么?
    接入ai聊天到微信群
  • 现在怎么做?
  • 遇到什么问题?

使用环境(请补全下列信息):

  • 操作系统:win11
  • 操作系统版本:【 64 位】

屏幕截图
c2b9bc0af7589b2e779a77559f3ee3d

能拿到微信客户端的二维码图片吗

感谢作者提供如此优秀的工具,请问能拿到微信客户端的二维码图片吗,还有能解密OpenIMContact.db吗,企业微信来的消息或人员获取还有点问题

[优化] 优化下 /text 接口,谢谢

描述这个 bug

对 bug 作一个清晰简明的描述:

  • 想做什么?
    调用 wcfhttp 里面发送文本消息的 /text 接口。

  • 现在怎么做?
    这是我的数据格式
    {
    "msg": "689789 @",
    "receiver": "xxxxx@chatroom",
    "aters": "xxx1111"
    }

  • 遇到什么问题?
    我上面返回的数据是 689789 @,我希望变成 689789 @张三
    希望优化下 msg 发送的格式,你 py 里面 sendTextMsg 已经查询过群成员昵称了,是不是可以直接帮我拼接到 msg 里面,不然我还要自己再查询一次群成员昵称,拼接在 msg 后面,然后再调用 /text 接口

使用环境(请补全下列信息):

  • 操作系统:Windows Server 2008 64 位
  • 微信版本:3.9.2.23
  • Python 版本:3.10.11

[💡SUG] 发送视频时,添加变量控制是否勾选原画

你希望添加的功能是否与某个问题相关?
当 [我接收到机器人发送的视频] 时,点开视频总是压缩画质,需要点击“查看原视频”,很不方便。

描述你希望的解决方案
单独设置变量控制是否勾选原画,或者不切实际一点,直接发送原画,但接收方不显示“查看原视频”(将原画视频替换掉压缩视频后发送?)

描述你考虑的替代方案
直接发送压缩后的视频,即不勾选原画。

其他

如何指定ChatGPT的Model?

例如我希望使用3.5-turbo-16k,或者gpt4的接口,但是默认他调用的模型太老了,数据仅停留在2020年

[🐛BUG] 用一句话描述您的问题。

使用环境(请补全下列信息):

  • 操作系统:【Windows Server 2008 】
  • 操作系统版本:【 64 位】
  • Python 版本 【3.10】

描述这个 bug
google gemini的API接口调用失败

  • 访问python sdk遇到问题

Traceback (most recent call last):
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 79, in error_remapped_callable
return callable_(*args, **kwargs)
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\grpc_channel.py", line 1160, in call
return _end_unary_response_blocking(state, call, False, None)
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\grpc_channel.py", line 1003, in _end_unary_response_blocking
raise _InactiveRpcError(state) # pytype: disable=not-instantiable
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.160.106:443: socket is null"
debug_error_string = "UNKNOWN:Error received from peer {created_time:"2023-12-16T00:55:14.7024441+00:00", grpc_status:14, grpc_message:"failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.160.106:443: socket is null"}"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\retry.py", line 207, in retry_target
result = target()
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\grpc_helpers.py", line 81, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.ServiceUnavailable: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.160.106:443: socket is null

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "D:\Python\wechat\new\WeChatRobot\test_gemini.py", line 9, in
response = model.generate_content("The opposite of hot is")
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\generativeai\generative_models.py", line 243, in generate_content
response = self._client.generate_content(request)
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\ai\generativelanguage_v1beta\services\generative_service\client.py", line 566, in generate_content
response = rpc(
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\gapic_v1\method.py", line 131, in call
return wrapped_func(*args, **kwargs)
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\retry.py", line 372, in retry_wrapped_func
return retry_target(
File "D:\Python\wechat\new\WeChatRobot\venv\lib\site-packages\google\api_core\retry.py", line 226, in retry_target
raise exceptions.RetryError(
google.api_core.exceptions.RetryError: Deadline of 60.0s exceeded while calling target function, last exception: 503 failed to connect to all addresses; last error: UNKNOWN: ipv4:172.217.160.106:443: socket is null

[🐛BUG] 群里拷贝@消息修改后发送,msg.is_at(self.wxid)接口识别为非群@消息。

描述这个 bug
对 bug 作一个清晰简明的描述。
群里直接拷贝@消息后发送,processMsg函数中调用msg.is_at(self.wxid)接口识别为非群@消息。
使用环境(请补全下列信息):

  • 操作系统:【如 Windows 7, Windows 10, Windows Server 2008 等】
  • 操作系统版本:[32 位 或 64 位】
  • Python 版本 【如 3.7.9 32位, 3.8.15 64位 等】

屏幕截图
添加屏幕截图以帮助解释您的问题。(可选)

崩溃信息
微信崩溃原因描述文件内容。(可选)

[🐛BUG] 用一句话描述您的问题。

描述这个 bug
对 bug 作一个清晰简明的描述。

使用环境(请补全下列信息):

  • 操作系统:【如 Windows 7, Windows 10, Windows Server 2008 等】
  • 操作系统版本:[32 位 或 64 位】
  • Python 版本 【如 3.7.9 32位, 3.8.15 64位 等】

屏幕截图
添加屏幕截图以帮助解释您的问题。(可选)

崩溃信息
微信崩溃原因描述文件内容。(可选)

想进群学习,老兄。

[🐛BUG] 配置 bard 响应超时。

配置 bard 之后, 报超时error, 已开启vpn, 网页端 Gemini 可用

使用环境(请补全下列信息):

  • 操作系统:Windows 11 22621.3155
  • 操作系统版本:【64 位】
  • Python 版本 【Python 3.12.1 64 位 】

屏幕截图

image
image

请问有工作日定时提醒发送消息的功能吗?

工作日定时发送自定义消息的功能。
还有请问下,为什么天气预报功能不能正常使用(时间不对),是因为我接入的是chatgpt3.5吗? 如果要正常使用是不是需要接入chatgpt4.0?

chatglm3 代码模式生成了爱心图片,但不能发送到微信

chatglm3代码模式,生成了爱心,但结果图片没有发送到微信,只提示:这就是一个爱心形状的图形。希望你会喜欢!如果你有其他要求或需要进一步的调整,请告诉我。

这是为什么?我看了目录也生成了照片,就是没有回复到微信中。

请大神指点。

[🐛BUG] win10上运行时微信崩溃退出

描述这个 bug
微信3.7.0.30,登录后,执行python main.py,微信崩溃退出。试过几次都是崩溃。

使用环境(请补全下列信息):

  • Windows 10 64位 专业版 22H2 19045.2604
  • Python 10.10 64位

崩溃信息
请见附件

*另外,在win11上第一次运行崩溃退出,再次运行却可以了。以下是win10出错时系统自动给出的log文件

WeChat9cef1c2.zip

[🐛BUG] 运行一段时间后,不接收消息了

描述这个 bug
对 bug 作一个清晰简明的描述:

  • 想一直运行,根据接收到的消息 自动回复消息
  • 运行一段时间后,不接受消息了

使用环境(请补全下列信息):

  • 操作系统:windows server 2022 datacenter (阿里的云电脑)
  • 操作系统版本:64 位
  • Python 版本: 3.11.0

屏幕截图
image

运行一段时候后,不打印这个日志了

    def enableReceivingMsg(self) -> None:
        def innerProcessMsg(wcf: Wcf):
            while wcf.is_receiving_msg():
                now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                print(f"{now_time}【等待消息】************************")
                try:
                    msg = wcf.get_msg()
                    if msg.roomid and msg.roomid not in self.config.GROUPS:
                        self.all_room.update({msg.roomid: "未知"})
                        with open("room/all_room.json", "w") as f:
                            f.write(json.dumps(self.all_room))
                        return
                    self.LOG.info(f"msg:roomid: {msg.roomid}, sender: {msg.sender}, content: {msg.content}")

                    flag = self.baseFunc.manage_command(msg, self)  # 首先执行管理指令
                    self.LOG.info(f"【管理指令】是否是管理执行指令 {flag}")
                    if not flag:
                        self.processMsg(msg)
                    # self.processMsg(msg)
                except Empty:
                    now_time = str(datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
                    print(f"{now_time}【空消息】!!!!!!!!!!!!!! ")
                    continue  # Empty message
                except Exception as e:
                    traceback.print_exc()
                    self.LOG.error(f"Receiving message error: {e}")

        self.wcf.enable_receiving_msg()
        Thread(target=innerProcessMsg, name="GetMessage", args=(self.wcf,), daemon=True).start()

最开始就发现这个问题,然后在群里也有其他人遇到,群友他自己 print 打印日志后就咩有这个问题,但是我依旧存在这个问题

然后我就想看看运行的多线程情况,如下图

image

图上半截是正常运行的,下半截是不接受消息时的,线程丢失了

[💡SUG] 提允许通过配置特定的wxid来自动屏蔽或忽视来自这些wxid的对话请求,以减少不必要的干扰。

问题背景: 在管理用户请求的系统中,某些用户可能因为各种原因需要被临时或永久屏蔽对话请求。比如,滥用服务、发送垃圾信息等行为。目前,系统缺乏直接通过用户的微信ID来快速屏蔽对话请求的功能。

期望的解决方案: 实现一个功能,让管理员或系统维护者能通过添加用户的微信ID到一个黑名单中,来自动屏蔽或忽略这些用户的对话请求。这个功能应该包括:

一个界面或命令行工具,用于输入需要屏蔽的用户wxid。
一个黑名单数据库或列表,存储被屏蔽用户的wxid。
一个逻辑判断机制,在接收到用户请求时检查其wxid是否在黑名单中。
如果用户的wxid在黑名单中,则自动忽略或拒绝其对话请求,可能伴随一条通知消息告知用户。
考虑的替代方案:

基于用户行为的自动屏蔽: 系统根据用户的行为自动判断是否需要屏蔽,如发送消息频率、内容质量等指标。
举报机制: 允许其他用户举报不当行为,当举报达到一定数量时自动触发屏蔽逻辑。
时间限制屏蔽: 不是永久屏蔽用户wxid,而是给予一定时间的禁言或屏蔽,过后自动解除。

运行python main.py时提示连接失败

描述这个 bug
对 bug 作一个清晰简明的描述:运行python main.py时提示连接失败

  • 想做什么?
  • 现在怎么做?
  • 遇到什么问题?
    微信版本:
    3.9.2.23
    wcf.txt
    [2024-05-29 14:15:00.744] [debug] [WCF] [log.cpp::33::InitLogger] InitLogger with debug level
    [2024-05-29 14:15:00.745] [error] [WCF] [spy.cpp::27::InitSpy] 获取微信版本失败

python main.py
2024-05-29 14:14:58 wcferry version: 39.0.14.1
2024-05-29 14:15:02 连接失败: Connection refused

使用环境(请补全下列信息):

  • 操作系统:【Windows 10】
  • 操作系统版本:【64 位】
  • Python 版本 【3.11 64位】

屏幕截图
添加屏幕截图以帮助解释您的问题。(可选)

[🐛BUG] 被微信封号的概率有多高

描述这个 bug
对 bug 作一个清晰简明的描述。

使用环境(请补全下列信息):

  • 操作系统:【如 Windows 7, Windows 10, Windows Server 2008 等】
  • 操作系统版本:[32 位 或 64 位】
  • Python 版本 【如 3.7.9 32位, 3.8.15 64位 等】

屏幕截图
添加屏幕截图以帮助解释您的问题。(可选)

崩溃信息
微信崩溃原因描述文件内容。(可选)

[🐛BUG] Google Gemini模型没有正确识别提示词来运行

描述这个 bug
对 bug 作一个清晰简明的描述:
这个bug来自于Google Gemini模型,它并没有正确的识别到提示词,它认为“我是 Gemini,是 Google 开发的多模态 AI 语言模型。”
我在提示词的地方正确设置了,可是它似乎没有正确的生效?
具体可以查看屏幕截图
如果需要作者可以联系我[email protected]

使用环境(请补全下列信息):

  • 操作系统:Windows Server 2012R2【如 Windows 7, Windows 10, Windows Server 2008 等】
  • 操作系统版本:64 位【32 位或 64 位】
  • Python 版本:3.10.11【如 3.7.9 32 位,3.8.15 64 位 等】

屏幕截图
添加屏幕截图以帮助解释您的问题。(可选)
image
image
image

在ubuntu环境下运行出现错误

Linux环境1 wsl ubuntu 22.04
Linux环境2 ubuntu 22.04 物理机
python版本 3.10.6

windows环境 windows11
python版本 3.10.7

Win环境下运行正常

Linux环境下报错:

3d6193f1fdf811d8e2ee4a63adc092b

经测试,在WSL和物理机Linux 下报一样的错误,WIN下正常

关于chatgpt

如果我想接入chatgpt,该如何去抓取我账号里的那些参数
可不可以直接用本地的电脑开启v2使用国外的代理,然后不填proxy的参数啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.