ChatGPT 接入微信的方法汇总(含 dify | coze | FastGPT | one-api)

#WeChaty #ItChat #ChatGPT-On-WeChat #企业微信 #微秘书 #LinkAI #开源项目 #配置文件 #docker-compose #API KEY #机器人 #AI智能助手 #多模态基础模型 #知识库 #文本 #语音 #图像 #Agent插件 #对接教程 #技术分享 #Linuxdo论坛

一、免费方法

1、WeChaty

项目地址: https://github.com/wechaty/wechaty

2、ItChat

项目地址: https://github.com/littlecodersh/ItChat

3、ChatGPT-On-WeChat

项目地址: https://github.com/zhayujie/chatgpt-on-wechat
功能范围:个人微信、微信公众号、企业微信应用等。(这里只讲解如何配置企业微信应用)
需要有自己的服务器(配置过程面板为1panel

1)配置企业微信应用

a)创建应用

b)搜集的数据

1
2
3
4
5
Agentld=
Secret=
企业ID=
Token=
EncodingAESKey=

2)获取openai key

搭建ChatGPT-Web-Site ——PPPFZ’S BLOG # 三、申请 OpenAI 的 API KEY

我的代转 api 服务: https://gptapi.pppfz.com/

只有3.5哈,个人使用哈,测试下通信

3)修改配置文件

打开你的本本,复制进去,修改:

配置文件模板: https://github.com/zhayujie/chatgpt-on-wechat/blob/master/config-template.json
配置文件可选项及其解释: https://github.com/zhayujie/chatgpt-on-wechat/blob/master/config.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
{
  "channel_type": "wechatcom_app",
  "wechatcom_corp_id": "",  
  "wechatcomapp_port": 9898,  
  "wechatcomapp_agent_id": ,  
  "wechatcomapp_secret": "",  
  "wechatcomapp_token": "",  
  "wechatcomapp_aes_key": "",
  "model": "gpt-3.5-turbo",
  "open_ai_api_key": "",
  "claude_api_key": "YOUR API KEY",
  "text_to_image": "dall-e-2",
  "voice_to_text": "openai",
  "text_to_voice": "openai",
  "open_ai_api_base": "https://gptapi.pppfz.com/v1",
  "hot_reload": false,
  "single_chat_prefix": [""],
  "single_chat_reply_prefix": "[bot] ",
  "group_chat_prefix": [
    "@bot"
  ],
  "group_name_white_list": [
    "ChatGPT测试群",
    "ChatGPT测试群2"
  ],
  "image_create_prefix": [
    "画"
  ],
  "speech_recognition": true,
  "group_speech_recognition": false,
  "voice_reply_voice": false,
  "conversation_max_tokens": 2500,
  "expires_in_seconds": 3600,
  "character_desc": "你是基于大语言模型的AI智能助手,旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。",
  "temperature": 0.7,
  "subscribe_msg": "感谢您的关注!\n这里是AI智能助手,可以自由对话。\n支持语音对话。\n支持图片输入。\n支持图片输出,画字开头的消息将按要求创作图片。\n支持tool、角色扮演和文字冒险等丰富的插件。\n输入{trigger_prefix}#help 查看详细指令。",
  "use_linkai": false,
  "linkai_api_key": "",
  "linkai_app_code": "",
  "linkai_api_base": "https://api.link-ai.tech"
}

注意事项:

  • 文中不能有 # 注释
  • 添加配置选项后,记得添加英文逗号: ,
  • 需要添加或修改
    • wechatcom_corp_id
    • wechatcomapp_agent_id
    • wechatcomapp_secret
    • wechatcomapp_token
    • wechatcomapp_aes_key
    • open_ai_api_key
    • open_ai_api_base
      • api 代理地址,官网api 不需要填写,别人代转的api 需要填写
    • single_chat_prefix
      • 现在无需前缀,即可与机器人聊天

4)启动服务并验证

创建 docker-compose.yml 文件,将下面的内容粘入:

1
2
3
4
5
6
7
8
9
10
11
12
version: '2.0'

services:
  chatgpt-on-wechat:
    image: zhayujie/chatgpt-on-wechat
    container_name: chatgpt-on-wechat
    ports:
      - 9898:9898
    security_opt:
      - seccomp:unconfined
    volumes:
      - ./config.json:/app/config.json
  • 配置文件 放在docker-compose.yml 同一目录下
  • 同一目录下运行: docker-compose up -d

启动成功后,访问 http://your_ip:9898/wxcomapp ,看到下面的页面即为启动服务成功

注意开启防火墙端口

最后一步保存,我们的企业微信应用

参考教程: https://zhuanlan.zhihu.com/p/632457208

4、Dify-On-WeChat

项目地址: https://github.com/hanfangyuan4396/dify-on-wechat
chatgpt-on-wechat下游分支, 额外对接了LLMOps平台 Dify

二、付费方式

1、微秘书

基于两个开源项目:

总共分为两步

功能:

  • 基于xxxx协议,不易被封(显示在电脑端登录)
  • 对接多种机器人(chatgpt、fastgpt、coze、dify)
  • 可视化面板,操作简单
  • 提供 api 接口,可以对接其他程序
  • 但是要收费

1)对接openapi的python代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import requests
import json

# 从输入数据中提取出content和img的内容

content = input_data.get("content")
img = input_data.get("img")

if content:
    url = 'https://api-bot.aibotk.com/openapi/v1/chat/room'
    headers = {
        'Content-Type': 'application/json'
    }
    data = {
        "apiKey": "802fd684xxxxxxxxxxxxxxxxxxxxxxxx55d46f8",
        "roomName": "转发测试",
        "message": {
            "type": 1,
            "content": content
        }
    }
    response = requests.post(url, headers=headers, data=json.dumps(data))
    if response.status_code == 200:
        print(json.dumps(response.json()))
    else:
        print(response.text)
if img:
    url = 'https://api-bot.aibotk.com/openapi/v1/chat/room'
    headers = {
        'Content-Type': 'application/json'
    }
    data = {
        "apiKey": "802fd684b9xxxxxxxxxxxxxxxxxx955d46f8",
        "roomName": "转发测试",
        "message": {
            "type": 2,
            "url": img
        }
    }
    response = requests.post(url, headers=headers, data=json.dumps(data))
    if response.status_code == 200:
        print(json.dumps(response.json()))
    else:
        print(response.text)
    pass

2、LinkAI

LinkAI是一站式的AI应用平台,聚合文本、语音、图像等多模态基础模型,在此基础上提供知识库定制化、Agent插件等增强能力,基于开源生态和开放接口快速完成应用接入。

三、其他

论坛老哥的分享: https://linux.do/t/topic/30834/5


ChatGPT 接入微信的方法汇总(含 dify | coze | FastGPT | one-api)
https://blog.pppfz.com/posts/20.html
作者
PPPFZ
发布于
2024年5月11日
许可协议