ChatGPT DingTalk
? DingTalk integrated ChatGPT robot based on GO language?
Table of contents
This project can help you integrate GPT robots into DingTalk Group Chat. The current default model is gpt-3.5
, and it supports gpt-4
and gpt-4o-mini
. It also supports Azure-OpenAI.
? 注意
: The deployment and configuration process are now very mature, and the documents and issue are basically covered. Therefore, no questions about installation, deployment and configuration use of any project will be answered. If you don’t understand at all, you can consider contacting me through email for paid technical support.
? 注意
: All the functions of this project are gathered in the usage guide. Please be sure to read them carefully to experience its complete essence.
? Welcome to follow my other open source projects:
- Go-Ldap-Admin:? OpenLDAP backend management project based on Go+Vue.
- learning-weekly: The weekly content is mainly operation and maintenance technology and Go language peripherals, supplemented by excellent projects on GitHub or other people's excellent experience.
- HowToStartOpenSource:? GitHub Open Source Project Maintenance Collaboration Guide.
- read-list: The reading is the basis for high-quality content subscription
- awesome-github-profile-readme-chinese:? Collection of excellent Chinese area personal homepages
? I also created a project awesome-chatgpt-answer : record those moments of good questions and great answers. Welcome to submit the exquisite conversations you encountered during your interaction with ChatGPT.
⚗️ openai official provides a status page to present the current status of the openAI service. At the same time, if there are any problems, the announcement will be posted on this page. If you feel that it has a problem, you can check it out on this page.
Sponsors
302.AI is a one-stop AI application platform that pays on demand, an open platform, and an open source ecosystem.
- Click to register: Get 1PTC (1PTC=1 US dollars, about RMB 7) tokens immediately.
- It brings together the latest and most complete AI models and brands, including but not limited to language models, image models, sound models, and video models.
- Carry out in-depth application development on the basic model so that novices can use it at zero threshold without learning costs.
- Zero monthly fee, all functions are paid on demand, fully open, achieving a real low threshold and high ceiling.
- Innovative usage model, separation of management and use, aimed at teams and small and medium-sized enterprises, managed by one person and used by multiple people.
- All AI capabilities provide API access, and all applications open source support self-customization (in progress).
- A strong development team, launching 2-3 new applications every week, and the platform features are updated daily.
帮助
you will see the help list,? View the example#图片
keyword, ? View example#周报
? View the example余额
keyword, ? View the example#查对话username:xxx
xxx, you can preview it online and download it to the local area.api_key
, you can refer to this article for registration related matters. Visit here to apply for a personal key.It is recommended that you use docker to run this project quickly.
第一种:基于环境变量运行
# 运行项目
$ docker run -itd --name chatgpt -p 8090:8090
-v ./data:/app/data --add-host="host.docker.internal:host-gateway"
-e LOG_LEVEL="info" -e APIKEY=换成你的key -e BASE_URL=""
-e MODEL="gpt-3.5-turbo" -e SESSION_TIMEOUT=600
-e MAX_QUESTION_LENL=2048 -e MAX_ANSWER_LEN=2048 -e MAX_TEXT=4096
-e HTTP_PROXY="http://host.docker.internal:15732"
-e DEFAULT_MODE="单聊" -e MAX_REQUEST=0 -e PORT=8090
-e SERVICE_URL="你当前服务外网可访问的URL" -e CHAT_TYPE="0"
-e ALLOW_GROUPS=a,b -e ALLOW_OUTGOING_GROUPS=a,b -e ALLOW_USERS=a,b -e DENY_USERS=a,b -e VIP_USERS=a,b -e ADMIN_USERS=a,b -e APP_SECRETS="xxx,yyy"
-e SENSITIVE_WORDS="aa,bb" -e RUN_MODE="http"
-e AZURE_ON="false" -e AZURE_API_VERSION="" -e AZURE_RESOURCE_NAME=""
-e AZURE_DEPLOYMENT_NAME="" -e AZURE_OPENAI_TOKEN=""
-e DINGTALK_CREDENTIALS="your_client_id1:secret1,your_client_id2:secret2"
-e HELP="欢迎使用本工具nn你可以查看:[用户指南](https://github.com/eryajf/chatgpt-dingtalk/blob/main/docs/userGuide.md)nn这是一个[开源项目](https://github.com/eryajf/chatgpt-dingtalk/)
,觉得不错你可以来波素质三连."
--restart=always registry.cn-hangzhou.aliyuncs.com/eryajf/chatgpt-dingtalk
The configuration file mapped in the run command is referenced below for the configuration file description.
? 注意:
If deployed using docker, no adjustments are required for the PORT parameters.? 注意:
The ALLOW_GROUPS,ALLOW_USERS,DENY_USERS,VIP_USERS,ADMIN_USERS parameters are arrays. If multiple parameters need to be specified, they can be divided by English commas. outgoing These parameters are invalid in robot mode.? 注意:
If the server node itself is abroad or has customized BASE_URL
, then leave HTTP_PROXY
parameter blank.? 注意:
If you use docker to deploy, then the proxy address can be deployed directly in the above method. host.docker.internal
will point to the IP of the host host where the container is located. You only need to change the port to your proxy port. See: How Docker containers elegantly access host networks 第二种:基于配置文件挂载运行
# 复制配置文件,根据自己实际情况,调整配置里的内容
$ cp config.example.yml config.yml # 其中 config.example.yml 从项目的根目录获取
# 运行项目
$ docker run -itd --name chatgpt -p 8090:8090 -v `pwd`/config.yml:/app/config.yml --restart=always registry.cn-hangzhou.aliyuncs.com/eryajf/chatgpt-dingtalk
The configuration file is referenced to the configuration file description below.
第三种:使用 docker compose 运行
$ wget https://raw.githubusercontent.com/eryajf/chatgpt-dingtalk/main/docker-compose.yml
$ vim docker-compose.yml # 编辑 APIKEY 等信息
$ docker compose up -d
There is also a step to configure Nginx after the deployment is completed. Now the mode is specified as stream mode by default, so Nginx is no longer required.
If you want to deploy directly through the command line, you can directly download the compressed package in release. Please select the appropriate compressed package according to your system and architecture, and then unzip it directly after downloading.
After downloading, unzip locally and you will see the executable program and configuration file:
$ tar xf chatgpt-dingtalk-v0.0.4-darwin-arm64.tar.gz
$ cd chatgpt-dingtalk-v0.0.4-darwin-arm64
$ cp config.example.yml config.yml
$ ./chatgpt-dingtalk # 直接运行
# 如果要守护在后台运行
$ nohup ./chatgpt-dingtalk & > run.log &
$ tail -f run.log
DingTalk officially launched the stream mode in May 2023, so it is recommended that you use this mode directly here. Other HTTPs are still supported, but they will not conduct in-depth research. Therefore, the following documents are also introduced in the configuration process of the stream mode.
Create steps reference document: internal enterprise application, or configure it according to the following steps.
Create an app.
? 注意:
The name ofchatgpt
may be restricted by DingTalk when creating a robot. Please name it with another name.
In基础信息
-->应用信息
, you can obtain the robot's AppKey
and AppSecret
.
Configure the robot.
Release the robot.
Click版本管理与发布
, and then click上线
. At this time, you can add this robot to DingTalk's group.
Add bots to group chat.
2023-03-08
Added, I found that I can also chat without tying the robot in the group, and clicking on the robot, and then clicking on sending a message to chat by directly talking to the robot:
Student @Raytow found that it is impossible to chat with the robot directly in the test group automatically generated by the robot. Add this robot separately in other groups, and then click to chat with it privately.
When the Aitbot sends empty content or help, it will return to the help list.
Send a specified keyword and you can switch different modes.
? Note: In chat mode, the chat context of each person in the group is independent. ? Note: The default dialogue mode is single chat, so you don’t have to send single chat to enter single chat mode. To enter string chat, you need to send string chat keywords to switch. When the string chat content exceeds the maximum limit, you can send a reset and then enter string chat mode again.
When the Ait robot sends the word
余额
, it will return the remaining amount and available date of the account corresponding to the current key.
Send two words to the template, which will return the currently built-in support prompt list.
If you find a better propt, welcome PR. Note: Some use scenarios that do not match DingTalk very well, so don’t submit them.
Sending content starting with
#图片
will trigger the painting ability. After the image is generated, it will be saved inimages目录
in the root directory of the program.If you have no idea about drawing, you can find some good propts here as well as here.
If your account passes the official whitelist, you can configure the model as: gpt-4-0314
, gpt-4
or gpt-4o-mini
. Currently, the balance query and image generation function of gpt-4 are not available for the time being. It may be an interface limitation or other reasons. When I have the conditions, I will test and verify these functions.
The following is the difference between gpt-3.5 and gpt-4 in terms of mathematical calculations.
Thanks to @PIRANHACHAN for providing the gpt-4 key, which enables the project to perform verification and tests on the docking of gpt-4, and reaches the available state.
# 获取项目
$ git clone https://github.com/eryajf/chatgpt-dingtalk.git
# 进入项目目录
$ cd chatgpt-dingtalk
# 复制配置文件,根据个人实际情况进行配置
$ cp config.example.yml config.yml
# 启动项目
$ go run main.go
# 应用的日志级别,info or debug
log_level : " info "
# 运行模式,http 或者 stream ,强烈建议你使用stream模式,通过此链接了解:https://open.dingtalk.com/document/isvapp/stream
run_mode : " stream "
# openai api_key,如果你是用的是azure,则该配置项可以留空或者直接忽略
api_key : " xxxxxxxxx "
# 如果你使用官方的接口地址 https://api.openai.com,则留空即可,如果你想指定请求url的地址,可通过这个参数进行配置,注意需要带上 http 协议,如果你是用的是azure,则该配置项可以留空或者直接忽略
base_url : " "
# 指定模型,默认为 gpt-3.5-turbo , 可选参数有: "gpt-4-32k-0613", "gpt-4-32k-0314", "gpt-4-32k", "gpt-4-0613", "gpt-4-0314", "gpt-4", "gpt-3.5-turbo-16k-0613", "gpt-3.5-turbo-16k", "gpt-3.5-turbo-0613", "gpt-3.5-turbo-0301", "gpt-3.5-turbo",如果使用gpt-4,请确认自己是否有接口调用白名单,如果你是用的是azure,则该配置项可以留空或者直接忽略
model : " gpt-3.5-turbo "
# 指定绘画模型,默认为 dall-e-2 , 可选参数有:"dall-e-2", "dall-e-3"
image_model : " dall-e-2 "
# 会话超时时间,默认600秒,在会话时间内所有发送给机器人的信息会作为上下文
session_timeout : 600
# 最大问题长度
max_question_len : 2048
# 最大回答长度
max_answer_len : 2048
# 最大上下文文本长度,通常该参数可设置为与模型Token限制相同
max_text : 4096
# 指定请求时使用的代理,如果为空,则不使用代理,注意需要带上 http 协议 或 socks5 协议,如果你是用的是azure,则该配置项可以留空或者直接忽略
http_proxy : " "
# 指定默认的对话模式,可根据实际需求进行自定义,如果不设置,默认为单聊,即无上下文关联的对话模式
default_mode : "单聊"
# 单人单日请求次数上限,默认为0,即不限制
max_request : 0
# 指定服务启动端口,默认为 8090,一般在二进制宿主机部署时,遇到端口冲突时使用,如果run_mode为stream模式,则可以忽略该配置项
port : " 8090 "
# 指定服务的地址,就是当前服务可供外网访问的地址(或者直接理解为你配置在钉钉回调那里的地址),用于生成图片时给钉钉做渲染,最新版本中将图片上传到了钉钉服务器,理论上你可以忽略该配置项,如果run_mode为stream模式,则可以忽略该配置项
service_url : " http://xxxxxx "
# 限定对话类型 0:不限 1:只能单聊 2:只能群聊
chat_type : " 0 "
# 哪些群组可以进行对话(仅在chat_type为0、2时有效),如果留空,则表示允许所有群组,如果要限制,则列表中写群ID(ConversationID)
# 群ID,可在群组中 @机器人 群ID 来查看日志获取,例如日志会输出:[? 企业内部机器人 在『测试』群的ConversationID为: "cidrabcdefgh1234567890AAAAA"],获取后可填写该参数并重启程序
allow_groups : []
# 哪些普通群(使用outgoing机器人)可以进行对话,如果留空,则表示允许所有群组,如果要限制,则列表中写群ID(ConversationID)
# 群ID,可在群组中 @机器人 群ID 来查看日志获取,例如日志会输出:[? outgoing机器人 在『测试』群的ConversationID为: "cidrabcdefgh1234567890AAAAA"],获取后可填写该参数并重启程序
# 如果不想支持outgoing机器人功能,这里可以随意设置一个内部群组,例如:cidrabcdefgh1234567890AAAAA;或随意一个字符串,例如:disabled
# 建议该功能默认关闭:除非你必须要用到outgoing机器人
allow_outgoing_groups : []
# 以下 allow_users、deny_users、vip_users、admin_users 配置中填写的是用户的userid,outgoing机器人模式下不适用这些配置
# 比如 ["1301691029702722","1301691029702733"],这个信息需要在钉钉管理后台的通讯录当中获取:https://oa.dingtalk.com/contacts.htm#/contacts
# 哪些用户可以进行对话,如果留空,则表示允许所有用户,如果要限制,则列表中写用户的userid
allow_users : []
# 哪些用户不可以进行对话,如果留空,则表示允许所有用户(如allow_user有配置,需满足相应条件),如果要限制,则列表中写用户的userid,黑名单优先级高于白名单
deny_users : []
# 哪些用户可以进行无限对话,如果留空,则表示只允许管理员(如max_request配置为0,则允许所有人)
# 如果要针对指定VIP用户放开限制(如max_request配置不为0),则列表中写用户的userid
vip_users : []
# 指定哪些人为此系统的管理员,如果留空,则表示没有人是管理员,如果要限制,则列表中写用户的userid
# 注意:如果下边的app_secrets为空,以及使用outgoing的方式配置机器人,这两种情况下,都表示没有人是管理员
admin_users : []
# 钉钉机器人在应用信息中的AppSecret,为了校验回调的请求是否合法,如果留空,将会忽略校验,则该接口将会存在其他人也能随意调用的安全隐患,因此强烈建议配置正确的secret,如果你的服务对接给多个机器人,这里可以配置多个机器人的secret
app_secrets : []
# 敏感词,提问时触发,则不允许提问,回答的内容中触发,则以 代替
sensitive_words : []
# 帮助信息,放在配置文件,可供自定义
help: "### 发送信息nn若您想给机器人发送信息,有如下两种方式:nn1. **群聊:** 在机器人所在群里 **@机器人** 后边跟着要提问的内容。nn2. **私聊:** 点击机器人的 **头像** 后,再点击 **发消息。** nn### 系统指令nn系统指令是一些特殊的词语,当您向机器人发送这些词语时,会触发对应的功能。nn**? 注意:系统指令,即只发指令,没有特殊标识,也没有内容。**nn以下是系统指令详情:nn| 指令 | 描述 | 示例 |n| :--------: | :------------------------------------------: | :----------------------------------------------------------: |n| **单聊** | 每次对话都是一次新的对话,没有聊天上下文联系 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_193608.jpg'><br /></details> |n| **串聊** | 带上下文联系的对话模式 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_193608.jpg'><br /></details> |n| **重置** | 重置上下文模式,回归到默认模式 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_193608.jpg'><br /></details> |n| **余额** | 查询机器人所用OpenAI账号的余额 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230304_222522.jpg'><br /></details> |n| **模板** | 查看应用内置的prompt模板 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_193827.jpg'><br /></details> |n| **图片** | 查看如何根据提示生成图片 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_194125.jpg'><br /></details> |n| **查对话** | 获取指定人员的对话历史 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_193938.jpg'><br /></details> |n| **帮助** | 获取帮助信息 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_202336.jpg'><br /></details> |nnn### 功能指令nn除去系统指令,还有一些功能指令,功能指令是直接与应用交互,达到交互目的的一种指令。nn**? 注意:功能指令,一律以 #+关键字 为开头,通常需要在关键字后边加个空格,然后再写描述或参数。**nn以下是功能指令详情nn| 指令 | 说明 | 示例 |n| :--: | :--: | :--: |n| **#图片** | 根据提示咒语生成对应图片 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230323_150547.jpg'><br /></details> |n| **#域名** | 查询域名相关信息 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_202620.jpg'><br /></details> |n| **#证书** | 查询域名证书相关信息 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_202706.jpg'><br /></details> |n| **#Linux命令** | 根据自然语言描述生成对应命令 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_214947.jpg'><br /></details> |n| **#解释代码** | 分析一段代码的功能或含义 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_215242.jpg'><br /></details> |n| **#正则** | 根据自然语言描述生成正则 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_220222.jpg'><br /></details> |n| **#周报** | 应用周报的prompt | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_214335.jpg'><br /></details> |n| **#生成sql** | 根据自然语言描述生成sql语句 | <details><br /><summary>预览</summary><br /><img src='https://cdn.jsdelivr.net/gh/eryajf/tu/img/image_20230404_221325.jpg'><br /></details> |nn如上大多数能力,都是依赖prompt模板实现,如果你有更好的prompt,欢迎提交PR。nn### 友情提示nn使用 **串聊模式** 会显著加快机器人所用账号的余额消耗速度,因此,若无保留上下文的需求,建议使用 **单聊模式。** nn即使有保留上下文的需求,也应适时使用 **重置** 指令来重置上下文。nn### 项目地址nn本项目已在GitHub开源,[查看源代码](https://github.com/eryajf/chatgpt-dingtalk)。"
# Azure OpenAI 配置
# 例如你的示例请求为: curl https://eryajf.openai.azure.com/openai/deployments/gpt-35-turbo/chat/completions?api-version=2023-03-15-preview 那么对应配置如下,如果配置完成之后还是无法正常使用,请新建应用,重新配置回调试试看
azure_on : false # 如果是true,则会走azure的openai接口
azure_resource_name : " eryajf " # 对应你的主个性域名
azure_deployment_name : " gpt-35-turbo " # 对应的是 /deployments/ 后边跟着的这个值
azure_api_version : " 2023-03-15-preview " # 对应的是请求中的 api-version 后边的值
azure_openai_token : " xxxxxxx "
# 钉钉应用鉴权凭据信息,支持多个应用。通过请求时候鉴权来识别是来自哪个机器人应用的消息
# 设置credentials 之后,即具备了访问钉钉平台绝大部分 OpenAPI 的能力;例如上传图片到钉钉平台,提升图片体验,结合 Stream 模式简化服务部署
# client_id 对应钉钉平台 AppKey/SuiteKey;client_secret 对应 AppSecret/SuiteSecret
credentials :
- client_id : " put-your-client-id-here "
client_secret : " put-your-client-secret-here "
How to better use ChatGPT: There are many cases for reference here.
? 重要重要
issue. I will open a separate issue here: Click me?, and you can check it here to help you solve the problem. If there is no one in it, please search for the historical issue (do not submit duplicate issue). Everyone is also welcome to add it.
I have created a DingTalk communication group, welcome to join the group to communicate.
This project can be established because of these open source projects:
If you think this project is helpful to you, you can invite the author to have a cup of coffee☕️
This project was once on | 2022-12-12 | 2022-12-18 | 2022-12-19 | 2022-12-20 | 2023-02-09 | 2023-02-10 | 2023-02-11 | 2023-02-12 | 2023-02-13 | 2023-02-14 | 2023-02-15 | 2023-03-04 | 2023-03-05 | 2023-03-19 | 2023-03-22 | 2023-03-25 | 2023-03-26 | 2023-03-27 | 2023-03-29, These days, board GitHub Trending. And it is still on the list, which shows the popularity of openai recently.
Erya talks about Fantasy | RiverRay | Null | Finly | Frank Cheung | Ashing Zheng | Benguang | Spicy orange |
Kim Hee @DingTalk | Swing | Null | Stoneflying | Mill Peng | Little_huang | Iblogc | WangBooth |
Mao Mao | Hugh Gao | AydenLii |