From b2880d5bc23fdaaf062cbc350c0e390e92000d01 Mon Sep 17 00:00:00 2001 From: SanaeFox <36219542+Hoshinonyaruko@users.noreply.github.com> Date: Fri, 26 Apr 2024 00:20:59 +0800 Subject: [PATCH] Beta81 (#80) * 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 --- applogic/ernie.go | 18 +++++++++++++++--- config/config.go | 34 ++++++++++++++++++++++++++++++++++ structs/struct.go | 1 + template/config_template.go | 1 + 4 files changed, 51 insertions(+), 3 deletions(-) diff --git a/applogic/ernie.go b/applogic/ernie.go index 22ce1f6..e388d66 100644 --- a/applogic/ernie.go +++ b/applogic/ernie.go @@ -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) + } } } @@ -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) // 构建请求负载 diff --git a/config/config.go b/config/config.go index a77a06b..f1dd3c0 100644 --- a/config/config.go +++ b/config/config.go @@ -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 +} diff --git a/structs/struct.go b/structs/struct.go index acc8aca..2cd5638 100644 --- a/structs/struct.go +++ b/structs/struct.go @@ -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 { diff --git a/template/config_template.go b/template/config_template.go index c2d6b17..488bd1e 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -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 : "" #腾讯云账号(右上角)-访问管理-访问密钥,生成获取