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

Beta66 #68

Merged
merged 69 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 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
b34885f
beta64
Hoshinonyaruko Apr 13, 2024
3658648
beta65
Hoshinonyaruko Apr 13, 2024
3307439
beta66
Hoshinonyaruko Apr 15, 2024
2fa1f05
Merge branch 'main' into beta66
Hoshinonyaruko Apr 15, 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
5 changes: 4 additions & 1 deletion applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
requestmsg = acnode.CheckWordIN(requestmsg)
}

fmtf.Printf("实际请求conversation端点内容:%v\n", requestmsg)
fmtf.Printf("实际请求conversation端点内容:[%v]%v\n", message.UserID, requestmsg)

requestBody, err := json.Marshal(map[string]interface{}{
"message": requestmsg,
Expand Down Expand Up @@ -442,6 +442,9 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, newPart)
}
} else {
//流的最后一次是完整结束的
fmtf.Printf("A完整信息: %s(sse完整结束)\n", response)
}

} else if response != "" {
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func main() {
testFlag := flag.Bool("test", false, "Run the test script, test.txt中的是虚拟信息,一行一条")
ymlPath := flag.String("yml", "", "指定config.yml的路径")
vFlag := flag.Bool("v", false, "Run ProcessSensitiveWordsV2")
tidyFlag := flag.Bool("tidy", false, "Run tidylog")
flag.Parse()

// 如果用户指定了-yml参数
Expand Down Expand Up @@ -176,6 +177,13 @@ func main() {
}
}

// 根据-tidy参数决定是否运行utils.Tidylogs()
if *tidyFlag {
utils.Tidylogs()
fmtf.Println("日志整理完毕")
return
}

http.HandleFunc("/gensokyo", app.GensokyoHandler)
port := config.GetPort()
portStr := fmtf.Sprintf(":%d", port)
Expand Down
125 changes: 125 additions & 0 deletions utils/log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package utils

import (
"bufio"
"bytes"
"fmt"
"os"
"path/filepath"
"strings"
)

func Tidylogs() {
logDir := "./log"
files, err := os.ReadDir(logDir)
if err != nil {
fmt.Println("Error reading log directory:", err)
return
}

for _, file := range files {
fileName := file.Name()
if filepath.Ext(fileName) == ".log" && !strings.Contains(fileName, "-tidy") {
processLogFile(filepath.Join(logDir, fileName))
}
}
}

func processLogFile(filePath string) {
outputFilePath := strings.TrimSuffix(filePath, filepath.Ext(filePath)) + "-tidy.log"

// Check if the tidy file already exists
if _, err := os.Stat(outputFilePath); err == nil {
fmt.Println("Skipping as tidy file already exists:", outputFilePath)
return // File exists, skip processing
} else if !os.IsNotExist(err) {
fmt.Println("Error checking output file:", err)
return // Some other error occurred when checking the file
}

// Read the entire file
data, err := os.ReadFile(filePath)
if err != nil {
fmt.Println("Error reading file:", err)
return
}

// Define newline sequences and placeholder
crlf := []byte{'\r', '\n'}
lf := []byte{'\n'}
placeholder := []byte{0xFF, 0xFE} // Safe placeholder for double newlines

// Handle different newline formats
doubleCRLF := append(crlf, crlf...)
doubleLF := append(lf, lf...)

// Replace double newlines with a placeholder
data = bytes.ReplaceAll(data, doubleCRLF, placeholder)
data = bytes.ReplaceAll(data, doubleLF, placeholder)

// Remove standalone newlines
data = bytes.ReplaceAll(data, crlf, []byte{})
data = bytes.ReplaceAll(data, lf, []byte{})

// Replace placeholders with a single newline (LF)
data = bytes.ReplaceAll(data, placeholder, lf)

outputFile, err := os.Create(outputFilePath)
if err != nil {
fmt.Println("Error creating output file:", err)
return
}
defer outputFile.Close()

// Scan through the modified content
scanner := bufio.NewScanner(bytes.NewReader(data))
for scanner.Scan() {
line := scanner.Text()
// Process each line based on specific patterns
if strings.Contains(line, "实际请求conversation端点内容:") {
formatAndWriteQuestionLine(line, outputFile)
}
if strings.Contains(line, "A完整信息:") {
formatAndWriteAnswerLine(line, outputFile)
}
}

if err := scanner.Err(); err != nil {
fmt.Println("Error scanning content:", err)
}
}

func formatAndWriteQuestionLine(line string, outputFile *os.File) {
prefix := "实际请求conversation端点内容:"
startIndex := strings.Index(line, prefix)
if startIndex != -1 {
// 找到前缀后,提取从这个位置开始直到行尾的内容
messageStart := startIndex + len(prefix)
message := line[messageStart:] // 从"实际请求conversation端点内容:"后的内容开始提取到行尾
message = strings.TrimSpace(message) // 去除前后空格
formattedLine := fmt.Sprintf("Q:%s\n", message) // 格式化行

// 写入到输出文件
_, err := outputFile.WriteString(formattedLine)
if err != nil {
fmt.Println("Error writing to output file:", err)
}
}
}

func formatAndWriteAnswerLine(line string, outputFile *os.File) {
prefix := "A完整信息:"
startIndex := strings.Index(line, prefix) // 查找"A完整信息:"的开始位置
if startIndex != -1 {
// 找到"A完整信息:"后,提取从这个位置开始直到行尾的内容
messageStart := startIndex + len(prefix)
message := line[messageStart:] // 从"A完整信息:"后的内容开始提取到行尾
formattedLine := fmt.Sprintf("A:%s\n", strings.TrimSpace(message)) // 格式化并去除前后空白字符

// 写入到输出文件
_, err := outputFile.WriteString(formattedLine)
if err != nil {
fmt.Println("Error writing to output file:", err)
}
}
}
1 change: 1 addition & 0 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func SendPrivateMessageSSE(UserID int64, message structs.InterfaceBody) error {
if message.Content == "" {
message.Content = " "
fmtf.Printf("过滤空SendPrivateMessageSSE,可能是llm api只发了换行符.")
return nil
}

// 构造请求体,包括InterfaceBody
Expand Down
Loading