63 lines
1.9 KiB
Go
63 lines
1.9 KiB
Go
|
|
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:
|
|||
|
|
- 節點總數 **24~32 個**,L1≥8、L2≥12(廣度優先,多方向觸及)
|
|||
|
|
- 每個節點的 relation 與 placementValue 各 25~55 字,寫完整句子
|
|||
|
|
- 痛點/求助類節點至少 10 個;L2 周邊情境要覆蓋多種生活場景,不可精簡或省略欄位`)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
func KnowledgeGraphBreadthUserPrompt(currentNodes int) string {
|
|||
|
|
return strings.TrimSpace(`目前延伸知識僅 ` + strconv.Itoa(currentNodes) + ` 個節點,廣度不足。請**維持既有節點**,只追加新節點與邊:
|
|||
|
|
- 至少再增加 **10~14 個**節點,總數目標 **24~32 個**
|
|||
|
|
- 優先補齊 L2 周邊情境:不同治療階段、生活事件、相鄰困擾、相關品類與使用場景
|
|||
|
|
- 也要補 L1 直接相關的成因、症狀、機制,讓圖譜能觸及更多討論方向
|
|||
|
|
- 新節點的 relation 與 placementValue 必須各 25~55 字;不要 high/medium/low
|
|||
|
|
- 只追加,不要刪除或覆蓋既有節點`)
|
|||
|
|
}
|