thread-master/internal/library/knowledge/quality.go

63 lines
1.9 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package knowledge
import (
"strconv"
"strings"
"unicode/utf8"
)
const (
minGraphNodes = 18
minLayer1Nodes = 6
minLayer2Nodes = 10
minBreadthNodes = 22
targetGraphNodes = 28
minNodeCopyRunes = 15
)
func GraphTooThin(g Graph) bool {
if len(g.Nodes) < minGraphNodes {
return true
}
layerCounts := map[int]int{}
thinCopy := 0
for _, node := range g.Nodes {
layerCounts[node.Layer]++
if utf8.RuneCountInString(strings.TrimSpace(node.Relation)) < minNodeCopyRunes ||
utf8.RuneCountInString(strings.TrimSpace(node.PlacementValue)) < minNodeCopyRunes {
thinCopy++
}
}
if layerCounts[1] < minLayer1Nodes || layerCounts[2] < minLayer2Nodes {
return true
}
if thinCopy > len(g.Nodes)/2 {
return true
}
return false
}
func GraphNeedsBreadth(g Graph) bool {
return len(g.Nodes) < minBreadthNodes
}
func MinBreadthGraphNodes() int {
return minBreadthNodes
}
func KnowledgeGraphRetryUserPrompt() string {
return strings.TrimSpace(`上次產出過於簡略或節點不足。請重新產出完整 TKG JSON
- 節點總數 **2432 個**L1≥8、L2≥12廣度優先多方向觸及
- 每個節點的 relation 與 placementValue 各 2555 字,寫完整句子
- 痛點/求助類節點至少 10 個L2 周邊情境要覆蓋多種生活場景,不可精簡或省略欄位`)
}
func KnowledgeGraphBreadthUserPrompt(currentNodes int) string {
return strings.TrimSpace(`目前延伸知識僅 ` + strconv.Itoa(currentNodes) + ` 個節點,廣度不足。請**維持既有節點**,只追加新節點與邊:
- 至少再增加 **1014 個**節點,總數目標 **2432 個**
- 優先補齊 L2 周邊情境:不同治療階段、生活事件、相鄰困擾、相關品類與使用場景
- 也要補 L1 直接相關的成因、症狀、機制,讓圖譜能觸及更多討論方向
- 新節點的 relation 與 placementValue 必須各 2555 字;不要 high/medium/low
- 只追加,不要刪除或覆蓋既有節點`)
}