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

Beta116 #114

Merged
merged 114 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
114 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
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
6 changes: 3 additions & 3 deletions applogic/chatglm.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ func (app *App) ChatHandlerGlm(w http.ResponseWriter, r *http.Request) {
}

// 获取配置信息
apiKey := config.GetGlmApiKey()
apiKey := config.GetGlmApiKey(promptstr)
// 创建请求体的映射结构
requestBody := map[string]interface{}{
"model": config.GetGlmModel(),
"model": config.GetGlmModel(promptstr),
"messages": messages,
"do_sample": config.GetGlmDoSample(),
"stream": config.GetuseSse(promptstr),
"temperature": config.GetGlmTemperature(),
"top_p": config.GetGlmTopP(),
"max_tokens": config.GetGlmMaxTokens(),
"max_tokens": config.GetGlmMaxTokens(promptstr),
"stop": config.GetGlmStop(),
//"tools": config.GetGlmTools(), 不太清楚参数格式
"tool_choice": config.GetGlmToolChoice(),
Expand Down
55 changes: 40 additions & 15 deletions applogic/gensokyo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"net/url"
"strconv"
"strings"
"sync"

"github.com/hoshinonyaruko/gensokyo-llm/acnode"
"github.com/hoshinonyaruko/gensokyo-llm/config"
Expand All @@ -20,7 +21,8 @@ import (
)

var newmsgToStringMap = make(map[string]string)
var stringToIndexMap = make(map[string]int)
var stringToIndexMap sync.Map
var processMessageMu sync.Mutex

// RecordStringById 根据id记录一个string
func RecordStringByNewmsg(id, value string) {
Expand All @@ -38,20 +40,30 @@ func GetStringByNewmsg(newmsg string) string {

// IncrementIndex 为给定的字符串递增索引
func IncrementIndex(s string) int {
// 检查map中是否已经有这个字符串的索引
if _, exists := stringToIndexMap[s]; !exists {
// 如果不存在,初始化为0
stringToIndexMap[s] = 0
// 尝试从map中获取值,如果不存在则初始化为0
val, loaded := stringToIndexMap.LoadOrStore(s, 0)
if !loaded {
// 如果这是一个新的键,我们现在将其值设置为1
stringToIndexMap.Store(s, 1)
return 1
}
// 递增索引
stringToIndexMap[s]++
// 返回新的索引值
return stringToIndexMap[s]

// 如果已存在,递增索引
newVal := val.(int) + 1
stringToIndexMap.Store(s, newVal)
return newVal
}

// ResetIndex 将给定字符串的索引归零
// ResetIndex 重置或删除给定字符串的索引
func ResetIndex(s string) {
stringToIndexMap[s] = 0
// 直接从map中删除指定的键
stringToIndexMap.Delete(s)
}

// ResetAllIndexes 清空整个索引map
func ResetAllIndexes() {
// 重新初始化stringToIndexMap,因为sync.Map没有提供清空所有条目的直接方法
stringToIndexMap = sync.Map{}
}

// checkMessageForHints 检查消息中是否包含给定的提示词
Expand Down Expand Up @@ -607,7 +619,11 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
lastMessageID = id // 更新lastMessageID
// 检查是否有未发送的消息部分
key := utils.GetKey(message.GroupID, message.UserID)
accumulatedMessage, exists := groupUserMessages[key]
accumulatedMessageInterface, exists := groupUserMessages.Load(key)
var accumulatedMessage string
if exists {
accumulatedMessage = accumulatedMessageInterface.(string)
}

// 提取response字段
if response, ok = responseData["response"].(string); ok {
Expand Down Expand Up @@ -721,8 +737,8 @@ func (app *App) GensokyoHandler(w http.ResponseWriter, r *http.Request) {
}
}

// 清空映射中对应的累积消息
groupUserMessages[key] = ""
// 清空key的值
groupUserMessages.Store(key, "")
}
} else {
//发送信息
Expand Down Expand Up @@ -909,7 +925,16 @@ func processMessage(response string, msg structs.OnebotGroupMessage, newmesssage
// 达到标点符号,发送累积的整个消息
if messageBuilder.Len() > 0 {
accumulatedMessage := messageBuilder.String()
groupUserMessages[key] += accumulatedMessage
// 锁定
processMessageMu.Lock()
// 从sync.map读取当前的value
valueInterface, _ := groupUserMessages.Load(key)
value, _ := valueInterface.(string)
// 添加当前messageBuilder中的新内容
value += accumulatedMessage
// 储存新的内容到sync.map
groupUserMessages.Store(key, value)
processMessageMu.Unlock() // 完成更新后时解锁

// 判断消息类型,如果是私人消息或私有群消息,发送私人消息;否则,根据配置决定是否发送群消息
if msg.RealMessageType == "group_private" || msg.MessageType == "private" {
Expand Down
3 changes: 2 additions & 1 deletion applogic/hunyuan.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"net/http"
"strings"
"sync"

"github.com/hoshinonyaruko/gensokyo-llm/config"
"github.com/hoshinonyaruko/gensokyo-llm/fmtf"
Expand All @@ -15,7 +16,7 @@ import (
)

var messageBuilder strings.Builder
var groupUserMessages = make(map[string]string)
var groupUserMessages sync.Map

func (app *App) ChatHandlerHunyuan(w http.ResponseWriter, r *http.Request) {
if r.Method != "POST" {
Expand Down
50 changes: 25 additions & 25 deletions applogic/tongyiqianwen.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
fmtf.Printf("Tyqw上下文history:%v\n", history)

// 构建请求到Tyqw API
apiURL := config.GetTyqwApiPath()
apiURL := config.GetTyqwApiPath(promptstr)

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

var isIncrementalOutput bool
if config.GetTyqwSseType() == 1 {
if config.GetTyqwSseType(promptstr) == 1 {
isIncrementalOutput = true
}
// 获取配置信息
useSSE := config.GetuseSse(promptstr)
apiKey := config.GetTyqwKey()
apiKey := config.GetTyqwKey(promptstr)
var requestBody map[string]interface{}
if useSSE {
// 构建请求体,根据提供的文档重新调整
requestBody = map[string]interface{}{
"parameters": map[string]interface{}{
"max_tokens": config.GetTyqwMaxTokens(), // 最大生成的token数
"temperature": config.GetTyqwTemperature(), // 控制随机性和多样性的温度
"top_p": config.GetTyqwTopP(), // 核采样方法的概率阈值
"top_k": config.GetTyqwTopK(), // 采样候选集的大小
"repetition_penalty": config.GetTyqwRepetitionPenalty(), // 控制重复度的惩罚因子
"stop": config.GetTyqwStopTokens(), // 停止标记
"seed": config.GetTyqwSeed(), // 随机数种子
"result_format": "message", // 返回结果的格式
"enable_search": config.GetTyqwEnableSearch(), // 是否启用互联网搜索
"incremental_output": isIncrementalOutput, // 是否使用增量SSE模式,使用增量模式会更快,rwkv和openai不支持增量模式
"max_tokens": config.GetTyqwMaxTokens(promptstr), // 最大生成的token数
"temperature": config.GetTyqwTemperature(promptstr), // 控制随机性和多样性的温度
"top_p": config.GetTyqwTopP(promptstr), // 核采样方法的概率阈值
"top_k": config.GetTyqwTopK(promptstr), // 采样候选集的大小
"repetition_penalty": config.GetTyqwRepetitionPenalty(), // 控制重复度的惩罚因子
"stop": config.GetTyqwStopTokens(), // 停止标记
"seed": config.GetTyqwSeed(), // 随机数种子
"result_format": "message", // 返回结果的格式
"enable_search": config.GetTyqwEnableSearch(), // 是否启用互联网搜索
"incremental_output": isIncrementalOutput, // 是否使用增量SSE模式,使用增量模式会更快,rwkv和openai不支持增量模式
},
"model": config.GetTyqwModel(), // 指定对话模型
"model": config.GetTyqwModel(promptstr), // 指定对话模型
"input": map[string]interface{}{
"messages": messages, // 用户与模型的对话历史
},
Expand All @@ -251,17 +251,17 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {
// 构建请求体,根据提供的文档重新调整
requestBody = map[string]interface{}{
"parameters": map[string]interface{}{
"max_tokens": config.GetTyqwMaxTokens(), // 最大生成的token数
"temperature": config.GetTyqwTemperature(), // 控制随机性和多样性的温度
"top_p": config.GetTyqwTopP(), // 核采样方法的概率阈值
"top_k": config.GetTyqwTopK(), // 采样候选集的大小
"repetition_penalty": config.GetTyqwRepetitionPenalty(), // 控制重复度的惩罚因子
"stop": config.GetTyqwStopTokens(), // 停止标记
"seed": config.GetTyqwSeed(), // 随机数种子
"result_format": "message", // 返回结果的格式
"enable_search": config.GetTyqwEnableSearch(), // 是否启用互联网搜索
"max_tokens": config.GetTyqwMaxTokens(promptstr), // 最大生成的token数
"temperature": config.GetTyqwTemperature(promptstr), // 控制随机性和多样性的温度
"top_p": config.GetTyqwTopP(promptstr), // 核采样方法的概率阈值
"top_k": config.GetTyqwTopK(promptstr), // 采样候选集的大小
"repetition_penalty": config.GetTyqwRepetitionPenalty(), // 控制重复度的惩罚因子
"stop": config.GetTyqwStopTokens(), // 停止标记
"seed": config.GetTyqwSeed(), // 随机数种子
"result_format": "message", // 返回结果的格式
"enable_search": config.GetTyqwEnableSearch(), // 是否启用互联网搜索
},
"model": config.GetTyqwModel(), // 指定对话模型
"model": config.GetTyqwModel(promptstr), // 指定对话模型
"input": map[string]interface{}{
"messages": messages, // 用户与模型的对话历史
},
Expand Down Expand Up @@ -402,7 +402,7 @@ func (app *App) ChatHandlerTyqw(w http.ResponseWriter, r *http.Request) {

reader := bufio.NewReader(resp.Body)
var totalUsage structs.GPTUsageInfo
if config.GetTyqwSseType() == 1 {
if config.GetTyqwSseType(promptstr) == 1 {
for {
line, err := reader.ReadString('\n')
if err != nil {
Expand Down
Loading
Loading