Skip to content

Commit 9ebc44f

Browse files
authored
Merge pull request #88 from renxiawang/master
Add a default system prompt env var
2 parents 0e36ee9 + 45264f7 commit 9ebc44f

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

chat/chat.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ package chat
33
import (
44
_ "errors"
55
"fmt"
6-
"github.com/pwh-pwh/aiwechat-vercel/client"
76
"os"
87
"strconv"
98
"strings"
109
"time"
1110

11+
"github.com/pwh-pwh/aiwechat-vercel/client"
12+
1213
"github.com/google/generative-ai-go/genai"
1314

1415
"github.com/pwh-pwh/aiwechat-vercel/db"
@@ -301,7 +302,11 @@ func GetMsgListWithDb[T ChatMsg](botType, userId string, msg T, f func(msg T) db
301302
isSupportPrompt := config.IsSupportPrompt(botType)
302303
if isSupportPrompt {
303304
prompt, err := db.GetPrompt(userId, botType)
304-
if err == nil && prompt != "" {
305+
if err != nil || prompt == "" {
306+
prompt = config.GetDefaultSystemPrompt()
307+
}
308+
309+
if prompt != "" {
305310
dbList = append(dbList, db.Msg{
306311
Role: "system",
307312
Msg: prompt,

conf/.env.sample

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# common config
22
botType=** 机器人类型 目前支持(gpt,spark,echo,qwen,gemini)例如botType=gpt
3+
defaultSystemPrompt=你是AI机器人。你会为用户提供安全,有帮助,准确的回答。
34

45
# wx config
56
WX_TOKEN=*** 微信公众号开发平台设置的token

config/config.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"fmt"
66
"os"
77
"slices"
8-
"sync"
98
"strconv"
9+
"sync"
1010

1111
"github.com/pwh-pwh/aiwechat-vercel/db"
1212
)
@@ -129,4 +129,8 @@ func GetMaxTokens() int {
129129
return 0
130130
}
131131
return maxTokens
132-
}
132+
}
133+
134+
func GetDefaultSystemPrompt() string {
135+
return os.Getenv("defaultSystemPrompt")
136+
}

0 commit comments

Comments
 (0)