feat: Add DataSchema tool for retrieving schema information from CSV and Excel files

This commit is contained in:
begoniezhao
2025-12-23 16:56:30 +08:00
parent ddf5ae4e65
commit 907e9a5522
51 changed files with 2784 additions and 1307 deletions
+15 -16
View File
@@ -2,33 +2,22 @@ package tools
import (
"context"
"encoding/json"
"fmt"
"github.com/Tencent/WeKnora/internal/common"
"github.com/Tencent/WeKnora/internal/types"
"github.com/Tencent/WeKnora/internal/types/interfaces"
"gorm.io/gorm"
)
// ToolRegistry manages the registration and retrieval of tools
type ToolRegistry struct {
tools map[string]types.Tool
knowledgeService interfaces.KnowledgeService
chunkService interfaces.ChunkService
db *gorm.DB
tools map[string]types.Tool
}
// NewToolRegistry creates a new tool registry
func NewToolRegistry(
knowledgeService interfaces.KnowledgeService,
chunkService interfaces.ChunkService,
db *gorm.DB, // gorm.DB for database operations
) *ToolRegistry {
func NewToolRegistry() *ToolRegistry {
return &ToolRegistry{
tools: make(map[string]types.Tool),
knowledgeService: knowledgeService,
chunkService: chunkService,
db: db,
tools: make(map[string]types.Tool),
}
}
@@ -72,7 +61,7 @@ func (r *ToolRegistry) GetFunctionDefinitions() []types.FunctionDefinition {
func (r *ToolRegistry) ExecuteTool(
ctx context.Context,
name string,
args map[string]interface{},
args json.RawMessage,
) (*types.ToolResult, error) {
common.PipelineInfo(ctx, "AgentTool", "execute_start", map[string]interface{}{
"tool": name,
@@ -112,3 +101,13 @@ func (r *ToolRegistry) ExecuteTool(
return result, execErr
}
// Cleanup cleans up all registered tools that implement the Cleanup method
func (r *ToolRegistry) Cleanup(ctx context.Context) {
// Check specifically for DataAnalysisTool
if tool, exists := r.tools[ToolDataAnalysis]; exists {
if dataAnalysisTool, ok := tool.(*DataAnalysisTool); ok {
dataAnalysisTool.Cleanup(ctx)
}
}
}