Skip to content

Commit

Permalink
Beta81 (#80)
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
  • Loading branch information
Hoshinonyaruko authored Apr 25, 2024
1 parent 7e8c16d commit b2880d5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 3 deletions.
18 changes: 15 additions & 3 deletions applogic/ernie.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,12 @@ func (app *App) ChatHandlerErnie(w http.ResponseWriter, r *http.Request) {
}
}
} else {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
// 默认执行 正常提示词顺序
if !config.GetEnhancedQA(promptstr) {
history, err = prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
}
}

Expand All @@ -124,6 +127,15 @@ func (app *App) ChatHandlerErnie(w http.ResponseWriter, r *http.Request) {
history = append(history, userhistory...)
}

// 如果使用增强的提示词顺序(需配置覆盖)
if config.GetEnhancedQA(promptstr) {
systemHistory, err := prompt.GetMessagesExcludingSystem(promptstr)
if err != nil {
fmtf.Printf("prompt.GetMessagesExcludingSystem error: %v\n", err)
}
history = append(history, systemHistory...)
}

fmtf.Printf("文心上下文history:%v\n", history)

// 构建请求负载
Expand Down
34 changes: 34 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1504,3 +1504,37 @@ func getPromptMarksInternal(options ...string) []string {

return promptMarks
}

// 获取 EnhancedQA
func GetEnhancedQA(options ...string) bool {
mu.Lock()
defer mu.Unlock()
return getEnhancedQAInternal(options...)
}

// 内部逻辑执行函数,不处理锁,可以安全地递归调用
func getEnhancedQAInternal(options ...string) bool {
// 检查是否有参数传递进来,以及是否为空字符串
if len(options) == 0 || options[0] == "" {
if instance != nil {
return instance.Settings.EnhancedQA
}
return false
}

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

enhancedQA, ok := enhancedQAInterface.(bool)
if !ok { // 检查是否断言失败
fmt.Println("Type assertion failed for EnhancedQA, fetching default")
return getEnhancedQAInternal() // 递归调用内部函数,不传递任何参数
}

return enhancedQA
}
1 change: 1 addition & 0 deletions structs/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ type Settings struct {
PromptMarkType int `yaml:"promptMarkType"`
PromptMarksLength int `yaml:"promptMarksLength"`
PromptMarks []string `yaml:"promptMarks"`
EnhancedQA bool `yaml:"enhancedQA"`
}

type MetaEvent struct {
Expand Down
1 change: 1 addition & 0 deletions template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ settings:
promptMarkType : 0 #0=多个里随机一个,promptMarksLength达到时触发 1=按条件触发,promptMarksLength达到时也触发.条件格式aaaa:xxx-xxx-xxxx-xxx,aaa是promptmark中的yml,xxx是标记,识别到用户和模型说出标记就会触发这个支线(需要自行写好提示词,让llm能根据条件说出.)
promptMarksLength : 2 #promptMarkType=0时,多少轮开始切换上下文.
promptMarks : [] #prompts文件夹内的文件,一个代表一个配置文件,当promptMarkType为0是,直接是prompts文件夹内的yml名字,当为1时,格式在上面.
enhancedQA : false #默认是false,用于在故事支线将firstQA的位置从顶部移动到用户之前,从而增强权重和效果.
#混元配置项
secretId : "" #腾讯云账号(右上角)-访问管理-访问密钥,生成获取
Expand Down

0 comments on commit b2880d5

Please sign in to comment.