Browse Source

Merge branch 'master' of github.com:zhayujie/chatgpt-on-wechat

develop
Saboteur7 4 months ago
parent
commit
2711fa1b1b
11 changed files with 38 additions and 14 deletions
  1. +8
    -2
      README.md
  2. +2
    -0
      bot/claudeapi/claude_api_bot.py
  3. +4
    -2
      bot/gemini/google_gemini_bot.py
  4. +1
    -1
      bridge/bridge.py
  5. +1
    -0
      channel/chat_channel.py
  6. +1
    -1
      channel/dingtalk/dingtalk_channel.py
  7. +1
    -0
      channel/dingtalk/dingtalk_message.py
  8. +7
    -4
      common/const.py
  9. +4
    -4
      config.py
  10. +1
    -0
      docker/docker-compose.yml
  11. +8
    -0
      plugins/source.json

+ 8
- 2
README.md View File

@@ -5,7 +5,7 @@
最新版本支持的功能如下: 最新版本支持的功能如下:


- ✅ **多端部署:** 有多种部署方式可选择且功能完备,目前已支持微信公众号、企业微信应用、飞书、钉钉等部署方式 - ✅ **多端部署:** 有多种部署方式可选择且功能完备,目前已支持微信公众号、企业微信应用、飞书、钉钉等部署方式
- ✅ **基础对话:** 私聊及群聊的消息智能回复,支持多轮会话上下文记忆,支持 GPT-3.5, GPT-4, GPT-4o, Claude-3, Gemini, 文心一言, 讯飞星火, 通义千问,ChatGLM-4,Kimi(月之暗面)
- ✅ **基础对话:** 私聊及群聊的消息智能回复,支持多轮会话上下文记忆,支持 GPT-3.5, GPT-4, GPT-4o, Claude-3.5, Gemini, 文心一言, 讯飞星火, 通义千问,ChatGLM-4,Kimi(月之暗面), MiniMax
- ✅ **语音能力:** 可识别语音消息,通过文字或语音回复,支持 azure, baidu, google, openai(whisper/tts) 等多种语音模型 - ✅ **语音能力:** 可识别语音消息,通过文字或语音回复,支持 azure, baidu, google, openai(whisper/tts) 等多种语音模型
- ✅ **图像能力:** 支持图片生成、图片识别、图生图(如照片修复),可选择 Dall-E-3, stable diffusion, replicate, midjourney, CogView-3, vision模型 - ✅ **图像能力:** 支持图片生成、图片识别、图生图(如照片修复),可选择 Dall-E-3, stable diffusion, replicate, midjourney, CogView-3, vision模型
- ✅ **丰富插件:** 支持个性化插件扩展,已实现多角色切换、文字冒险、敏感词过滤、聊天记录总结、文档总结和对话、联网搜索等插件 - ✅ **丰富插件:** 支持个性化插件扩展,已实现多角色切换、文字冒险、敏感词过滤、聊天记录总结、文档总结和对话、联网搜索等插件
@@ -18,6 +18,10 @@
3. 本项目主要接入协同办公平台,推荐使用公众号、企微自建应用、钉钉、飞书等接入通道,其他通道为历史产物已不维护 3. 本项目主要接入协同办公平台,推荐使用公众号、企微自建应用、钉钉、飞书等接入通道,其他通道为历史产物已不维护
4. 任何个人、团队和企业,无论以何种方式使用该项目、对何对象提供服务,所产生的一切后果,本项目均不承担任何责任 4. 任何个人、团队和企业,无论以何种方式使用该项目、对何对象提供服务,所产生的一切后果,本项目均不承担任何责任


## 演示

DEMO视频:https://cdn.link-ai.tech/doc/cow_demo.mp4

## 社区 ## 社区


添加小助手微信加入开源项目交流群: 添加小助手微信加入开源项目交流群:
@@ -42,6 +46,8 @@


# 🏷 更新日志 # 🏷 更新日志


>**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模型、工作流图片输入、模型列表完善

>**2024.06.04:** [1.6.6版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.6) 和 [1.6.5版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.5),gpt-4o模型、钉钉流式卡片、讯飞语音识别/合成 >**2024.06.04:** [1.6.6版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.6) 和 [1.6.5版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.5),gpt-4o模型、钉钉流式卡片、讯飞语音识别/合成


>**2024.04.26:** [1.6.0版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.0),新增 Kimi 接入、gpt-4-turbo版本升级、文件总结和语音识别问题修复 >**2024.04.26:** [1.6.0版本](https://github.com/zhayujie/chatgpt-on-wechat/releases/tag/1.6.0),新增 Kimi 接入、gpt-4-turbo版本升级、文件总结和语音识别问题修复
@@ -80,7 +86,7 @@


> 默认对话模型是 openai 的 gpt-3.5-turbo,计费方式是约每 1000tokens (约750个英文单词 或 500汉字,包含请求和回复) 消耗 $0.002,图片生成是Dell E模型,每张消耗 $0.016。 > 默认对话模型是 openai 的 gpt-3.5-turbo,计费方式是约每 1000tokens (约750个英文单词 或 500汉字,包含请求和回复) 消耗 $0.002,图片生成是Dell E模型,每张消耗 $0.016。


项目同时也支持使用 LinkAI 接口,无需代理,可使用 文心、讯飞、GPT-3、GPT-4 等模型,支持 定制化知识库、联网搜索、MJ绘图、文档总结和对话等能力。修改配置即可一键切换,参考 [接入文档](https://link-ai.tech/platform/link-app/wechat)。
项目同时也支持使用 LinkAI 接口,无需代理,可使用 Kimi、文心、讯飞、GPT-3.5、GPT-4o 等模型,支持 定制化知识库、联网搜索、MJ绘图、文档总结、工作流等能力。修改配置即可一键使用,参考 [接入文档](https://link-ai.tech/platform/link-app/wechat)。


### 2.运行环境 ### 2.运行环境




+ 2
- 0
bot/claudeapi/claude_api_bot.py View File

@@ -130,4 +130,6 @@ class ClaudeAPIBot(Bot, OpenAIImage):
return "claude-3-sonnet-20240229" return "claude-3-sonnet-20240229"
elif model == "claude-3-haiku": elif model == "claude-3-haiku":
return "claude-3-haiku-20240307" return "claude-3-haiku-20240307"
elif model == "claude-3.5-sonnet":
return "claude-3-5-sonnet-20240620"
return model return model

+ 4
- 2
bot/gemini/google_gemini_bot.py View File

@@ -24,7 +24,9 @@ class GoogleGeminiBot(Bot):
self.api_key = conf().get("gemini_api_key") self.api_key = conf().get("gemini_api_key")
# 复用文心的token计算方式 # 复用文心的token计算方式
self.sessions = SessionManager(BaiduWenxinSession, model=conf().get("model") or "gpt-3.5-turbo") self.sessions = SessionManager(BaiduWenxinSession, model=conf().get("model") or "gpt-3.5-turbo")

self.model = conf().get("model") or "gemini-pro"
if self.model == "gemini":
self.model = "gemini-pro"
def reply(self, query, context: Context = None) -> Reply: def reply(self, query, context: Context = None) -> Reply:
try: try:
if context.type != ContextType.TEXT: if context.type != ContextType.TEXT:
@@ -35,7 +37,7 @@ class GoogleGeminiBot(Bot):
session = self.sessions.session_query(query, session_id) session = self.sessions.session_query(query, session_id)
gemini_messages = self._convert_to_gemini_messages(self.filter_messages(session.messages)) gemini_messages = self._convert_to_gemini_messages(self.filter_messages(session.messages))
genai.configure(api_key=self.api_key) genai.configure(api_key=self.api_key)
model = genai.GenerativeModel('gemini-pro')
model = genai.GenerativeModel(self.model)
response = model.generate_content(gemini_messages) response = model.generate_content(gemini_messages)
reply_text = response.text reply_text = response.text
self.sessions.session_reply(reply_text, session_id) self.sessions.session_reply(reply_text, session_id)


+ 1
- 1
bridge/bridge.py View File

@@ -36,7 +36,7 @@ class Bridge(object):
self.btype["chat"] = const.QWEN self.btype["chat"] = const.QWEN
if model_type in [const.QWEN_TURBO, const.QWEN_PLUS, const.QWEN_MAX]: if model_type in [const.QWEN_TURBO, const.QWEN_PLUS, const.QWEN_MAX]:
self.btype["chat"] = const.QWEN_DASHSCOPE self.btype["chat"] = const.QWEN_DASHSCOPE
if model_type in [const.GEMINI]:
if model_type and model_type.startswith("gemini"):
self.btype["chat"] = const.GEMINI self.btype["chat"] = const.GEMINI
if model_type in [const.ZHIPU_AI]: if model_type in [const.ZHIPU_AI]:
self.btype["chat"] = const.ZHIPU_AI self.btype["chat"] = const.ZHIPU_AI


+ 1
- 0
channel/chat_channel.py View File

@@ -117,6 +117,7 @@ class ChatChannel(Channel):
logger.info("[chat_channel]receive group at") logger.info("[chat_channel]receive group at")
if not conf().get("group_at_off", False): if not conf().get("group_at_off", False):
flag = True flag = True
self.name = self.name if self.name is not None else "" # 部分渠道self.name可能没有赋值
pattern = f"@{re.escape(self.name)}(\u2005|\u0020)" pattern = f"@{re.escape(self.name)}(\u2005|\u0020)"
subtract_res = re.sub(pattern, r"", content) subtract_res = re.sub(pattern, r"", content)
if isinstance(context["msg"].at_list, list): if isinstance(context["msg"].at_list, list):


+ 1
- 1
channel/dingtalk/dingtalk_channel.py View File

@@ -163,7 +163,7 @@ class DingTalkChanel(ChatChannel, dingtalk_stream.ChatbotHandler):
elif cmsg.ctype == ContextType.PATPAT: elif cmsg.ctype == ContextType.PATPAT:
logger.debug("[DingTalk]receive patpat msg: {}".format(cmsg.content)) logger.debug("[DingTalk]receive patpat msg: {}".format(cmsg.content))
elif cmsg.ctype == ContextType.TEXT: elif cmsg.ctype == ContextType.TEXT:
logger.debug("[DingTalk]receive patpat msg: {}".format(cmsg.content))
logger.debug("[DingTalk]receive text msg: {}".format(cmsg.content))
else: else:
logger.debug("[DingTalk]receive other msg: {}".format(cmsg.content)) logger.debug("[DingTalk]receive other msg: {}".format(cmsg.content))
context = self._compose_context(cmsg.ctype, cmsg.content, isgroup=True, msg=cmsg) context = self._compose_context(cmsg.ctype, cmsg.content, isgroup=True, msg=cmsg)


+ 1
- 0
channel/dingtalk/dingtalk_message.py View File

@@ -49,6 +49,7 @@ class DingTalkMessage(ChatMessage):
if self.is_group: if self.is_group:
self.from_user_id = event.conversation_id self.from_user_id = event.conversation_id
self.actual_user_id = event.sender_id self.actual_user_id = event.sender_id
self.is_at = True
else: else:
self.from_user_id = event.sender_id self.from_user_id = event.sender_id
self.actual_user_id = event.sender_id self.actual_user_id = event.sender_id


+ 7
- 4
common/const.py View File

@@ -11,7 +11,7 @@ QWEN = "qwen" # 旧版通义模型
QWEN_DASHSCOPE = "dashscope" # 通义新版sdk和api key QWEN_DASHSCOPE = "dashscope" # 通义新版sdk和api key




GEMINI = "gemini"
GEMINI = "gemini" # gemini-1.0-pro
ZHIPU_AI = "glm-4" ZHIPU_AI = "glm-4"
MOONSHOT = "moonshot" MOONSHOT = "moonshot"
MiniMax = "minimax" MiniMax = "minimax"
@@ -51,16 +51,19 @@ LINKAI_35 = "linkai-3.5"
LINKAI_4_TURBO = "linkai-4-turbo" LINKAI_4_TURBO = "linkai-4-turbo"
LINKAI_4o = "linkai-4o" LINKAI_4o = "linkai-4o"


GEMINI_PRO = "gemini-1.0-pro"
GEMINI_15_flash = "gemini-1.5-flash"
GEMINI_15_PRO = "gemini-1.5-pro"


MODEL_LIST = [ MODEL_LIST = [
GPT35, GPT35_0125, GPT35_1106, "gpt-3.5-turbo-16k", GPT35, GPT35_0125, GPT35_1106, "gpt-3.5-turbo-16k",
GPT_4o, GPT4_TURBO, GPT4_TURBO_PREVIEW, GPT4_TURBO_01_25, GPT4_TURBO_11_06, GPT4, GPT4_32k, GPT4_06_13, GPT4_32k_06_13, GPT_4o, GPT4_TURBO, GPT4_TURBO_PREVIEW, GPT4_TURBO_01_25, GPT4_TURBO_11_06, GPT4, GPT4_32k, GPT4_06_13, GPT4_32k_06_13,
WEN_XIN, WEN_XIN_4, WEN_XIN, WEN_XIN_4,
XUNFEI, GEMINI, ZHIPU_AI, MOONSHOT,
"claude", "claude-3-haiku", "claude-3-sonnet", "claude-3-opus", "claude-3-opus-20240229",
XUNFEI, ZHIPU_AI, MOONSHOT, MiniMax,
GEMINI, GEMINI_PRO, GEMINI_15_flash, GEMINI_15_PRO,
"claude", "claude-3-haiku", "claude-3-sonnet", "claude-3-opus", "claude-3-opus-20240229", "claude-3.5-sonnet",
"moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k", "moonshot-v1-8k", "moonshot-v1-32k", "moonshot-v1-128k",
QWEN, QWEN_TURBO, QWEN_PLUS, QWEN_MAX, QWEN, QWEN_TURBO, QWEN_PLUS, QWEN_MAX,
MiniMax,
LINKAI_35, LINKAI_4_TURBO, LINKAI_4o LINKAI_35, LINKAI_4_TURBO, LINKAI_4o
] ]




+ 4
- 4
config.py View File

@@ -17,7 +17,7 @@ available_setting = {
"open_ai_api_base": "https://api.openai.com/v1", "open_ai_api_base": "https://api.openai.com/v1",
"proxy": "", # openai使用的代理 "proxy": "", # openai使用的代理
# chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称 # chatgpt模型, 当use_azure_chatgpt为true时,其名称为Azure上model deployment名称
"model": "gpt-3.5-turbo", # 支持ChatGPT、Claude、Gemini、文心一言、通义千问、Kimi、讯飞星火、智谱、LinkAI等模型,模型具体名称详见common/const.py文件列出的模型
"model": "gpt-3.5-turbo", # 可选择: gpt-4o, gpt-4-turbo, claude-3-sonnet, wenxin, moonshot, qwen-turbo, xunfei, glm-4, minimax, gemini等模型,全部可选模型详见common/const.py文件
"bot_type": "", # 可选配置,使用兼容openai格式的三方服务时候,需填"chatGPT"。bot具体名称详见common/const.py文件列出的bot_type,如不填根据model名称判断, "bot_type": "", # 可选配置,使用兼容openai格式的三方服务时候,需填"chatGPT"。bot具体名称详见common/const.py文件列出的bot_type,如不填根据model名称判断,
"use_azure_chatgpt": False, # 是否使用azure的chatgpt "use_azure_chatgpt": False, # 是否使用azure的chatgpt
"azure_deployment_id": "", # azure 模型部署名称 "azure_deployment_id": "", # azure 模型部署名称
@@ -96,7 +96,7 @@ available_setting = {
"voice_reply_voice": False, # 是否使用语音回复语音,需要设置对应语音合成引擎的api key "voice_reply_voice": False, # 是否使用语音回复语音,需要设置对应语音合成引擎的api key
"always_reply_voice": False, # 是否一直使用语音回复 "always_reply_voice": False, # 是否一直使用语音回复
"voice_to_text": "openai", # 语音识别引擎,支持openai,baidu,google,azure "voice_to_text": "openai", # 语音识别引擎,支持openai,baidu,google,azure
"text_to_voice": "openai", # 语音合成引擎,支持openai,baidu,google,pytts(offline),azure,elevenlabs,edge(online)
"text_to_voice": "openai", # 语音合成引擎,支持openai,baidu,google,pytts(offline),ali,azure,elevenlabs,edge(online)
"text_to_voice_model": "tts-1", "text_to_voice_model": "tts-1",
"tts_voice_id": "alloy", "tts_voice_id": "alloy",
# baidu 语音api配置, 使用百度语音识别和语音合成时需要 # baidu 语音api配置, 使用百度语音识别和语音合成时需要
@@ -242,7 +242,7 @@ def drag_sensitive(config):
conf_dict_copy = copy.deepcopy(conf_dict) conf_dict_copy = copy.deepcopy(conf_dict)
for key in conf_dict_copy: for key in conf_dict_copy:
if "key" in key or "secret" in key: if "key" in key or "secret" in key:
if isinstance(key, str):
if isinstance(conf_dict_copy[key], str):
conf_dict_copy[key] = conf_dict_copy[key][0:3] + "*" * 5 + conf_dict_copy[key][-3:] conf_dict_copy[key] = conf_dict_copy[key][0:3] + "*" * 5 + conf_dict_copy[key][-3:]
return json.dumps(conf_dict_copy, indent=4) return json.dumps(conf_dict_copy, indent=4)


@@ -250,7 +250,7 @@ def drag_sensitive(config):
config_copy = copy.deepcopy(config) config_copy = copy.deepcopy(config)
for key in config: for key in config:
if "key" in key or "secret" in key: if "key" in key or "secret" in key:
if isinstance(key, str):
if isinstance(config_copy[key], str):
config_copy[key] = config_copy[key][0:3] + "*" * 5 + config_copy[key][-3:] config_copy[key] = config_copy[key][0:3] + "*" * 5 + config_copy[key][-3:]
return config_copy return config_copy
except Exception as e: except Exception as e:


+ 1
- 0
docker/docker-compose.yml View File

@@ -6,6 +6,7 @@ services:
security_opt: security_opt:
- seccomp:unconfined - seccomp:unconfined
environment: environment:
TZ: 'Asia/Shanghai'
OPEN_AI_API_KEY: 'YOUR API KEY' OPEN_AI_API_KEY: 'YOUR API KEY'
MODEL: 'gpt-3.5-turbo' MODEL: 'gpt-3.5-turbo'
PROXY: '' PROXY: ''


+ 8
- 0
plugins/source.json View File

@@ -31,6 +31,14 @@
"midjourney": { "midjourney": {
"url": "https://github.com/baojingyu/midjourney.git", "url": "https://github.com/baojingyu/midjourney.git",
"desc": "利用midjourney实现ai绘图的的插件" "desc": "利用midjourney实现ai绘图的的插件"
},
"solitaire": {
"url": "https://github.com/Wang-zhechao/solitaire.git",
"desc": "机器人微信接龙插件"
},
"HighSpeedTicket": {
"url": "https://github.com/He0607/HighSpeedTicket.git",
"desc": "高铁(火车)票查询插件"
} }
} }
} }

Loading…
Cancel
Save