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

Beta118 #116

Merged
merged 117 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 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
627bbff
Merge branch 'main' into beta118
Hoshinonyaruko May 16, 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
41 changes: 23 additions & 18 deletions applogic/chatglm.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (app *App) ChatHandlerGlm(w http.ResponseWriter, r *http.Request) {
}
} else {
// 只获取系统提示词
systemMessage, err := prompt.FindFirstSystemMessage(history)
systemMessage, err := prompt.GetFirstSystemMessageStruct(promptstr)
if err != nil {
fmt.Println("Error:", err)
} else {
Expand Down Expand Up @@ -164,28 +164,33 @@ func (app *App) ChatHandlerGlm(w http.ResponseWriter, r *http.Request) {
fmtf.Printf("Error getting system history: %v,promptstr[%v]\n", err, promptstr)
return
}

// 处理增强QA逻辑
if config.GetEnhancedQA(promptstr) {
// 确保系统历史与用户或助手历史数量一致,如果不足,则补足空的历史记录
// 因为最后一个成员让给当前QA,所以-1
if len(systemHistory)-2 > len(userHistory) {
difference := len(systemHistory) - len(userHistory)
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
return
}

// 计算需要补足的历史记录数量
neededHistoryCount := len(systemHistory) - 2 // 最后两条留给当前QA处理
if neededHistoryCount > len(userHistory) {
// 补足用户或助手历史
difference := neededHistoryCount - len(userHistory)
for i := 0; i < difference; i++ {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
if i%2 != 0 {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
} else {
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
}
}
}

// 如果系统历史中只有一个成员,跳过覆盖逻辑,留给后续处理
if len(systemHistory) > 1 {
// 将系统历史(除最后2个成员外)附加到相应的用户或助手历史上,采用倒序方式处理最近的记录
for i := 0; i < len(systemHistory)-2; i++ {
sysMsg := systemHistory[i]
index := len(userHistory) - len(systemHistory) + i
if index >= 0 && index < len(userHistory) && (userHistory[index].Role == "user" || userHistory[index].Role == "assistant") {
userHistory[index].Text += fmt.Sprintf(" (%s)", sysMsg.Text)
}
// 附加系统历史到用户或助手历史,除了最后两条
for i := 0; i < len(systemHistory)-2; i++ {
sysMsg := systemHistory[i]
index := len(userHistory) - neededHistoryCount + i
if index >= 0 && index < len(userHistory) {
userHistory[index].Text += fmt.Sprintf(" (%s)", sysMsg.Text)
}
}
} else {
Expand Down
15 changes: 10 additions & 5 deletions applogic/ernie.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,17 @@ func (app *App) ChatHandlerErnie(w http.ResponseWriter, r *http.Request) {
// 处理增强QA逻辑
if config.GetEnhancedQA(promptstr) {
// 确保系统历史与用户或助手历史数量一致,如果不足,则补足空的历史记录
// 因为最后一个成员让给当前QA,所以-1
if len(systemHistory)-2 > len(userHistory) {
difference := len(systemHistory) - len(userHistory)
// 计算需要补足的历史记录数量
neededHistoryCount := len(systemHistory) - 2 // 最后两条留给当前QA处理
if neededHistoryCount > len(userHistory) {
// 补足用户或助手历史
difference := neededHistoryCount - len(userHistory)
for i := 0; i < difference; i++ {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
if i%2 != 0 {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
} else {
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
}
}
}

Expand Down
49 changes: 29 additions & 20 deletions applogic/tongyiqianwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
}
} else {
// 只获取系统提示词
systemMessage, err := prompt.FindFirstSystemMessage(history)
systemMessage, err := prompt.GetFirstSystemMessageStruct(promptstr)
if err != nil {
fmt.Println("Error:", err)
} else {
Expand All @@ -138,7 +138,7 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
}
}
}

// TODO: msgid是空的开始第一句也要处理 插入
// 获取历史信息
if msg.ParentMessageID != "" {
userhistory, err := app.getHistory(msg.ConversationID, msg.ParentMessageID)
Expand All @@ -159,28 +159,33 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
fmtf.Printf("Error getting system history: %v,promptstr[%v]\n", err, promptstr)
return
}

// 处理增强QA逻辑
if config.GetEnhancedQA(promptstr) {
// 确保系统历史与用户或助手历史数量一致,如果不足,则补足空的历史记录
// 因为最后一个成员让给当前QA,所以-1
if len(systemHistory)-2 > len(userHistory) {
difference := len(systemHistory) - len(userHistory)
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmt.Printf("Error getting system history: %v\n", err)
return
}

// 计算需要补足的历史记录数量
neededHistoryCount := len(systemHistory) - 2 // 最后两条留给当前QA处理
if neededHistoryCount > len(userHistory) {
// 补足用户或助手历史
difference := neededHistoryCount - len(userHistory)
for i := 0; i < difference; i++ {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
if i%2 != 0 {
userHistory = append(userHistory, structs.Message{Text: "", Role: "user"})
} else {
userHistory = append(userHistory, structs.Message{Text: "", Role: "assistant"})
}
}
}

// 如果系统历史中只有一个成员,跳过覆盖逻辑,留给后续处理
if len(systemHistory) > 1 {
// 将系统历史(除最后2个成员外)附加到相应的用户或助手历史上,采用倒序方式处理最近的记录
for i := 0; i < len(systemHistory)-2; i++ {
sysMsg := systemHistory[i]
index := len(userHistory) - len(systemHistory) + i
if index >= 0 && index < len(userHistory) && (userHistory[index].Role == "user" || userHistory[index].Role == "assistant") {
userHistory[index].Text += fmt.Sprintf(" (%s)", sysMsg.Text)
}
// 附加系统历史到用户或助手历史,除了最后两条
for i := 0; i < len(systemHistory)-2; i++ {
sysMsg := systemHistory[i]
index := len(userHistory) - neededHistoryCount + i
if index >= 0 && index < len(userHistory) {
userHistory[index].Text += fmt.Sprintf(" (%s)", sysMsg.Text)
}
}
} else {
Expand All @@ -199,6 +204,7 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {

// 构建请求到Tyqw API
apiURL := config.GetTyqwApiPath(promptstr)
fmtf.Printf("Tyqw请求地址:%v\n", apiURL)

// 构造消息历史和当前消息
messages := []map[string]interface{}{}
Expand All @@ -216,8 +222,11 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
})

var isIncrementalOutput bool
if config.GetTyqwSseType(promptstr) == 1 {
tyqwssetype := config.GetTyqwSseType(promptstr)
if tyqwssetype == 1 {
isIncrementalOutput = true
} else if tyqwssetype == 2 {
isIncrementalOutput = false
}
// 获取配置信息
useSSE := config.GetuseSse(promptstr)
Expand Down
44 changes: 44 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ func getMaxTokensHunyuanInternal(options ...string) int {
return getMaxTokensHunyuanInternal() // 递归调用内部函数,不传递任何参数
}

if maxTokensHunyuan == 0 {
return getMaxTokensHunyuanInternal()
}

return maxTokensHunyuan
}

Expand Down Expand Up @@ -316,6 +320,10 @@ func getWenxinApiPathInternal(options ...string) string {
return getWenxinApiPathInternal() // 递归调用内部函数,不传递任何参数
}

if apiPath == "" {
return getWenxinApiPathInternal()
}

return apiPath
}

Expand Down Expand Up @@ -360,6 +368,10 @@ func getGptModelInternal(options ...string) string {
return getGptModelInternal() // 递归调用内部函数,不传递任何参数
}

if gptModel == "" {
return getGptModelInternal()
}

return gptModel
}

Expand Down Expand Up @@ -2063,6 +2075,10 @@ func getTyqwApiPathInternal(options ...string) string {
return getTyqwApiPathInternal() // 递归调用内部函数,不传递任何参数
}

if apiPath == "" {
return getTyqwApiPathInternal()
}

return apiPath
}

Expand Down Expand Up @@ -2097,6 +2113,10 @@ func getTyqwMaxTokensInternal(options ...string) int {
return getTyqwMaxTokensInternal() // 递归调用内部函数,不传递任何参数
}

if maxTokens == 0 {
return getTyqwMaxTokensInternal()
}

return maxTokens
}

Expand Down Expand Up @@ -2131,6 +2151,10 @@ func getTyqwTemperatureInternal(options ...string) float64 {
return getTyqwTemperatureInternal() // 递归调用内部函数,不传递任何参数
}

if temperature == 0 {
return getTyqwTemperatureInternal()
}

return temperature
}

Expand Down Expand Up @@ -2165,6 +2189,10 @@ func getTyqwTopPInternal(options ...string) float64 {
return getTyqwTopPInternal() // 递归调用内部函数,不传递任何参数
}

if topP == 0 {
return getTyqwTopPInternal()
}

return topP
}

Expand Down Expand Up @@ -2199,6 +2227,10 @@ func getTyqwTopKInternal(options ...string) int {
return getTyqwTopKInternal() // 递归调用内部函数,不传递任何参数
}

if topK == 0 {
return getTyqwTopKInternal()
}

return topK
}

Expand Down Expand Up @@ -2233,6 +2265,10 @@ func getTyqwSseTypeInternal(options ...string) int {
return getTyqwSseTypeInternal() // 递归调用内部函数,不传递任何参数
}

if sseType == 0 {
return getTyqwSseTypeInternal()
}

return sseType
}

Expand Down Expand Up @@ -2347,6 +2383,10 @@ func getTyqwModelInternal(options ...string) string {
return getTyqwModelInternal() // 递归调用内部函数,不传递任何参数
}

if model == "" {
return getTyqwModelInternal()
}

return model
}

Expand Down Expand Up @@ -2381,6 +2421,10 @@ func getTyqwKeyInternal(options ...string) string {
return getTyqwKeyInternal() // 递归调用内部函数,不传递任何参数
}

if apiKey == "" {
return getTyqwKeyInternal()
}

return apiKey
}

Expand Down
23 changes: 23 additions & 0 deletions prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,29 @@ func FindFirstSystemMessage(history []structs.Message) (structs.Message, error)
return structs.Message{}, fmt.Errorf("no system message found in history")
}

// GetFirstSystemMessage returns the first message that is of "system" role.
func GetFirstSystemMessageStruct(basename string) (structs.Message, error) {
lock.RLock()
defer lock.RUnlock()

filename := basename + ".yml"
promptFile, exists := promptsCache[filename]
if !exists {
return structs.Message{}, fmt.Errorf("no data for file: %s", filename)
}

for _, prompt := range promptFile.Prompts {
if prompt.Role == "system" || prompt.Role == "System" {
return structs.Message{
Text: prompt.Content,
Role: prompt.Role,
}, nil
}
}

return structs.Message{}, fmt.Errorf("no system message found in file: %s", filename)
}

// 返回除了 "system" 角色之外的所有消息
// GetMessagesExcludingSystem returns a list of messages that are not of "system" role,
// randomly selecting from options separated by "||" in prompt contents.
Expand Down
2 changes: 1 addition & 1 deletion template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ settings:
tyqwRepetitionPenalty : 1.1 # 用于控制模型生成时的重复度。提高repetition_penalty时可以降低模型生成的重复度。1.0表示不做惩罚,默认为1.1。没有严格的取值范围。
tyqwTopK: 40 # 从概率最高的K个令牌中采样
tyqwSeed : 1234 # 生成时使用的随机数种子,用户控制模型生成内容的随机性。seed支持无符号64位整数,默认值为1234。在使用seed时,模型将尽可能生成相同或相似的结果,但目前不保证每次生成的结果完全相同。
tyqwSseType: 1 # 同gptSseType, 例如0代表不使用, 1代表使用
tyqwSseType: 1 # 1=默认,sse发新内容 2=sse内容递增(不推荐)
tyqwGlobalPenalty: false # 是否在全局上应用频率惩罚
tyqwStop: # 停止生成的标记列表
- "\n\nUser"
Expand Down
Loading