Skip to content

Commit

Permalink
Beta133 (#132)
Browse files Browse the repository at this point in the history
* beta1

* beta2

* beta3

* beta4

* beta5

* beta6

* beta7

* beta8

* beta9

* beta10

* beta11

* beta12

* beta13

* beta14

* beta15

* beta16

* beta16

* beta19

* beta20

* beta21

* beta22

* beta23

* beta24

* beta25

* beta27

* beta28

* beta29

* beta30

* beta31

* beta33

* beta34

* beta35

* beta36

* beta37

* beta38

* beta39

* beta40

* beta41

* beta42

* beta43

* beta44

* beta45

* beta45

* beta46

* beat48

* beta49

* beta50

* beta51

* beta52

* beta53

* beta54

* beta55

* beta57

* beta58

* beta59

* beta61

* beta62

* beta63

* beta63

* beta64

* beta65

* beta66

* beta67

* beta70

* beta71

* beta72

* beta72

* beta74

* beta75

* beta76

* beta77

* beta78

* beta79

* beta80

* beta81

* beta82

* beta83

* beta85

* beta86

* beta87

* beta88

* beta89

* beta90

* beta91

* beta92

* beta93

* beta94

* beta94

* beta96

* beta97

* beta98

* beta99

* beta100

* beta101

* beta102

* beta104

* beta105

* beta106

* beta107

* beta108

* beta109

* beta110

* beta111

* beta112

* beta113

* beta115

* beta116

* beta117

* beta118

* beta119

* beta120

* beta121

* beta122

* beta123

* beta124

* beta125

* beta126

* beta127

* beta128

* beta129

* beta130

* beta131

* beta132

* beta1333
  • Loading branch information
Hoshinonyaruko authored May 28, 2024
1 parent f7d60c1 commit 85d7fc4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 58 deletions.
5 changes: 3 additions & 2 deletions applogic/yuanqi.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ func (app *App) ChatHandlerYuanQi(w http.ResponseWriter, r *http.Request) {
}

apiURL := config.GetYuanqiApiPath(promptstr)
token := config.GetYuanqiToken(promptstr)

assistantID, token := config.GetYuanqiConf(promptstr)
fmtf.Printf("YuanQi上下文history:%v\n", history)

// 构建请求到yuanqi API的请求体
Expand Down Expand Up @@ -226,7 +227,7 @@ func (app *App) ChatHandlerYuanQi(w http.ResponseWriter, r *http.Request) {

// 创建请求数据结构体
requestBody = structs.RequestDataYuanQi{
AssistantID: config.GetYuanqiAssistantID(promptstr),
AssistantID: assistantID,
UserID: useridstr,
Stream: config.GetuseSse(promptstr),
ChatType: config.GetYuanqiChatType(promptstr),
Expand Down
142 changes: 95 additions & 47 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2881,74 +2881,122 @@ func getTemperatureHunyuanInternal(options ...string) float64 {
return value
}

// 获取助手ID
func GetYuanqiAssistantID(options ...string) string {
mu.Lock()
defer mu.Unlock()
return getYuanqiAssistantIDInternal(options...)
}
// // 获取助手ID
// func GetYuanqiAssistantID(options ...string) string {
// mu.Lock()
// defer mu.Unlock()
// return getYuanqiAssistantIDInternal(options...)
// }

func getYuanqiAssistantIDInternal(options ...string) string {
if len(options) == 0 || options[0] == "" {
if instance != nil {
return instance.Settings.YuanqiAssistantID
}
return "" // 默认值或错误处理
}
// func getYuanqiAssistantIDInternal(options ...string) string {
// if len(options) == 0 || options[0] == "" {
// if instance != nil {
// return instance.Settings.YuanqiAssistantID
// }
// return "" // 默认值或错误处理
// }

basename := options[0]
assistantIDInterface, err := prompt.GetSettingFromFilename(basename, "YuanqiAssistantID")
if err != nil {
log.Println("Error retrieving YuanqiAssistantID:", err)
return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
}
// basename := options[0]
// assistantIDInterface, err := prompt.GetSettingFromFilename(basename, "YuanqiAssistantID")
// if err != nil {
// log.Println("Error retrieving YuanqiAssistantID:", err)
// return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
// }

assistantID, ok := assistantIDInterface.(string)
if !ok { // 检查类型断言是否失败
log.Println("Type assertion failed for YuanqiAssistantID, fetching default")
return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
}
// assistantID, ok := assistantIDInterface.(string)
// if !ok { // 检查类型断言是否失败
// log.Println("Type assertion failed for YuanqiAssistantID, fetching default")
// return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
// }

if assistantID == "" {
return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
}
// if assistantID == "" {
// return getYuanqiAssistantIDInternal() // 递归调用内部函数,不传递任何参数
// }

return assistantID
}
// return assistantID
// }

// // 获取Token
// func GetYuanqiToken(options ...string) string {
// mu.Lock()
// defer mu.Unlock()
// return getYuanqiTokenInternal(options...)
// }

// func getYuanqiTokenInternal(options ...string) string {
// if len(options) == 0 || options[0] == "" {
// if instance != nil {
// return instance.Settings.YuanqiToken
// }
// return "" // 默认值或错误处理
// }

// basename := options[0]
// YuanqiTokenInterface, err := prompt.GetSettingFromFilename(basename, "YuanqiToken")
// if err != nil {
// log.Println("Error retrieving YuanqiToken:", err)
// return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
// }

// YuanqiToken, ok := YuanqiTokenInterface.(string)
// if !ok { // 检查类型断言是否失败
// log.Println("Type assertion failed for YuanqiToken, fetching default")
// return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
// }

// 获取Token
func GetYuanqiToken(options ...string) string {
// if YuanqiToken == "" {
// return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
// }

// return YuanqiToken
// }

// GetYuanqiConf return conf.YuanqiAssistantID, conf.YuanqiToken
func GetYuanqiConf(options ...string) (string, string) {
mu.Lock()
defer mu.Unlock()
return getYuanqiTokenInternal(options...)
return getYuanqiConfInternal(options...)
}

func getYuanqiTokenInternal(options ...string) string {
if len(options) == 0 || options[0] == "" {
if instance != nil {
return instance.Settings.YuanqiToken
// getYuanqiConfInternal 内部递归函数,处理配置获取逻辑
func getYuanqiConfInternal(options ...string) (string, string) {
// 从instance中读取配置数组
if instance != nil && len(instance.Settings.Yuanqiconfs) > 0 {
if len(options) == 0 || options[0] == "" {
// 从instance全局变量中随机选择一个配置
index := rand.Intn(len(instance.Settings.Yuanqiconfs))
conf := instance.Settings.Yuanqiconfs[index]
return conf.YuanqiAssistantID, conf.YuanqiToken
}
return "" // 默认值或错误处理
} else {
log.Println("No configurations available in instance or default behavior")
return "", "" // 默认值或错误处理
}

// 使用prompt包从指定的文件名中获取配置
basename := options[0]
YuanqiTokenInterface, err := prompt.GetSettingFromFilename(basename, "YuanqiToken")
confInterface, err := prompt.GetSettingFromFilename(basename, "Yuanqiconfs")
if err != nil {
log.Println("Error retrieving YuanqiToken:", err)
return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
log.Printf("Error retrieving settings from file: %s, error: %v", basename, err)
return getYuanqiConfInternal() // 递归调用内部函数,不传递任何参数
}

YuanqiToken, ok := YuanqiTokenInterface.(string)
if !ok { // 检查类型断言是否失败
log.Println("Type assertion failed for YuanqiToken, fetching default")
return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
// 断言获取的interface{}为[]YuanqiConf
confs, ok := confInterface.([]structs.YuanqiConf)
if !ok {
log.Println("Type assertion failed for YuanqiConfs, attempting default behavior")
return getYuanqiConfInternal() // 递归调用内部函数,尝试默认配置
}

if YuanqiToken == "" {
return getYuanqiTokenInternal() // 递归调用内部函数,不传递任何参数
if len(confs) == 0 {
log.Println("No configurations found in file:", basename)
return getYuanqiConfInternal() // 递归调用内部函数,尝试默认配置
}

return YuanqiToken
// 随机选择一个配置返回
index := rand.Intn(len(confs))
conf := confs[index]
return conf.YuanqiAssistantID, conf.YuanqiToken
}

// 获取助手版本
Expand Down
19 changes: 12 additions & 7 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,12 @@ type Settings struct {
GlmToolChoice string `yaml:"glmToolChoice"` // 工具选择策略
GlmUserID string `yaml:"glmUserID"` // 用户ID

YuanqiApiPath string `yaml:"yuanqiApiPath"` // 元器api地址
YuanqiAssistantID string `yaml:"yuanqiAssistantID"` // 助手ID
YuanqiVersion float64 `yaml:"yuanqiVersion"` // 助手版本, 仅对内部开放
YuanqiUserID string `yaml:"yuanqiUserID"` // 用户ID,调用者业务侧的用户ID,会影响智能体的数据统计,建议按实际情况填写
YuanqiStream bool `yaml:"yuanqiStream"` // 是否启用流式返回,默认为false
YuanqiChatType string `yaml:"yuanqiChatType"` // 聊天类型,默认为published,preview时使用草稿态智能体,仅对内部开放
YuanqiToken string `yaml:"yuanqiToken"` // Token
YuanqiApiPath string `yaml:"yuanqiApiPath"` // 元器api地址
Yuanqiconfs []YuanqiConf `yaml:"yuanqiConfs"` // 元器api配置 支持多个
YuanqiVersion float64 `yaml:"yuanqiVersion"` // 助手版本, 仅对内部开放
YuanqiUserID string `yaml:"yuanqiUserID"` // 用户ID,调用者业务侧的用户ID,会影响智能体的数据统计,建议按实际情况填写
YuanqiStream bool `yaml:"yuanqiStream"` // 是否启用流式返回,默认为false
YuanqiChatType string `yaml:"yuanqiChatType"` // 聊天类型,默认为published,preview时使用草稿态智能体,仅对内部开放

WSServerToken string `yaml:"wsServerToken"`
WSPath string `yaml:"wsPath"`
Expand All @@ -424,6 +423,12 @@ type Settings struct {
PromptCoverA []string `yaml:"promptCoverA"` //暂时用不上 待实现
}

type YuanqiConf struct {
YuanqiAssistantID string `yaml:"yuanqiAssistantID"` // 助手ID
YuanqiToken string `yaml:"yuanqiToken"` // Token
YuanqiName string `yaml:"yuanqiName"` // 名字
}

type MetaEvent struct {
PostType string `json:"post_type"`
MetaEventType string `json:"meta_event_type"`
Expand Down
10 changes: 8 additions & 2 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,15 @@ settings:
# Yuanqi 助手配置文件,确保按业务需求配置。
yuanqiApiPath: "https://open.hunyuan.tencent.com/openapi/v1/agent/chat/completions"
yuanqiAssistantID: "" # 助手ID,唯一标识您的助手实例
yuanqiToken: "" # 元器Token
yuanqiChatType: "published" # 聊天类型,默认为published,支持preview模式下使用草稿态智能体
yuanqiConfs:
- yuanqiAssistantID: "123"
yuanqiToken: "123"
yuanqiName: "123"
- yuanqiAssistantID: "123"
uanqiToken: "123"
yuanqiName: "123"
`

const Logo = `
Expand Down

0 comments on commit 85d7fc4

Please sign in to comment.