Skip to content

Commit d347905

Browse files
authored
Merge pull request #1 from zhayujie/master
merge 15 commits
2 parents 3effd5a + f495213 commit d347905

File tree

10 files changed

+54
-17
lines changed

10 files changed

+54
-17
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ DEMO视频:https://cdn.link-ai.tech/doc/cow_demo.mp4
4646

4747
# 🏷 更新日志
4848

49+
>**2024.08.02:** [1.7.0版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.9) 新增 讯飞4.0 模型、知识库引用来源展示、相关插件优化
50+
4951
>**2024.07.19:** [1.6.9版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.9) 新增 gpt-4o-mini 模型、阿里语音识别、企微应用渠道路由优化
5052
5153
>**2024.07.05:** [1.6.8版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.8)[1.6.7版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.7),Claude3.5, Gemini 1.5 Pro, MiniMax模型、工作流图片输入、模型列表完善

bot/xunfei/xunfei_spark_bot.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ def __init__(self):
4141
self.api_key = conf().get("xunfei_api_key")
4242
self.api_secret = conf().get("xunfei_api_secret")
4343
# 默认使用v2.0版本: "generalv2"
44-
# v1.5版本为 "general"
45-
# v3.0版本为: "generalv3"
46-
self.domain = "generalv3"
47-
# 默认使用v2.0版本: "ws://spark-api.xf-yun.com/v2.1/chat"
48-
# v1.5版本为: "ws://spark-api.xf-yun.com/v1.1/chat"
49-
# v3.0版本为: "ws://spark-api.xf-yun.com/v3.1/chat"
50-
# v3.5版本为: "wss://spark-api.xf-yun.com/v3.5/chat"
51-
self.spark_url = "wss://spark-api.xf-yun.com/v3.5/chat"
44+
# Spark Lite请求地址(spark_url): wss://spark-api.xf-yun.com/v1.1/chat, 对应的domain参数为: "general"
45+
# Spark V2.0请求地址(spark_url): wss://spark-api.xf-yun.com/v2.1/chat, 对应的domain参数为: "generalv2"
46+
# Spark Pro 请求地址(spark_url): wss://spark-api.xf-yun.com/v3.1/chat, 对应的domain参数为: "generalv3"
47+
# Spark Pro-128K请求地址(spark_url): wss://spark-api.xf-yun.com/chat/pro-128k, 对应的domain参数为: "pro-128k"
48+
# Spark Max 请求地址(spark_url): wss://spark-api.xf-yun.com/v3.5/chat, 对应的domain参数为: "generalv3.5"
49+
# Spark4.0 Ultra 请求地址(spark_url): wss://spark-api.xf-yun.com/v4.0/chat, 对应的domain参数为: "4.0Ultra"
50+
# 后续模型更新,对应的参数可以参考官网文档获取:https://www.xfyun.cn/doc/spark/Web.html
51+
self.domain = conf().get("xunfei_domain", "generalv3.5")
52+
self.spark_url = conf().get("xunfei_spark_url", "wss://spark-api.xf-yun.com/v3.5/chat")
5253
self.host = urlparse(self.spark_url).netloc
5354
self.path = urlparse(self.spark_url).path
5455
# 和wenxin使用相同的session机制

channel/dingtalk/dingtalk_channel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def __init__(self):
100100
super(dingtalk_stream.ChatbotHandler, self).__init__()
101101
self.logger = self.setup_logger()
102102
# 历史消息id暂存,用于幂等控制
103-
self.receivedMsgs = ExpiredDict(conf().get("expires_in_seconds"))
103+
self.receivedMsgs = ExpiredDict(conf().get("expires_in_seconds", 3600))
104104
logger.info("[DingTalk] client_id={}, client_secret={} ".format(
105105
self.dingtalk_client_id, self.dingtalk_client_secret))
106106
# 无需群校验和前缀

channel/wechat/wechat_channel.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import os
1010
import threading
1111
import time
12-
1312
import requests
1413

1514
from bridge.context import *
@@ -21,6 +20,7 @@
2120
from common.log import logger
2221
from common.singleton import singleton
2322
from common.time_check import time_checker
23+
from common.utils import convert_webp_to_png
2424
from config import conf, get_appdata_dir
2525
from lib import itchat
2626
from lib.itchat.content import *
@@ -109,7 +109,7 @@ class WechatChannel(ChatChannel):
109109

110110
def __init__(self):
111111
super().__init__()
112-
self.receivedMsgs = ExpiredDict(conf().get("expires_in_seconds"))
112+
self.receivedMsgs = ExpiredDict(conf().get("expires_in_seconds", 3600))
113113
self.auto_login_times = 0
114114

115115
def startup(self):
@@ -229,6 +229,12 @@ def send(self, reply: Reply, context: Context):
229229
image_storage.write(block)
230230
logger.info(f"[WX] download image success, size={size}, img_url={img_url}")
231231
image_storage.seek(0)
232+
if ".webp" in img_url:
233+
try:
234+
image_storage = convert_webp_to_png(image_storage)
235+
except Exception as e:
236+
logger.error(f"Failed to convert image: {e}")
237+
return
232238
itchat.send_image(image_storage, toUserName=receiver)
233239
logger.info("[WX] sendImage url={}, receiver={}".format(img_url, receiver))
234240
elif reply.type == ReplyType.IMAGE: # 从文件读取图片
@@ -266,6 +272,7 @@ def _send_login_success():
266272
except Exception as e:
267273
pass
268274

275+
269276
def _send_logout():
270277
try:
271278
from common.linkai_client import chat_client
@@ -274,10 +281,12 @@ def _send_logout():
274281
except Exception as e:
275282
pass
276283

284+
277285
def _send_qr_code(qrcode_list: list):
278286
try:
279287
from common.linkai_client import chat_client
280288
if chat_client.client_id:
281289
chat_client.send_qrcode(qrcode_list)
282290
except Exception as e:
283291
pass
292+

channel/wechatcom/wechatcomapp_channel.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from channel.wechatcom.wechatcomapp_message import WechatComAppMessage
1818
from common.log import logger
1919
from common.singleton import singleton
20-
from common.utils import compress_imgfile, fsize, split_string_by_utf8_length
20+
from common.utils import compress_imgfile, fsize, split_string_by_utf8_length, convert_webp_to_png
2121
from config import conf, subscribe_msg
2222
from voice.audio_convert import any_to_amr, split_audio
2323

@@ -99,6 +99,12 @@ def send(self, reply: Reply, context: Context):
9999
image_storage = compress_imgfile(image_storage, 10 * 1024 * 1024 - 1)
100100
logger.info("[wechatcom] image compressed, sz={}".format(fsize(image_storage)))
101101
image_storage.seek(0)
102+
if ".webp" in img_url:
103+
try:
104+
image_storage = convert_webp_to_png(image_storage)
105+
except Exception as e:
106+
logger.error(f"Failed to convert image: {e}")
107+
return
102108
try:
103109
response = self.client.media.upload("image", image_storage)
104110
logger.debug("[wechatcom] upload image response: {}".format(response))

common/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
from urllib.parse import urlparse
44
from PIL import Image
5-
5+
from common.log import logger
66

77
def fsize(file):
88
if isinstance(file, io.BytesIO):
@@ -54,3 +54,17 @@ def split_string_by_utf8_length(string, max_length, max_split=0):
5454
def get_path_suffix(path):
5555
path = urlparse(path).path
5656
return os.path.splitext(path)[-1].lstrip('.')
57+
58+
59+
def convert_webp_to_png(webp_image):
60+
from PIL import Image
61+
try:
62+
webp_image.seek(0)
63+
img = Image.open(webp_image).convert("RGBA")
64+
png_image = io.BytesIO()
65+
img.save(png_image, format="PNG")
66+
png_image.seek(0)
67+
return png_image
68+
except Exception as e:
69+
logger.error(f"Failed to convert WEBP to PNG: {e}")
70+
raise

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
"xunfei_app_id": "", # 讯飞应用ID
7474
"xunfei_api_key": "", # 讯飞 API key
7575
"xunfei_api_secret": "", # 讯飞 API secret
76+
"xunfei_domain": "", # 讯飞模型对应的domain参数,Spark4.0 Ultra为 4.0Ultra,其他模型详见: https://www.xfyun.cn/doc/spark/Web.html
77+
"xunfei_spark_url": "", # 讯飞模型对应的请求地址,Spark4.0 Ultra为 wss://spark-api.xf-yun.com/v4.0/chat,其他模型参考详见: https://www.xfyun.cn/doc/spark/Web.html
7678
# claude 配置
7779
"claude_api_cookie": "",
7880
"claude_uuid": "",

plugins/keyword/keyword.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def on_handle_context(self, e_context: EventContext):
5555
reply_text = self.keyword[content]
5656

5757
# 判断匹配内容的类型
58-
if (reply_text.startswith("http://") or reply_text.startswith("https://")) and any(reply_text.endswith(ext) for ext in [".jpg", ".jpeg", ".png", ".gif", ".img"]):
58+
if (reply_text.startswith("http://") or reply_text.startswith("https://")) and any(reply_text.endswith(ext) for ext in [".jpg", ".webp", ".jpeg", ".png", ".gif", ".img"]):
5959
# 如果是以 http:// 或 https:// 开头,且".jpg", ".jpeg", ".png", ".gif", ".img"结尾,则认为是图片 URL。
6060
reply = Reply()
6161
reply.type = ReplyType.IMAGE_URL

plugins/role/role.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ def on_handle_context(self, e_context: EventContext):
9999
if e_context["context"].type != ContextType.TEXT:
100100
return
101101
btype = Bridge().get_bot_type("chat")
102-
if btype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.LINKAI]:
102+
if btype not in [const.OPEN_AI, const.CHATGPT, const.CHATGPTONAZURE, const.QWEN_DASHSCOPE, const.XUNFEI, const.BAIDU, const.ZHIPU_AI, const.MOONSHOT, const.MiniMax, const.LINKAI]:
103+
logger.debug(f'不支持的bot: {btype}')
103104
return
104105
bot = Bridge().get_bot("chat")
105106
content = e_context["context"].content[:]

plugins/tool/tool.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ class Tool(Plugin):
2222
def __init__(self):
2323
super().__init__()
2424
self.handlers[Event.ON_HANDLE_CONTEXT] = self.on_handle_context
25-
2625
self.app = self._reset_app()
27-
26+
if not self.tool_config.get("tools"):
27+
logger.warn("[tool] init failed, ignore ")
28+
raise Exception("config.json not found")
2829
logger.info("[tool] inited")
2930

31+
3032
def get_help_text(self, verbose=False, **kwargs):
3133
help_text = "这是一个能让chatgpt联网,搜索,数字运算的插件,将赋予强大且丰富的扩展能力。"
3234
trigger_prefix = conf().get("plugin_trigger_prefix", "$")

0 commit comments

Comments
 (0)