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

Beta124 #123

Merged
merged 123 commits into from
May 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
123 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
f15c422
beta67
Hoshinonyaruko Apr 17, 2024
518de35
beta70
Hoshinonyaruko Apr 18, 2024
a65f07d
beta71
Hoshinonyaruko Apr 18, 2024
59d07c7
beta72
Hoshinonyaruko Apr 18, 2024
a16ea64
beta72
Hoshinonyaruko Apr 18, 2024
08d5864
beta74
Hoshinonyaruko Apr 19, 2024
9b09401
beta75
Hoshinonyaruko Apr 19, 2024
b51e185
beta76
Hoshinonyaruko Apr 20, 2024
c978654
beta77
Hoshinonyaruko Apr 21, 2024
6aa9f33
beta78
Hoshinonyaruko Apr 22, 2024
7b84a9d
beta79
Hoshinonyaruko Apr 25, 2024
4b96807
beta80
Hoshinonyaruko Apr 25, 2024
9b97146
beta81
Hoshinonyaruko Apr 25, 2024
f481e85
beta82
Hoshinonyaruko Apr 29, 2024
cb33ba5
beta83
Hoshinonyaruko Apr 29, 2024
7dbe4d5
beta85
Hoshinonyaruko Apr 29, 2024
2fb67a2
beta86
Hoshinonyaruko Apr 29, 2024
20f26c1
beta87
Hoshinonyaruko Apr 29, 2024
3146232
beta88
Hoshinonyaruko Apr 29, 2024
cbf731b
beta89
Hoshinonyaruko Apr 29, 2024
cc8a439
beta90
Hoshinonyaruko Apr 29, 2024
f56c272
beta91
Hoshinonyaruko Apr 29, 2024
c19f071
beta92
Hoshinonyaruko Apr 29, 2024
84d0513
beta93
Hoshinonyaruko Apr 29, 2024
c2f8e28
beta94
Hoshinonyaruko Apr 29, 2024
142f2fa
beta94
Hoshinonyaruko Apr 29, 2024
8828006
beta96
Hoshinonyaruko Apr 29, 2024
541a127
beta97
Hoshinonyaruko Apr 30, 2024
9d52ce8
beta98
Hoshinonyaruko Apr 30, 2024
16e0ed4
beta99
Hoshinonyaruko Apr 30, 2024
8f0e406
beta100
Hoshinonyaruko May 1, 2024
d242bc2
beta101
Hoshinonyaruko May 1, 2024
2ea5f4a
beta102
Hoshinonyaruko May 2, 2024
c208482
beta104
Hoshinonyaruko May 3, 2024
777aaa0
beta105
Hoshinonyaruko May 4, 2024
3ccedea
beta106
Hoshinonyaruko May 4, 2024
956c9a2
beta107
Hoshinonyaruko May 8, 2024
1a04702
beta108
Hoshinonyaruko May 8, 2024
d88d84b
beta109
Hoshinonyaruko May 8, 2024
e9a3788
beta110
Hoshinonyaruko May 9, 2024
a6dccf7
beta111
Hoshinonyaruko May 13, 2024
48a1d26
beta112
Hoshinonyaruko May 13, 2024
5cbd1a6
beta113
Hoshinonyaruko May 13, 2024
a8f8dbd
Merge branch 'main' of https://github.com/Hoshinonyaruko/Gensokyo-llm…
Hoshinonyaruko May 13, 2024
0ce3929
beta115
Hoshinonyaruko May 13, 2024
3c24828
beta116
Hoshinonyaruko May 14, 2024
d17b87e
beta117
Hoshinonyaruko May 14, 2024
a0d9d93
beta118
Hoshinonyaruko May 16, 2024
81c5f60
beta119
Hoshinonyaruko May 17, 2024
0bf4eae
beta120
Hoshinonyaruko May 19, 2024
dfff20e
beta121
Hoshinonyaruko May 19, 2024
6659607
beta122
Hoshinonyaruko May 19, 2024
89c92a0
beta123
Hoshinonyaruko May 19, 2024
a35581e
beta124
Hoshinonyaruko May 19, 2024
08ada5b
Merge branch 'main' into beta124
Hoshinonyaruko May 19, 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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -11,4 +11,10 @@
log

# prompts
prompts
prompts

# pics
pics

# temp
channel_temp
4 changes: 2 additions & 2 deletions acnode/acnode.go
Original file line number Diff line number Diff line change
@@ -334,7 +334,7 @@ func CheckWordIN(word string) string {
if len([]rune(word)) > 5000 {
if strings.Contains(word, "[CQ:image,file=base64://") {
// 当word包含特定字符串时原样返回
fmtf.Printf("原样返回的文本:%s", word)
//fmtf.Printf("原样返回的文本:%s", word)
return word
}
log.Printf("错误请求:字符数超过最大限制(5000字符)。内容:%s", word)
@@ -360,7 +360,7 @@ func CheckWordOUT(word string) string {
if len([]rune(word)) > 5000 {
if strings.Contains(word, "[CQ:image,file=base64://") {
// 当word包含特定字符串时原样返回
fmtf.Printf("原样返回的文本:%s", word)
//fmtf.Printf("原样返回的文本:%s", word)
return word
}
log.Printf("错误请求:字符数超过最大限制(5000字符)。内容:%s", word)
232 changes: 171 additions & 61 deletions applogic/env.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"net/http"
"net/url"
"os"
@@ -15,6 +16,7 @@ import (

"github.com/hoshinonyaruko/gensokyo-llm/config"
"github.com/hoshinonyaruko/gensokyo-llm/fmtf"
"github.com/hoshinonyaruko/gensokyo-llm/server"
"github.com/hoshinonyaruko/gensokyo-llm/structs"
"github.com/hoshinonyaruko/gensokyo-llm/utils"
)
@@ -27,112 +29,220 @@ type ResponseDataEnv struct {
}

// 分开发而且不使用sse
func GetAndSendEnv(msg string, promptstr string, message structs.OnebotGroupMessage, selfid string) {
baseurl := config.GetAIPromptkeyboardPath(promptstr)
fmtf.Printf("获取到keyboard baseurl:%v", baseurl)
// 使用net/url包来构建和编码URL
urlParams := url.Values{}
if promptstr != "" {
urlParams.Add("prompt", promptstr+"-env")
} else {
urlParams.Add("prompt", "env")
}
func (app *App) GetAndSendEnv(msg string, promptstr string, message structs.OnebotGroupMessage, selfid string) {
var responseData ResponseDataEnv
EnvContents := config.GetEnvContents(promptstr + "-env")
//如果没有人工写的EnvContents,使用ai生成,速度慢的感人,还影响对话效果和气泡keyboard
if len(EnvContents) == 0 {
// 故事模式规则 应用 PromptCoverQ
app.ApplyPromptCoverQ(promptstr+"-env", &msg, &message)
// 生成后续场景 暂时共用keyboard baseurl
baseurl := config.GetAIPromptkeyboardPath(promptstr)
fmtf.Printf("获取到keyboard baseurl:%v", baseurl)
// 使用net/url包来构建和编码URL
urlParams := url.Values{}
if promptstr != "" {
urlParams.Add("prompt", promptstr+"-env")
} else {
urlParams.Add("prompt", "env")
}

// 将查询参数编码后附加到基本URL上
fullURL := baseurl
if len(urlParams) > 0 {
fullURL += "?" + urlParams.Encode()
}
// 将查询参数编码后附加到基本URL上
fullURL := baseurl
if len(urlParams) > 0 {
fullURL += "?" + urlParams.Encode()
}

fmtf.Printf("Generated PromptKeyboard URL:%v\n", fullURL)
fmtf.Printf("Generated PromptKeyboard URL:%v\n", fullURL)

requestBody, err := json.Marshal(map[string]interface{}{
"message": msg,
"conversationId": "",
"parentMessageId": "",
"user_id": "",
})
requestBody, err := json.Marshal(map[string]interface{}{
"message": msg,
"conversationId": "",
"parentMessageId": "",
"user_id": "",
})

if err != nil {
fmt.Printf("Error marshalling request: %v\n", err)
return
}
if err != nil {
fmt.Printf("Error marshalling request: %v\n", err)
return
}

resp, err := http.Post(fullURL, "application/json", bytes.NewBuffer(requestBody))
if err != nil {
fmt.Printf("Error sending request: %v\n", err)
return
}
defer resp.Body.Close()
resp, err := http.Post(fullURL, "application/json", bytes.NewBuffer(requestBody))
if err != nil {
fmt.Printf("Error sending request: %v\n", err)
return
}
defer resp.Body.Close()

responseBody, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response body: %v\n", err)
return
}
fmt.Printf("Response: %s\n", string(responseBody))
responseBody, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Printf("Error reading response body: %v\n", err)
return
}
fmt.Printf("Response: %s\n", string(responseBody))

var responseData ResponseDataEnv
if err := json.Unmarshal(responseBody, &responseData); err != nil {
fmt.Printf("Error unmarshalling response data: %v\n", err)
return
if err := json.Unmarshal(responseBody, &responseData); err != nil {
fmt.Printf("Error unmarshalling response data: %v\n", err)
return
}
} else {
// 获取 EnvContents 数组并从中随机选择一个
envContents := config.GetEnvContents(promptstr + "-env")
if len(envContents) > 0 {
randomContentIndex := rand.Intn(len(envContents))
selectedContent := envContents[randomContentIndex]

// 获取 EnvPics 数组并从中随机选择一个
envPics := config.GetEnvPics(promptstr + "-env")
if len(envPics) > 0 {
randomPicIndex := rand.Intn(len(envPics))
selectedPic := envPics[randomPicIndex]

// 组合内容和图片链接
responseData.Response = fmt.Sprintf("%s%s", selectedContent, selectedPic)
} else {
// 如果没有图片,只添加内容
responseData.Response = selectedContent
}
} else {
// 如果没有内容,可以选择返回默认字符串或错误处理
responseData.Response = "默认内容"
}

// 打印或处理 responseData
fmt.Println("最终env响应:", responseData.Response)
}

// 处理图片
processResponseData(&responseData)
newResponse := processResponseData(responseData)

// 判断消息类型,如果是私人消息或私有群消息,发送私人消息;否则,根据配置决定是否发送群消息
if message.RealMessageType == "group_private" || message.MessageType == "private" {
utils.SendPrivateMessage(message.UserID, responseData.Response, selfid)
utils.SendPrivateMessageRaw(message.UserID, newResponse, selfid)
} else {
utils.SendGroupMessage(message.GroupID, message.UserID, responseData.Response, selfid)
utils.SendGroupMessage(message.GroupID, message.UserID, newResponse, selfid)
}
}

// processResponseData 处理响应数据并返回处理后的字符串
func processResponseData(responseData ResponseDataEnv) string {
// 判断是否使用HTTP图片地址
if config.GetUrlSendPics() {
return processWithHttpImages(responseData)
}
return processWithLocalImages(responseData)
}

func processResponseData(responseData *ResponseDataEnv) {
// processWithLocalImages 处理本地图片转为CQ码
func processWithLocalImages(responseData ResponseDataEnv) string {
currentDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting current directory: %v\n", err)
return
return responseData.Response
}
fmt.Println("Current directory:", currentDir)

// 正则表达式匹配多种图片格式
re := regexp.MustCompile(`\[(?:图片|pic|背景|image):(.*?)\]`)
// 使用更加宽泛的正则表达式匹配图片标签
re := regexp.MustCompile(`\[(?:图片|pic|背景|image):([^\]]+)\]`)
matches := re.FindAllStringSubmatch(responseData.Response, -1)

if len(matches) == 0 {
fmt.Println("No image tags found in response")
return responseData.Response // 如果没有找到匹配项,返回原始响应
}

// 创建一个新的响应字符串
newResponse := responseData.Response

for _, match := range matches {
imagePath := match[1]
fullPath := imagePath

// 如果不是绝对路径,则认为是相对路径
if !filepath.IsAbs(imagePath) {
fullPath = filepath.Join(currentDir, imagePath)
}

// 判断文件是否位于当前程序目录内
fmt.Println("Full image path:", fullPath)

if !strings.HasPrefix(fullPath, currentDir) {
fmt.Println("Image path is outside of the current directory")
return
continue // 跳过这个图片,处理下一个
}

// 检查文件后缀
if ext := filepath.Ext(imagePath); ext != ".jpg" && ext != ".png" && ext != ".gif" {
fmt.Println("Unsupported image file type")
return
ext := filepath.Ext(imagePath)
if ext != ".jpg" && ext != ".png" && ext != ".gif" {
fmt.Println("Unsupported image file type:", ext)
continue // 跳过这个图片,处理下一个
}

// 读取图片文件
imageData, err := os.ReadFile(fullPath)
if err != nil {
fmt.Printf("Error reading image file: %v\n", err)
return
continue // 跳过这个图片,处理下一个
}

// 转换为base64
base64Str := base64.StdEncoding.EncodeToString(imageData)
cqImageTag := fmt.Sprintf("[CQ:image,file=base64://%s]", base64Str)
newResponse = strings.Replace(newResponse, match[0], cqImageTag, 1)
}

return newResponse
}

// processWithHttpImages 上传图片并使用HTTP地址转为CQ码
func processWithHttpImages(responseData ResponseDataEnv) string {
currentDir, err := os.Getwd()
if err != nil {
fmt.Printf("Error getting current directory: %v\n", err)
return responseData.Response
}
fmt.Println("Current directory:", currentDir)

// 使用更加宽泛的正则表达式匹配图片标签
re := regexp.MustCompile(`\[(?:图片|pic|背景|image):([^\]]+)\]`)
matches := re.FindAllStringSubmatch(responseData.Response, -1)
if len(matches) == 0 {
fmt.Println("No image tags found in response")
return responseData.Response // 如果没有找到匹配项,返回原始响应
}

newResponse := responseData.Response
for _, match := range matches {
imagePath := match[1]
fullPath := imagePath

if !filepath.IsAbs(imagePath) {
fullPath = filepath.Join(currentDir, imagePath)
}

fmt.Println("Full image path:", fullPath)

if !strings.HasPrefix(fullPath, currentDir) {
fmt.Println("Image path is outside of the current directory")
continue // 跳过这个图片,处理下一个
}

ext := filepath.Ext(imagePath)
if ext != ".jpg" && ext != ".png" && ext != ".gif" {
fmt.Println("Unsupported image file type:", ext)
continue // 跳过这个图片,处理下一个
}

imageData, err := os.ReadFile(fullPath)
if err != nil {
fmt.Printf("Error reading image file: %v\n", err)
continue // 跳过这个图片,处理下一个
}

// 替换原始标签
responseData.Response = strings.Replace(responseData.Response, match[0], cqImageTag, 1)
base64Str := base64.StdEncoding.EncodeToString(imageData)
httpImageUrl, err := server.OriginalUploadBehavior(base64Str)
if err != nil {
continue
}

cqImageTag := fmt.Sprintf("[CQ:image,file=%s]", httpImageUrl)
newResponse = strings.Replace(newResponse, match[0], cqImageTag, 1)
}

return newResponse
}
Loading