fix(ai): Ask P0 禁 CoT、可澄清、禁 UPDATE_TIME 终答
prompt 禁止推理外露与编造列;信息不足允许一句澄清。 新增 SanitizeAssistantContent 剥回复中的推理草稿;业务「最近 N 天」不得默认用 information_schema.UPDATE_TIME。
This commit is contained in:
1 parent
dc7089857b
commit
4c68539db6
5 files changed
+154
-3
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package ai
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSanitizeAssistantContentStripsCoTKeepsSQL(t *testing.T) {
|
||||
raw := `我们需要回答中文。用户说查询最近7天。作为助手我们只能根据现有信息。指令要求生成SQL。
|
||||
|
||||
说明:因未提供业务时间字段,以表更新时间近似。
|
||||
|
||||
` + "```sql\nSELECT TABLE_NAME, UPDATE_TIME\nFROM information_schema.TABLES\nWHERE TABLE_SCHEMA = 'demo';\n```"
|
||||
out := SanitizeAssistantContent(raw)
|
||||
if strings.Contains(out, "我们需要回答中文") || strings.Contains(out, "作为助手") {
|
||||
t.Fatalf("CoT leaked: %s", out)
|
||||
}
|
||||
if !strings.Contains(out, "```sql") || !strings.Contains(out, "UPDATE_TIME") {
|
||||
t.Fatalf("SQL fence lost: %s", out)
|
||||
}
|
||||
// prose should be short
|
||||
prose := strings.Split(out, "```")[0]
|
||||
if len([]rune(strings.TrimSpace(prose))) > 80 {
|
||||
t.Fatalf("prose too long: %q", prose)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSanitizeAssistantContentKeepsShortClarify(t *testing.T) {
|
||||
in := "当前结构未给出时间列,请说明要查哪张表以及时间字段名。"
|
||||
if got := SanitizeAssistantContent(in); got != in {
|
||||
t.Fatalf("got %q", got)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user