Skip to content

Commit 1061178

Browse files
authored
feat: 添加stream模式的支持 (#230)
1 parent 05116ce commit 1061178

9 files changed

Lines changed: 350 additions & 144 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<p align='center'>
2929
😀企联AI共创计划正式开启😀
3030
</p>
31-
31+
3232
<p align='center'>
3333
https://fork-way.feishu.cn/docx/Gvztd1iVXoXOsVxF2ujcnPPenDf
3434
</p>
@@ -46,8 +46,8 @@
4646
查看更多内容: https://connect-ai.forkway.cn
4747

4848
企业客户咨询:13995928702(River)
49-
50-
49+
50+
5151
<p> 🌉 基于GO语言实现的钉钉集成ChatGPT机器人 🌉</p>
5252

5353
[![Auth](https://img.shields.io/badge/Auth-eryajf-ff69b4)](https://github.com/eryajf)
@@ -101,14 +101,14 @@ AIGC的热潮正在各行各业掀起巨大的变革,我们看到各大社群
101101
- A奖励:小队完成度奖励,鼓励小队长参与项目,能够在指定时间内完成课题规定的基本内容,队长应获得一定的奖励。
102102
- B奖励:项目优秀度奖励,根据项目复杂度、组内配合度、产品创意度,以及期中和期末用户体验打分,评选出部分优秀项目的队长和核心队员,并给予相应奖励。
103103
- C奖励:成员活跃度奖励,考虑到设计和测试身份的特殊性,无法单独带领项目。因此,我们将评选出优秀设计师和优秀测试反馈员,以表彰他们在项目中的积极参与和贡献。
104-
104+
105105
做出下面奖励安排
106106
- A奖励项目完成度:京东E卡300 * 10
107107
- B奖励项目优秀度:
108108
- 杰出奖: iPhone14 * 1 + 京东E卡300 * 3
109109
- 优秀奖: PS5 * 1 + 京东E卡300 * 3
110110
- C奖励成员活跃度:京东E卡300 * 4
111-
111+
112112
我们队员有
113113
- [EX-chatGPT](https://github.com/circlestarzero/EX-chatGPT)[ChatPaper的维护者](https://github.com/kaixindelele/ChatPaper)-->[cc](https://github.com/circlestarzero)
114114
- [钉钉GPT的维护者](https://github.com/eryajf/chatgpt-dingtalk)-->[eryajf](https://github.com/eryajf)
@@ -222,7 +222,7 @@ $ docker run -itd --name chatgpt -p 8090:8090 \
222222
-e DEFAULT_MODE="单聊" -e MAX_REQUEST=0 -e PORT=8090 \
223223
-e SERVICE_URL="你当前服务外网可访问的URL" -e CHAT_TYPE="0" \
224224
-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" \
225-
-e SENSITIVE_WORDS="aa,bb" \
225+
-e SENSITIVE_WORDS="aa,bb" -e RUN_MODE="http" \
226226
-e AZURE_ON="false" -e AZURE_API_VERSION="" -e AZURE_RESOURCE_NAME="" \
227227
-e AZURE_DEPLOYMENT_NAME="" -e AZURE_OPENAI_TOKEN="" \
228228
-e DINGTALK_CREDENTIALS="your_client_id1:secret1,your_client_id2:secret2" \
@@ -486,6 +486,8 @@ $ go run main.go
486486
log_level: "info"
487487
# openai api_key
488488
api_key: "xxxxxxxxx"
489+
# 运行模式,http 或者 stream ,当前默认为http,等stream全面开放之后,这个模式将会是默认的启动模式
490+
run_mode: "http"
489491
# 如果你使用官方的接口地址 https://api.openai.com,则留空即可,如果你想指定请求url的地址,可通过这个参数进行配置,注意需要带上 http 协议
490492
base_url: ""
491493
# 指定模型,默认为 gpt-3.5-turbo , 可选参数有: "gpt-4-0314", "gpt-4", "gpt-3.5-turbo-0301", "gpt-3.5-turbo",如果使用gpt-4,请确认自己是否有接口调用白名单

config.example.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
log_level: "info"
33
# openai api_key
44
api_key: "xxxxxxxxx"
5+
# 运行模式,http 或者 stream ,当前默认为http,等stream全面开放之后,这个模式将会是默认的启动模式
6+
run_mode: "http"
57
# 如果你使用官方的接口地址 https://api.openai.com,则留空即可,如果你想指定请求url的地址,可通过这个参数进行配置,注意需要带上 http 协议
68
base_url: ""
79
# 指定模型,默认为 gpt-3.5-turbo , 可选参数有: "gpt-4-0314", "gpt-4", "gpt-3.5-turbo-0301", "gpt-3.5-turbo",如果使用gpt-4,请确认自己是否有接口调用白名单

config/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ type Configuration struct {
2525
LogLevel string `yaml:"log_level"`
2626
// gpt apikey
2727
ApiKey string `yaml:"api_key"`
28+
// 运行模式
29+
RunMode string `yaml:"run_mode"`
2830
// 请求的 URL 地址
2931
BaseURL string `yaml:"base_url"`
3032
// 使用模型
@@ -97,6 +99,10 @@ func LoadConfig() *Configuration {
9799
if apiKey != "" {
98100
config.ApiKey = apiKey
99101
}
102+
runMode := os.Getenv("RUN_MODE")
103+
if runMode != "" {
104+
config.RunMode = runMode
105+
}
100106
baseURL := os.Getenv("BASE_URL")
101107
if baseURL != "" {
102108
config.BaseURL = baseURL
@@ -216,6 +222,9 @@ func LoadConfig() *Configuration {
216222
if config.LogLevel == "" {
217223
config.LogLevel = "info"
218224
}
225+
if config.RunMode == "" {
226+
config.LogLevel = "http"
227+
}
219228
if config.Model == "" {
220229
config.Model = "gpt-3.5-turbo"
221230
}

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
environment:
99
LOG_LEVEL: "info" # 应用的日志级别 info/debug
1010
APIKEY: xxxxxx # 你的 api_key
11+
RUN_MODE: "" # 运行模式,http 或者 stream ,当前默认为http,等stream全面开放之后,这个模式将会是默认的启动模式
1112
BASE_URL: "" # 如果你使用官方的接口地址 https://api.openai.com,则留空即可,如果你想指定请求url的地址,可通过这个参数进行配置,注意需要带上 http 协议
1213
MODEL: "gpt-3.5-turbo" # 指定模型,默认为 gpt-3.5-turbo , 可选参数有: "gpt-4-0314", "gpt-4", "gpt-3.5-turbo-0301", "gpt-3.5-turbo",如果使用gpt-4,请确认自己是否有接口调用白名单
1314
SESSION_TIMEOUT: 600 # 会话超时时间,默认600秒,在会话时间内所有发送给机器人的信息会作为上下文

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/gin-gonic/gin v1.9.0
88
github.com/glebarez/sqlite v1.7.0
99
github.com/go-resty/resty/v2 v2.7.0
10+
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.0.1
1011
github.com/patrickmn/go-cache v2.1.0+incompatible
1112
github.com/sashabaranov/go-openai v1.6.1
1213
github.com/solywsh/chatgpt v0.0.14
@@ -34,6 +35,7 @@ require (
3435
github.com/goccy/go-json v0.10.0 // indirect
3536
github.com/google/pprof v0.0.0-20230406165453-00490a63f317 // indirect
3637
github.com/google/uuid v1.3.0 // indirect
38+
github.com/gorilla/websocket v1.5.0 // indirect
3739
github.com/jinzhu/inflection v1.0.0 // indirect
3840
github.com/jinzhu/now v1.1.5 // indirect
3941
github.com/json-iterator/go v1.1.12 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ github.com/google/pprof v0.0.0-20230406165453-00490a63f317 h1:hFhpt7CTmR3DX+b4R1
6565
github.com/google/pprof v0.0.0-20230406165453-00490a63f317/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk=
6666
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
6767
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
68+
github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc=
69+
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
6870
github.com/ianlancetaylor/demangle v0.0.0-20220319035150-800ac71e25c2/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w=
6971
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
7072
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
@@ -99,6 +101,8 @@ github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
99101
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
100102
github.com/muesli/termenv v0.15.1 h1:UzuTb/+hhlBugQz28rpzey4ZuKcZ03MeKsoG7IJZIxs=
101103
github.com/muesli/termenv v0.15.1/go.mod h1:HeAQPTzpfs016yGtA4g00CsdYnVLJvxsS4ANqrZs2sQ=
104+
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.0.1 h1:F7c4ZWg5FuL0giOVg0slzPmYLwbuQqTjsu5BkUL6VEU=
105+
github.com/open-dingtalk/dingtalk-stream-sdk-go v0.0.1/go.mod h1:ln3IqPYYocZbYvl9TAOrG/cxGR9xcn4pnZRLdCTEGEU=
102106
github.com/pandodao/tokenizer-go v0.2.0 h1:NhfI8fGvQkDld2cZCag6NEU3pJ/ugU9zoY1R/zi9YCs=
103107
github.com/pandodao/tokenizer-go v0.2.0/go.mod h1:t6qFbaleKxbv0KNio2XUN/mfGM5WKv4haPXDQWVDG00=
104108
github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc=

0 commit comments

Comments
 (0)