109 lines
3.5 KiB
Go
109 lines
3.5 KiB
Go
package tools
|
|
|
|
import (
|
|
"ai_scheduler/internal/config"
|
|
"ai_scheduler/internal/entitys"
|
|
"ai_scheduler/internal/pkg/utils_ollama"
|
|
"ai_scheduler/internal/tools/public"
|
|
zltxtool "ai_scheduler/internal/tools/zltx"
|
|
"context"
|
|
|
|
"fmt"
|
|
)
|
|
|
|
// Manager 工具管理器
|
|
type Manager struct {
|
|
tools map[string]entitys.Tool
|
|
llm *utils_ollama.Client
|
|
}
|
|
|
|
// NewManager 创建工具管理器
|
|
func NewManager(config *config.Config, llm *utils_ollama.Client) *Manager {
|
|
m := &Manager{
|
|
tools: make(map[string]entitys.Tool),
|
|
llm: llm,
|
|
}
|
|
|
|
// 注册直连天下订单详情工具
|
|
if config.Tools.ZltxOrderDetail.Enabled {
|
|
zltxOrderDetailTool := zltxtool.NewZltxOrderDetailTool(config.Tools.ZltxOrderDetail, m.llm)
|
|
m.tools[zltxOrderDetailTool.Name()] = zltxOrderDetailTool
|
|
}
|
|
|
|
//注册直连天下订单日志工具
|
|
if config.Tools.ZltxOrderDirectLog.Enabled {
|
|
zltxOrderLogTool := zltxtool.NewZltxOrderLogTool(config.Tools.ZltxOrderDirectLog)
|
|
m.tools[zltxOrderLogTool.Name()] = zltxOrderLogTool
|
|
}
|
|
|
|
//注册直连天下商品工具
|
|
if config.Tools.ZltxProduct.Enabled {
|
|
zltxProductTool := zltxtool.NewZltxProductTool(config.Tools.ZltxProduct)
|
|
m.tools[zltxProductTool.Name()] = zltxProductTool
|
|
}
|
|
//注册直连天下订单统计工具
|
|
if config.Tools.ZltxOrderStatistics.Enabled {
|
|
zltxOrderStatisticsTool := zltxtool.NewZltxOrderStatisticsTool(config.Tools.ZltxOrderStatistics)
|
|
m.tools[zltxOrderStatisticsTool.Name()] = zltxOrderStatisticsTool
|
|
}
|
|
|
|
// 注册知识库工具
|
|
if config.Tools.Knowledge.Enabled {
|
|
knowledgeTool := public.NewKnowledgeBaseTool(config.Tools.Knowledge)
|
|
m.tools[knowledgeTool.Name()] = knowledgeTool
|
|
}
|
|
|
|
// 注册直连天下上游订单售后工具
|
|
if config.Tools.ZltxOrderAfterSaleSupplier.Enabled {
|
|
zltxOrderAfterSaleSupplierTool := zltxtool.NewOrderAfterSaleSupplierTool(config.Tools.ZltxOrderAfterSaleSupplier)
|
|
m.tools[zltxOrderAfterSaleSupplierTool.Name()] = zltxOrderAfterSaleSupplierTool
|
|
}
|
|
// 注册直连天下下游订单售后工具
|
|
if config.Tools.ZltxOrderAfterSaleReseller.Enabled {
|
|
zltxOrderAfterSaleResellerTool := zltxtool.NewOrderAfterSaleResellerTool(config.Tools.ZltxOrderAfterSaleReseller)
|
|
m.tools[zltxOrderAfterSaleResellerTool.Name()] = zltxOrderAfterSaleResellerTool
|
|
}
|
|
// 注册直连天下下游批充订单售后工具
|
|
if config.Tools.ZltxOrderAfterSaleResellerBatch.Enabled {
|
|
zltxOrderAfterSaleResellerBatchTool := zltxtool.NewOrderAfterSaleResellerBatchTool(config.Tools.ZltxOrderAfterSaleResellerBatch)
|
|
m.tools[zltxOrderAfterSaleResellerBatchTool.Name()] = zltxOrderAfterSaleResellerBatchTool
|
|
}
|
|
// 注册天气工具
|
|
if config.Tools.Weather.Enabled {
|
|
weatherTool := public.NewWeatherTool(config.Tools.Weather)
|
|
m.tools[weatherTool.Name()] = weatherTool
|
|
}
|
|
// 注册 Coze 快递查询工具
|
|
if config.Tools.CozeExpress.Enabled {
|
|
cozeTool := public.NewCozeExpress(config.Tools.CozeExpress, m.llm)
|
|
m.tools[cozeTool.Name()] = cozeTool
|
|
}
|
|
// 注册 Coze 公司查询工具
|
|
if config.Tools.CozeCompany.Enabled {
|
|
cozeTool := public.NewCozeCompany(config.Tools.CozeCompany, m.llm)
|
|
m.tools[cozeTool.Name()] = cozeTool
|
|
}
|
|
|
|
// 普通对话
|
|
chat := public.NewNormalChatTool(m.llm, config)
|
|
m.tools[chat.Name()] = chat
|
|
|
|
return m
|
|
}
|
|
|
|
// GetTool 获取工具
|
|
func (m *Manager) GetTool(name string) (entitys.Tool, bool) {
|
|
tool, exists := m.tools[name]
|
|
return tool, exists
|
|
}
|
|
|
|
// ExecuteTool 执行工具
|
|
func (m *Manager) ExecuteTool(ctx context.Context, name string, rec *entitys.Recognize) error {
|
|
tool, exists := m.GetTool(name)
|
|
if !exists {
|
|
return fmt.Errorf("tool not found: %s", name)
|
|
}
|
|
|
|
return tool.Execute(ctx, rec)
|
|
}
|