Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta63 #64

Merged
merged 65 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
ea4bcc6
beta1
Hoshinonyaruko Jan 21, 2024
5002a28
beta2
Hoshinonyaruko Jan 21, 2024
969841e
beta3
Hoshinonyaruko Jan 21, 2024
a2989c2
beta4
Hoshinonyaruko Jan 21, 2024
611cd8b
beta5
Hoshinonyaruko Jan 21, 2024
dbad42b
beta6
Hoshinonyaruko Jan 21, 2024
4f8895e
beta7
Hoshinonyaruko Jan 21, 2024
30a9cab
beta8
Hoshinonyaruko Jan 21, 2024
461d879
beta9
Hoshinonyaruko Jan 21, 2024
c90c2ee
beta10
Hoshinonyaruko Jan 21, 2024
5227c32
beta11
Hoshinonyaruko Jan 21, 2024
8e14e56
beta12
Hoshinonyaruko Jan 21, 2024
6adfb7f
beta13
Hoshinonyaruko Jan 21, 2024
b04f6c0
beta14
Hoshinonyaruko Jan 21, 2024
649e740
beta15
Hoshinonyaruko Jan 21, 2024
d55cf29
beta16
Hoshinonyaruko Jan 21, 2024
1cc351e
beta16
Hoshinonyaruko Jan 21, 2024
f1a373e
beta19
Hoshinonyaruko Jan 21, 2024
cbf2fe1
beta20
Hoshinonyaruko Jan 21, 2024
3485bfc
beta21
Hoshinonyaruko Jan 21, 2024
3e3bb1a
beta22
Hoshinonyaruko Jan 21, 2024
2e4f3fa
beta23
Hoshinonyaruko Mar 29, 2024
f74075d
beta24
Hoshinonyaruko Mar 29, 2024
f3913cf
beta25
Hoshinonyaruko Mar 29, 2024
4cfb51a
beta27
Hoshinonyaruko Mar 30, 2024
d9b26c0
beta28
Hoshinonyaruko Mar 31, 2024
19da709
beta29
Hoshinonyaruko Mar 31, 2024
e06dcbf
merge
Hoshinonyaruko Mar 31, 2024
c76923e
beta30
Hoshinonyaruko Mar 31, 2024
9ae21da
beta31
Hoshinonyaruko Apr 1, 2024
4f333bc
merge
Hoshinonyaruko Apr 1, 2024
5acba8f
beta33
Hoshinonyaruko Apr 1, 2024
c637fcd
beta34
Hoshinonyaruko Apr 1, 2024
4e85b37
beta35
Hoshinonyaruko Apr 1, 2024
970948e
beta36
Hoshinonyaruko Apr 1, 2024
14271c3
beta37
Hoshinonyaruko Apr 1, 2024
6154d1a
beta38
Hoshinonyaruko Apr 1, 2024
d5be5e6
beta39
Hoshinonyaruko Apr 3, 2024
54afe18
beta40
Hoshinonyaruko Apr 3, 2024
0b71855
beta41
Hoshinonyaruko Apr 3, 2024
8c5f9a3
merge
Hoshinonyaruko Apr 3, 2024
cf752d4
beta42
Hoshinonyaruko Apr 3, 2024
3698824
beta43
Hoshinonyaruko Apr 3, 2024
1e9c189
beta44
Hoshinonyaruko Apr 3, 2024
2adb4ac
beta45
Hoshinonyaruko Apr 4, 2024
79eb713
beta45
Hoshinonyaruko Apr 4, 2024
064f0d0
beta45
Hoshinonyaruko Apr 4, 2024
5a4a59e
beta46
Hoshinonyaruko Apr 5, 2024
df30a32
beta46
Hoshinonyaruko Apr 5, 2024
c920893
beat48
Hoshinonyaruko Apr 7, 2024
3491d5d
beta49
Hoshinonyaruko Apr 8, 2024
575b2ca
beta50
Hoshinonyaruko Apr 8, 2024
4c4bbaa
beta51
Hoshinonyaruko Apr 8, 2024
2ea728b
beta52
Hoshinonyaruko Apr 8, 2024
82bf952
beta53
Hoshinonyaruko Apr 8, 2024
869685c
beta54
Hoshinonyaruko Apr 9, 2024
1f3646e
beta55
Hoshinonyaruko Apr 9, 2024
d6bbadf
beta57
Hoshinonyaruko Apr 10, 2024
fc5086c
beta58
Hoshinonyaruko Apr 10, 2024
602ff65
beta59
Hoshinonyaruko Apr 10, 2024
a82538d
Merge branch 'main' of https://github.com/Hoshinonyaruko/Gensokyo-llm…
Hoshinonyaruko Apr 10, 2024
6433600
beta61
Hoshinonyaruko Apr 10, 2024
9ce88b3
beta62
Hoshinonyaruko Apr 12, 2024
b53617b
beta63
Hoshinonyaruko Apr 12, 2024
ff64c69
beta63
Hoshinonyaruko Apr 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
fmtf.Printf("消息进入替换前:%v", requestmsg)
}

// 繁体转换简体 安全策略
requestmsg, err = utils.ConvertTraditionalToSimplified(requestmsg)
if err != nil {
fmtf.Printf("繁体转换简体失败:%v", err)
}

// 替换in替换词规则
if config.GetSensitiveMode() {
requestmsg = acnode.CheckWordIN(requestmsg)
Expand Down Expand Up @@ -428,7 +434,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
} else {
//最后一条了
messageSSE := structs.InterfaceBody{
Content: newPart + "\n",
Content: newPart,
State: 11,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
Expand All @@ -449,7 +455,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
} else {
//最后一条了
messageSSE := structs.InterfaceBody{
Content: response + "\n",
Content: response,
State: 11,
}
utils.SendPrivateMessageSSE(message.UserID, messageSSE)
Expand Down Expand Up @@ -497,9 +503,14 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
promptkeyboard = GetPromptKeyboardAI("Q" + newmsg + "A" + response)
}

// 使用acnode.CheckWordOUT()过滤promptkeyboard中的每个字符串
for i, item := range promptkeyboard {
promptkeyboard[i] = acnode.CheckWordOUT(item)
}

//最后一条了
messageSSE := structs.InterfaceBody{
Content: " " + "\n",
Content: " ",
State: 20,
PromptKeyboard: promptkeyboard,
}
Expand Down Expand Up @@ -593,7 +604,7 @@ func processMessage(response string, msg structs.OnebotGroupMessage, newmesssage

for _, char := range response {
messageBuilder.WriteRune(char)
if utils.ContainsRune(punctuations, char) {
if utils.ContainsRune(punctuations, char, msg.GroupID) {
// 达到标点符号,发送累积的整个消息
if messageBuilder.Len() > 0 {
accumulatedMessage := messageBuilder.String()
Expand All @@ -610,7 +621,7 @@ func processMessage(response string, msg structs.OnebotGroupMessage, newmesssage
//CallbackData := GetStringById(lastMessageID)
uerid := strconv.FormatInt(msg.UserID, 10)
messageSSE := structs.InterfaceBody{
Content: accumulatedMessage + "\n",
Content: accumulatedMessage,
State: 1,
ActionButton: 10,
CallbackData: uerid,
Expand All @@ -619,7 +630,7 @@ func processMessage(response string, msg structs.OnebotGroupMessage, newmesssage
} else {
//SSE的前半部分
messageSSE := structs.InterfaceBody{
Content: accumulatedMessage + "\n",
Content: accumulatedMessage,
State: 1,
}
utils.SendPrivateMessageSSE(msg.UserID, messageSSE)
Expand Down
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Settings struct {
UseFunctionPromptkeyboard bool `yaml:"useFunctionPromptkeyboard"`
AIPromptkeyboardPath string `yaml:"AIPromptkeyboardPath"`
UseAIPromptkeyboard bool `yaml:"useAIPromptkeyboard"`
SplitByPuntuationsGroup int `yaml:"splitByPuntuationsGroup"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -341,6 +342,16 @@ func GetSplitByPuntuations() int {
return 0
}

// 获取SplitByPuntuationsGroup
func GetSplitByPuntuationsGroup() int {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.SplitByPuntuationsGroup
}
return 0
}

// 获取HunyuanType
func GetHunyuanType() int {
mu.Lock()
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ require (
require github.com/abadojack/whatlanggo v1.0.1

require (
github.com/fsnotify/fsnotify v1.7.0
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d // indirect
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d // indirect
github.com/longbridgeapp/opencc v0.3.11 // indirect
)

require (
github.com/fsnotify/fsnotify v1.7.0
golang.org/x/sys v0.4.0 // indirect
)
22 changes: 22 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
github.com/abadojack/whatlanggo v1.0.1 h1:19N6YogDnf71CTHm3Mp2qhYfkRdyvbgwWdd2EPxJRG4=
github.com/abadojack/whatlanggo v1.0.1/go.mod h1:66WiQbSbJBIlOZMsvbKe5m6pzQovxCH9B/K8tQB2uoc=
github.com/adamzy/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:PRWNwWq0yifz6XDPZu48aSld8BWwBfr2JKB2bGWiEd4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d h1:qSmEGTgjkESUX5kPMSGJ4pcBUtYVDdkNzMrjQyvRvp0=
github.com/liuzl/cedar-go v0.0.0-20170805034717-80a9c64b256d/go.mod h1:x7SghIWwLVcJObXbjK7S2ENsT1cAcdJcPl7dRaSFog0=
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d h1:hTRDIpJ1FjS9ULJuEzu69n3qTgc18eI+ztw/pJv47hs=
github.com/liuzl/da v0.0.0-20180704015230-14771aad5b1d/go.mod h1:7xD3p0XnHvJFQ3t/stEJd877CSIMkH/fACVWen5pYnc=
github.com/longbridgeapp/opencc v0.3.11 h1:MfozRXTRmchceDyVsJ/JoOsuXb7AqtjF7RUtWUa0cQo=
github.com/longbridgeapp/opencc v0.3.11/go.mod h1:jRuKtq8eLA+cZUu75XgMvkB/hFSXJbZDmij0v29lNaY=
github.com/mattn/go-sqlite3 v1.14.19 h1:fhGleo2h1p8tVChob4I9HpmVFIAkKGpiukdrgQbWfGI=
github.com/mattn/go-sqlite3 v1.14.19/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839 h1:VGVFNQDaUpDsPkJrh8I9qOxHZ1yj5sJmg9ngsUvTAHM=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.839/go.mod h1:r5r4xbfxSaeR04b166HGsBa/R4U3SueirEUpXGuw+Q0=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ AhoCorasick算法实现的超高效文本IN-Out替换规则,可大量替换n

命令行 -mlog 将当前储存的所有日志进行QA格式化,每日审验,从实际场景提炼新安全规则,不断增加安全性,第六重安全措施

语言过滤,允许llm只接受所指定的语言,在自己擅长的领域进行防守,第七重安全措施
语言过滤,允许llm只接受所指定的语言,自动将繁体转换为简体应用安全规则,在自己擅长的领域进行防守,第七重安全措施

提示词长度限制,用最原始的方式控制安全,阻止恶意用户构造长提示词,第八重安全措施

Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ settings:
thirdA : [""] #可空
groupMessage : true #是否响应群信息
splitByPuntuations : 40 #截断率,仅在sse时有效,100则代表每句截断
splitByPuntuationsGroup : 10 #截断率(群),仅在sse时有效,100则代表每句截断
sensitiveMode : false #是否开启敏感词替换
sensitiveModeType : 0 #0=只过滤用户输入 1=输出也进行过滤
defaultChangeWord : "*" #默认的屏蔽词替换,你可以在sensitive_words.txt的####后修改为自己需要,可以用记事本批量替换
Expand Down
29 changes: 29 additions & 0 deletions utils/t2s.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package utils

import (
"log"
"sync"

"github.com/longbridgeapp/opencc"
)

// Global converter instance
var converter *opencc.OpenCC
var once sync.Once

// init function to initialize the global converter
func init() {
var err error
once.Do(func() {
// Initialize the converter with the appropriate conversion configuration
converter, err = opencc.New("t2s")
if err != nil {
log.Fatalf("Failed to initialize OpenCC converter: %v", err)
}
})
}

// ConvertTraditionalToSimplified converts traditional Chinese to simplified Chinese.
func ConvertTraditionalToSimplified(text string) (string, error) {
return converter.Convert(text)
}
14 changes: 11 additions & 3 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,18 @@ func GetKey(groupid int64, userid int64) string {
}

// 随机的分布发送
func ContainsRune(slice []rune, value rune) bool {
func ContainsRune(slice []rune, value rune, groupid int64) bool {
var probability int
if groupid == 0 {
// 获取概率百分比
probability = config.GetSplitByPuntuations()
} else {
// 获取概率百分比
probability = config.GetSplitByPuntuationsGroup()
}

for _, item := range slice {
if item == value {
// 获取概率百分比
probability := config.GetSplitByPuntuations()
// 将概率转换为0到1之间的浮点数
probabilityPercentage := float64(probability) / 100.0
// 生成一个0到1之间的随机浮点数
Expand Down Expand Up @@ -152,6 +159,7 @@ func SendGroupMessage(groupID int64, userID int64, message string) error {
"user_id": userID,
"message": message,
})
fmtf.Printf("发群信息请求:%v", string(requestBody))
if err != nil {
return fmtf.Errorf("failed to marshal request body: %w", err)
}
Expand Down
Loading