refactor: Clean up code by removing unnecessary blank lines and improving comments for better readability and maintainability
This commit is contained in:
@@ -2,7 +2,6 @@ package tools
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
@@ -421,37 +420,3 @@ func (t *DatabaseQueryTool) formatQueryResults(columns []string, results []map[s
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
// Helper function to convert database value to proper type
|
||||
func convertDatabaseValue(val interface{}) interface{} {
|
||||
if val == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
switch v := val.(type) {
|
||||
case []byte:
|
||||
return string(v)
|
||||
case sql.NullString:
|
||||
if v.Valid {
|
||||
return v.String
|
||||
}
|
||||
return nil
|
||||
case sql.NullInt64:
|
||||
if v.Valid {
|
||||
return v.Int64
|
||||
}
|
||||
return nil
|
||||
case sql.NullFloat64:
|
||||
if v.Valid {
|
||||
return v.Float64
|
||||
}
|
||||
return nil
|
||||
case sql.NullBool:
|
||||
if v.Valid {
|
||||
return v.Bool
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
@@ -459,18 +459,19 @@ func (t *KnowledgeSearchTool) filterByThreshold(
|
||||
var threshold float64
|
||||
|
||||
// Special handling for history matches: use lower threshold
|
||||
if r.MatchType == types.MatchTypeHistory {
|
||||
switch r.MatchType {
|
||||
case types.MatchTypeHistory:
|
||||
// Use the lower of the two thresholds, then reduce by 0.1 (minimum 0.5)
|
||||
th := vectorThreshold
|
||||
if keywordThreshold < th {
|
||||
th = keywordThreshold
|
||||
}
|
||||
threshold = math.Max(th-0.1, 0.5)
|
||||
} else if r.MatchType == types.MatchTypeEmbedding {
|
||||
case types.MatchTypeEmbedding:
|
||||
threshold = vectorThreshold
|
||||
} else if r.MatchType == types.MatchTypeKeywords {
|
||||
case types.MatchTypeKeywords:
|
||||
threshold = keywordThreshold
|
||||
} else {
|
||||
default:
|
||||
// For other match types (graph, nearby chunk, etc.), use the lower threshold
|
||||
threshold = vectorThreshold
|
||||
if keywordThreshold < threshold {
|
||||
@@ -1208,7 +1209,7 @@ func (t *KnowledgeSearchTool) findMissingChunkRanges(retrievedChunks map[int]boo
|
||||
}
|
||||
|
||||
var ranges []chunkRange
|
||||
var currentStart int = -1
|
||||
currentStart := -1
|
||||
|
||||
// Iterate through all possible chunk indices (0 to totalChunks-1)
|
||||
for i := 0; i < totalChunks; i++ {
|
||||
|
||||
@@ -190,11 +190,11 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
builder.WriteString("=== 知识文档分块 ===\n\n")
|
||||
|
||||
if knowledgeTitle != "" {
|
||||
builder.WriteString(fmt.Sprintf("文档: %s (%s)\n", knowledgeTitle, knowledgeID))
|
||||
fmt.Fprintf(builder, "文档: %s (%s)\n", knowledgeTitle, knowledgeID)
|
||||
} else {
|
||||
builder.WriteString(fmt.Sprintf("文档 ID: %s\n", knowledgeID))
|
||||
fmt.Fprintf(builder, "文档 ID: %s\n", knowledgeID)
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("总分块数: %d\n", total))
|
||||
fmt.Fprintf(builder, "总分块数: %d\n", total)
|
||||
|
||||
if fetched == 0 {
|
||||
builder.WriteString("未找到任何分块,请确认文档是否已完成解析。\n")
|
||||
@@ -203,14 +203,14 @@ func (t *ListKnowledgeChunksTool) buildOutput(
|
||||
}
|
||||
return builder.String()
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("本次拉取: %d 条, 检索范围: %d - %d\n\n", fetched, chunks[0].ChunkIndex, chunks[len(chunks)-1].ChunkIndex))
|
||||
fmt.Fprintf(builder, "本次拉取: %d 条, 检索范围: %d - %d\n\n", fetched, chunks[0].ChunkIndex, chunks[len(chunks)-1].ChunkIndex)
|
||||
|
||||
builder.WriteString("=== 分块内容预览 ===\n\n")
|
||||
for idx, c := range chunks {
|
||||
builder.WriteString(fmt.Sprintf("Chunk #%d (Index %d)\n", idx+1, c.ChunkIndex+1))
|
||||
builder.WriteString(fmt.Sprintf(" chunk_id: %s\n", c.ID))
|
||||
builder.WriteString(fmt.Sprintf(" 类型: %s\n", c.ChunkType))
|
||||
builder.WriteString(fmt.Sprintf(" 内容: %s\n\n", summarizeContent(c.Content)))
|
||||
fmt.Fprintf(builder, "Chunk #%d (Index %d)\n", idx+1, c.ChunkIndex+1)
|
||||
fmt.Fprintf(builder, " chunk_id: %s\n", c.ID)
|
||||
fmt.Fprintf(builder, " 类型: %s\n", c.ChunkType)
|
||||
fmt.Fprintf(builder, " 内容: %s\n\n", summarizeContent(c.Content))
|
||||
}
|
||||
|
||||
if int64(fetched) < total {
|
||||
|
||||
@@ -502,7 +502,7 @@ func (t *WebFetchTool) processNode(s *goquery.Selection, markdown *strings.Build
|
||||
isOrdered := nodeName == "ol"
|
||||
node.Find("li").Each(func(idx int, li *goquery.Selection) {
|
||||
if isOrdered {
|
||||
markdown.WriteString(fmt.Sprintf("%d. ", idx+1))
|
||||
fmt.Fprintf(markdown, "%d. ", idx+1)
|
||||
} else {
|
||||
markdown.WriteString("- ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user