This project can only run on the win system . It is based on the second modification of chatgpt-on-wechat and completely uses the framework of the source project. Thanks! It supports the PC client of the Win platform and the enterprise and micro client. This project will continue to be updated, and plug-ins will also be gradually developed. It can be developed by one person, please do not rush, thank you!
The message channels and functions supported by the project are as follows:
Wework : The PC-side corporate and micro personal account messaging channel, which relies on ntwork and is limited to WeCom_4.0.8.6027 version, can only run the project on the Win platform .
Wechat : A micro-message channel on the PC side, which relies on the ntchat project. It supports up to Python310 environment version, is limited to WeChat3.6.0.18 version, and can only run the project on the Win platform .
2023.08.15: Update FastGpt access logic to support single group and single knowledge base. If not configured, the global base will be used by default.
{ "fast_gpt" : true , "fastgpt_list" : { "R:108864****63985" : " fastgpt-1aps*****pg47-64b16a*******181317 " , "R:107******373863" : " fastgpt-1aps8*****gni1kpg47-64b168*****cd181267 " } }2023.08.08: Added Wework (Qiwei personal account) message channel.
2023.07.25: It is appropriate to add a wechat message channel. The project is compatible with the FastGPT API interface and can be used by directly modifying open_ai_api_key and open_ai_api_base.
Only supports Windows systems and requires Python
to be installed.
It is recommended that the Python version is between 3.7.1~3.10.
(1) Download project code:
git clone https://github.com/chazzjimel/WeChat-AIChatbot-WinOnly
cd chatgpt-on-wechat/
(2) Install core dependencies (required):
pip3 install -r requirements.txt
(3) Expansion dependencies (optional, recommended to install):
pip3 install -r requirements-optional.txt
If the installation of a certain dependency fails, please comment out the corresponding line before continuing.
Among them, tiktoken
requires python
version 3.8 or above. It is used to accurately calculate the number of tokens used in the session. It is strongly recommended to install it.
To use google
or baidu
speech recognition, you need to install ffmpeg
.
The default openai
speech recognition does not require ffmpeg
to be installed.
Reference #415
To use the azure
Voice function, you need to install dependencies and refer to the environmental requirements of the document. :
pip3 install azure-cognitiveservices-speech
The template of the configuration file is in config-template.json
in the root directory. You need to copy the template to create the final effective config.json
file:
cp config-template.json config.json
Then fill in the configuration in config.json
. The following is a description of the default configuration. You can customize it as needed (please remove the comments):
# config.json文件内容示例
{
"open_ai_api_key" : " YOUR API KEY " , # 填入上面创建的 OpenAI API KEY
"model" : " gpt-3.5-turbo " , # 模型名称。当use_azure_chatgpt为true时,其名称为Azure上model deployment名称
"proxy" : " " , # 代理客户端的ip和端口,国内环境开启代理的需要填写该项,如 "127.0.0.1:7890"
"single_chat_prefix" : [ " bot " , " @bot " ], # 私聊时文本需要包含该前缀才能触发机器人回复
"single_chat_reply_prefix" : " [bot] " , # 私聊时自动回复的前缀,用于区分真人
"group_chat_prefix" : [ " @bot " ], # 群聊时包含该前缀则会触发机器人回复
"group_name_white_list" : [ " ChatGPT测试群" , " ChatGPT测试群2 " ], # 开启自动回复的群名称列表
"group_chat_in_one_session" : [ " ChatGPT测试群" ], # 支持会话上下文共享的群名称
"image_create_prefix" : [ "画" , "看" , "找" ], # 开启图片回复的前缀
"conversation_max_tokens" : 1000 , # 支持上下文记忆的最多字符数
"speech_recognition" : false , # 是否开启语音识别
"group_speech_recognition" : false , # 是否开启群组语音识别
"use_azure_chatgpt" : false , # 是否使用Azure ChatGPT service代替openai ChatGPT service. 当设置为true时需要设置 open_ai_api_base,如 https://xxx.openai.azure.com/
"azure_deployment_id" : " " , # 采用Azure ChatGPT时,模型部署名称
"azure_api_version" : " " , # 采用Azure ChatGPT时,API版本
"character_desc" : "你是ChatGPT, 一个由OpenAI训练的大型语言模型, 你旨在回答并解决人们的任何问题,并且可以使用多种语言与人交流。 " , # 人格描述
# 订阅消息,公众号和企业微信channel中请填写,当被订阅时会自动回复,可使用特殊占位符。目前支持的占位符有{trigger_prefix } ,在程序中它会自动替换成bot的触发词。
"subscribe_msg" : "感谢您的关注! n这里是ChatGPT,可以自由对话。 n支持语音对话。 n支持图片输出,画字开头的消息将按要求创作图片。 n支持角色扮演和文字冒险等丰富插件。 n输入{trigger_prefix}#help 查看详细指令。 " ,
"accept_friend" : false , # 配置itchat和ntchat自动通过好友请求
"channel_type" : " wx " , #通道类型,支持:{ntchat,wework,weowrktop}
"fast_gpt" : false , # 标识模型接口是否是fastgpt
"ntchat_smart" : false , # 配置ntchat多开,为true时接管当前已登录微信,默认true
"wework_smart" : false , # 配置wework多开,为true时接管当前已登录企业微信,默认true
"fastgpt_list" : {
"R:108864****63985" : " fastgpt-1aps*****pg47-64b16a*******181317 " ,
"R:107******373863" : " fastgpt-1aps8*****gni1kpg47-64b168*****cd181267 "
}, # 每个群聊ID配置对应的key即可实现单群单知识库,未配置的默认
"wework_http" : " http://127.0.0.1:8000 " , # weworktop通道http接口地址,默认127.0.0.1:8000
"wework_callback_port" : 8001 , # weworktop回调端口
"voice_openai_api_key" : " " , # 使用了fasgpt仍然有openai语音识别需求的,要在这里配置一下openai的参数
"voice_openai_api_base" : " " , # 使用了fasgpt仍然有openai语音识别需求的,要在这里配置一下openai的参数
}
Configuration instructions:
1.Personal chat
single_chat_prefix
(if you do not need to trigger with a prefix, you can fill in "single_chat_prefix": [""]
)single_chat_reply_prefix
(if you do not need a prefix, you can fill in "single_chat_reply_prefix": ""
)2.Group chat
group_name_white_list
to enable group chat automatic reply. If you want to take effect for all group chats, you can directly fill in "group_name_white_list": ["ALL_GROUP"]
group_chat_prefix
group_name_keyword_white_list
configuration item supports fuzzy matching of group names, and the group_chat_keyword
configuration item supports fuzzy matching of group message content. The usage is the same as the above two configuration items. (Contributed by evolay)group_chat_in_one_session
: enables group chats to share a session context, and the configuration ["ALL_GROUP"]
applies to all group chats3. Voice recognition
"speech_recognition": true
will enable speech recognition. By default, openai's whisper model will be used to recognize text and reply with text. This parameter only supports private chat (note that since voice messages cannot match prefixes, once enabled, all voices will be automatically replied. Supports voice-triggered drawing);"group_speech_recognition": true
will enable group speech recognition. By default, openai's whisper model is used to recognize text and reply with text. The parameter only supports group chat (will match group_chat_prefix and group_chat_keyword, and supports voice-triggered drawing);"voice_reply_voice": true
will enable voice reply voice (applies to both private chat and group chat), but you need to configure the key corresponding to the speech synthesis platform. Due to the limitations of the itchat protocol, only voice mp3 files can be sent. If you use wechaty, reply It's WeChat voice.4.Other configurations
model
: model name, currently supports gpt-3.5-turbo
, text-davinci-003
, gpt-4
, gpt-4-32k
(the gpt-4 api is not yet fully open and can be used after the application is approved)temperature
, frequency_penalty
, presence_penalty
: Chat API interface parameters, please refer to OpenAI official documentation for details.proxy
: Since the openai
interface is currently inaccessible in China, the address of the proxy client needs to be configured. For details, refer to #351image_create_prefix
config.py
.conversation_max_tokens
: Indicates the maximum number of words in the context that can be remembered (one question and one answer is a set of conversations. If the accumulated number of words in the conversation exceeds the limit, the earliest set of conversations will be removed first)rate_limit_chatgpt
, rate_limit_dalle
: the maximum question and answer rate and drawing rate per minute, queued and processed in sequence after overspeeding.clear_memory_commands
: In-dialogue commands that automatically clear the previous memory. The string array can be customized with command aliases.hot_reload
: After the program exits, the WeChat code scanning status is temporarily stored and is closed by default.character_desc
configuration stores a sentence you said to the robot. He will remember this sentence and use it as his settings. You can customize any personality for him (for more information about conversation context, please refer to this issue)subscribe_msg
: To subscribe to messages, please fill in the official account and corporate WeChat channel. It will automatically reply when subscribed. Special placeholders can be used. Currently supported placeholders are {trigger_prefix}, which will be automatically replaced with the bot's trigger word in the program. This documentation may not be updated in time. All currently optional configuration items are listed in this config.py
.
If running locally on the development machine, execute directly in the project root directory:
python3 app.py
1. After installing the main dependencies in the main project, you also need to install the ntchat dependencies.
pip install ntchat
2. Install the designated PC WeChat version: WeChat version 3.6.0.18, scan the QR code to log in, and turn off automatic update of WeChat.
3. Modify the main project configuration items: in the config.json file
"channel_type" : " ntchat "
4. Run app.py
1. After installing the main dependencies in the main project, you also need to install the ntchat dependencies.
pip install ntwork
2. Install the designated PC Enterprise WeChat version: WeCom_4.0.8.6027 version, scan the QR code to log in, and turn off automatic update of Enterprise WeChat
3. Modify the main project configuration items: in the config.json file
"channel_type" : " wework "
4. Run app.py
1. Install the designated PC Enterprise WeChat version: WeCom_4.0.8.6027 version, scan the QR code to log in, and turn off automatic update of Enterprise WeChat
2. Modify the main project configuration items: in the config.json file
"channel_type" : " weworktop "
3. The administrator runs the Qiwei interface program. The basic version is in the project folder "WeChat-AIChatbot-WinOnlychannelweworktop". Run WeworkApi.exe. Click to start the service without entering the key. After successful startup, open Qiwei and download step
4. Run app.py