MCPcopy Create free account
hub / github.com/astercloud/aster / scoreSections

Method scoreSections

pkg/agent/prompt_optimizer.go:270–296  ·  view source on GitHub ↗

scoreSections 评分段落

(sections []string, preserveSections []string)

Source from the content-addressed store, hash-verified

268
269// scoreSections 评分段落
270func (c *EnhancedPromptCompressor) scoreSections(sections []string, preserveSections []string) []ScoredSection {
271 result := make([]ScoredSection, 0, len(sections))
272
273 for i, section := range sections {
274 title := c.extractSectionTitle(section)
275 mustKeep := c.shouldPreserve(title, preserveSections)
276 score := c.calculateSectionScore(section, i, len(sections), mustKeep)
277
278 result = append(result, ScoredSection{
279 Content: section,
280 Title: title,
281 Score: score,
282 MustKeep: mustKeep,
283 })
284 }
285
286 // 按评分排序(高分在前)
287 for i := range len(result) - 1 {
288 for j := i + 1; j < len(result); j++ {
289 if result[j].Score > result[i].Score {
290 result[i], result[j] = result[j], result[i]
291 }
292 }
293 }
294
295 return result
296}
297
298// calculateSectionScore 计算段落重要性评分
299func (c *EnhancedPromptCompressor) calculateSectionScore(section string, index, total int, mustKeep bool) float64 {

Callers 3

compressSimpleMethod · 0.95

Calls 3

extractSectionTitleMethod · 0.95
shouldPreserveMethod · 0.95
calculateSectionScoreMethod · 0.95