Skip to content

Commit 72ebd42

Browse files
committed
feat: support system message
1 parent 324a8b4 commit 72ebd42

File tree

5 files changed

+46
-7
lines changed

5 files changed

+46
-7
lines changed

README.md

+32-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,45 @@
11
# WeeChatGPT
22

3-
将 ChatGPT 集成到微信个人号。基于 [openwechat](https://github.com/eatmoreapple/openwechat)
3+
将 ChatGPT 集成到微信个人号。基于 [openwechat](https://github.com/eatmoreapple/openwechat),支持网页版和桌面版微信
44

55
## 运行方法
66

77
1. 前往 [Releases](https://github.com/AnotiaWang/WeeChatGPT/releases/latest) ,根据你使用的平台,下载最新版本的 WeeChatGPT。
88
2. 先运行一次 WeeChatGPT,程序会生成配置文件 `config.yml`,然后根据文件中的提示,填写配置。
99
3. 再次运行 WeeChatGPT,会显示微信的登录二维码链接,在浏览器中打开它,扫码登录微信即可。
1010

11-
### 提示
11+
![](https://i.328888.xyz/2023/03/13/v602P.png)
12+
13+
### 说明
1214

1315
- 程序支持热登录,如果两次登录之间的间隔较短,可以自动登录。
1416
- 建议将群组添加到通讯录,否则机器人可能无法获取到群组信息,导致回复失败。
1517
- 目前仅测试过 gpt-3.5-turbo 模型的支持。
18+
- 目前不支持多轮对话。
19+
20+
如果无法访问 OpenAI 的 API,可以考虑我自建的 Nginx 反代 https://proxy.api.ataw.top/openai/v1/chat/completions 。没有暗箱操作,请放心使用。
21+
22+
<details>
23+
<summary>Nginx 反代配置</summary>
24+
25+
```text
26+
server {
27+
listen 80;
28+
listen 443 ssl http2;
29+
server_name proxy.api.ataw.top;
30+
31+
ssl_certificate /etc/nginx/conf.d/proxy.api.ataw.top_bundle.crt;
32+
ssl_certificate_key /etc/nginx/conf.d/proxy.api.ataw.top.key;
33+
ssl_session_timeout 5m;
34+
ssl_protocols TLSv1.2 TLSv1.3;
35+
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
36+
ssl_prefer_server_ciphers on;
37+
38+
location /openai/ {
39+
proxy_pass https://api.openai.com/;
40+
proxy_set_header Host api.openai.com;
41+
proxy_set_header X-Real-IP $remote_addr;
42+
}
43+
}
44+
```
45+
</details>

build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o ./dist/weechatbot_linux_amd64
33
echo Building for darwin_amd64...
44
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o ./dist/weechatbot_darwin_amd64 .
55
echo Building for windows_amd64...
6-
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./dist/weechatbot_windows_amd64 .
6+
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o ./dist/weechatbot_windows_amd64.exe .

handler/message.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func Default(ctx context.Context) openwechat.MessageHandler {
2323
if strings.Index(msg.Content, config.OpenAI.Prefix) == 0 {
2424
log.Println("found message match: " + msg.Content)
2525
query := msg.Content[4:]
26-
response, err := model.ChatCompletion(ctx, model.MakeMessage(query))
26+
response, err := model.ChatCompletion(ctx, model.MakeMessage(query, config.OpenAI.SystemMsg))
2727
if err != nil {
2828
log.Println("ChatCompletion error: " + err.Error())
2929
return

model/chat_completion.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,15 @@ type ChatCompletionResponse struct {
4848
}
4949
}
5050

51-
func MakeMessage(content string) []Message {
51+
func MakeMessage(content string, sysMsg string) []Message {
5252
messages := make([]Message, 0)
53-
// TODO: config.OpenAI.SystemMessage
53+
54+
if sysMsg != "" {
55+
messages = append(messages, Message{
56+
Role: "system",
57+
Content: sysMsg,
58+
})
59+
}
5460
messages = append(messages, Message{
5561
Role: "user",
5662
Content: content,

model/config.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type OpenAIConfig struct {
2929
Model string `yaml:"model"`
3030
SecretKey string `yaml:"secretKey"`
3131
Prefix string `yaml:"prefix"`
32+
SystemMsg string `yaml:"systemMsg"`
3233
}
3334

3435
func InitConfigFile() error {
@@ -40,10 +41,12 @@ openai:
4041
endpoint: https://api.openai.com/v1/chat/completions
4142
# 模型
4243
model: gpt-3.5-turbo
43-
# OpenAI SecretKey (SK)
44+
# OpenAI SecretKey ( https://platform.openai.com/account/api-keys )
4445
secretKey:
4546
# 前缀
4647
prefix: ChatGPT,
48+
# 设定身份,如:你是 ChatGPT,OpenAI 发布的语言模型
49+
systemMsg:
4750
`
4851
err := os.WriteFile("./config.yml", []byte(str), 0644)
4952
if err != nil {

0 commit comments

Comments
 (0)