feat(docparser): enhance sortedKeys function for numeric string sorting

- Modified the sortedKeys function to sort keys numerically when all keys are numeric strings, ensuring correct order for keys like "2" and "10".
- Updated the NeedsKBRetrieval method to include IntentSummarize as a valid case for knowledge base retrieval.
- Added a new test data file for chat import to support testing of document parsing and processing functionalities.
This commit is contained in:
wizardchen
2026-03-24 13:41:15 +08:00
committed by lyingbug
parent e7c21c0733
commit 4fb08f3ec8
3 changed files with 381 additions and 2 deletions
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"sort"
"strconv"
"strings"
)
@@ -244,11 +245,27 @@ func canSplitDict(d map[string]interface{}) bool {
}
// sortedKeys returns the keys of a map in sorted order.
// When all keys are numeric strings (from array-to-dict conversion),
// sorts numerically so "2" comes before "10".
func sortedKeys(m map[string]interface{}) []string {
keys := make([]string, 0, len(m))
allNumeric := true
for k := range m {
keys = append(keys, k)
if allNumeric {
if _, err := strconv.Atoi(k); err != nil {
allNumeric = false
}
}
}
if allNumeric {
sort.Slice(keys, func(i, j int) bool {
ni, _ := strconv.Atoi(keys[i])
nj, _ := strconv.Atoi(keys[j])
return ni < nj
})
} else {
sort.Strings(keys)
}
sort.Strings(keys)
return keys
}