refactor: rename tools_bot to tool_callback
This commit is contained in:
parent
b409266751
commit
7a48333efc
|
|
@ -13,8 +13,8 @@ import (
|
|||
"ai_scheduler/internal/pkg"
|
||||
"ai_scheduler/internal/server"
|
||||
"ai_scheduler/internal/services"
|
||||
"ai_scheduler/internal/tool_callback"
|
||||
"ai_scheduler/internal/tools"
|
||||
"ai_scheduler/internal/tools_bot"
|
||||
"ai_scheduler/utils"
|
||||
|
||||
"github.com/gofiber/fiber/v2/log"
|
||||
|
|
@ -32,9 +32,9 @@ func InitializeApp(*config.Config, log.AllLogger) (*server.Servers, func(), erro
|
|||
biz.ProviderSetBiz,
|
||||
impl.ProviderImpl,
|
||||
utils.ProviderUtils,
|
||||
tools_bot.ProviderSetBotTools,
|
||||
dingtalk.ProviderSetDingTalk,
|
||||
tools_regis.ProviderToolsRegis,
|
||||
tool_callback.ProviderSetCallBackTools,
|
||||
))
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"ai_scheduler/internal/domain/workflow/runtime"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"ai_scheduler/internal/gateway"
|
||||
"ai_scheduler/internal/pkg"
|
||||
"ai_scheduler/internal/pkg/l_request"
|
||||
"ai_scheduler/internal/pkg/mapstructure"
|
||||
"ai_scheduler/internal/pkg/rec_extra"
|
||||
|
|
@ -218,7 +219,7 @@ func (r *Handle) handleKnowle(ctx context.Context, rec *entitys.Recognize, task
|
|||
ApiKey: ext.Sys.KnowlegeTenantKey,
|
||||
Query: query,
|
||||
}
|
||||
|
||||
rec.Ext = pkg.JsonByteIgonErr(ext)
|
||||
// 执行工具
|
||||
err = r.toolManager.ExecuteTool(ctx, configData.Tool, rec)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,91 +0,0 @@
|
|||
package constants
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/biz"
|
||||
"ai_scheduler/internal/biz/do"
|
||||
"ai_scheduler/internal/biz/llm_service"
|
||||
"ai_scheduler/internal/data/impl"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"ai_scheduler/internal/gateway"
|
||||
"ai_scheduler/internal/pkg/dingtalk"
|
||||
"ai_scheduler/internal/pkg/utils_ollama"
|
||||
"ai_scheduler/internal/pkg/utils_vllm"
|
||||
"ai_scheduler/internal/server"
|
||||
"ai_scheduler/internal/services"
|
||||
"ai_scheduler/internal/tools"
|
||||
"ai_scheduler/internal/tools_bot"
|
||||
"ai_scheduler/utils"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
bootstrap := initialize.LoadConfigWithTest()
|
||||
businessLogger := log2.NewBusinessLogger(bootstrap.Logs, id, Name, Version)
|
||||
helper := pkg.NewLogHelper(businessLogger, bootstrap)
|
||||
|
||||
db, cleanup := utils.NewGormDb(configConfig)
|
||||
sysImpl := impl.NewSysImpl(db)
|
||||
taskImpl := impl.NewTaskImpl(db)
|
||||
chatHisImpl := impl.NewChatHisImpl(db)
|
||||
doDo := do.NewDo(sysImpl, taskImpl, chatHisImpl, configConfig)
|
||||
client, cleanup2, err := utils_ollama.NewClient(configConfig)
|
||||
if err != nil {
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
utils_vllmClient, cleanup3, err := utils_vllm.NewClient(configConfig)
|
||||
if err != nil {
|
||||
cleanup2()
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
ollamaService := llm_service.NewOllamaGenerate(client, utils_vllmClient, configConfig, chatHisImpl)
|
||||
manager := tools.NewManager(configConfig, client)
|
||||
sessionImpl := impl.NewSessionImpl(db)
|
||||
botTool := tools_bot.NewBotTool(configConfig, client, sessionImpl)
|
||||
handle := do.NewHandle(ollamaService, manager, configConfig, sessionImpl, botTool)
|
||||
aiRouterBiz := biz.NewAiRouterBiz(doDo, handle)
|
||||
chatHistoryBiz := biz.NewChatHistoryBiz(chatHisImpl, taskImpl)
|
||||
gatewayGateway := gateway.NewGateway()
|
||||
chatService := services.NewChatService(aiRouterBiz, chatHistoryBiz, gatewayGateway, configConfig)
|
||||
sessionBiz := biz.NewSessionBiz(configConfig, sessionImpl, sysImpl, chatHisImpl)
|
||||
sessionService := services.NewSessionService(sessionBiz, chatHistoryBiz)
|
||||
taskBiz := biz.NewTaskBiz(configConfig, taskImpl)
|
||||
taskService := services.NewTaskService(sessionBiz, taskBiz)
|
||||
oldClient := dingtalk.NewOldClient(configConfig)
|
||||
contactClient, err := dingtalk.NewContactClient(configConfig)
|
||||
if err != nil {
|
||||
cleanup3()
|
||||
cleanup2()
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
notableClient, err := dingtalk.NewNotableClient(configConfig)
|
||||
if err != nil {
|
||||
cleanup3()
|
||||
cleanup2()
|
||||
cleanup()
|
||||
return nil, nil, err
|
||||
}
|
||||
callbackService := services.NewCallbackService(configConfig, gatewayGateway, oldClient, contactClient, notableClient, botTool)
|
||||
historyService := services.NewHistoryService(chatHistoryBiz)
|
||||
app := server.NewHTTPServer(chatService, sessionService, taskService, gatewayGateway, callbackService, historyService)
|
||||
botConfigImpl := impl.NewBotConfigImpl(db)
|
||||
dingTalkBotBiz := biz.NewDingTalkBotBiz(doDo, handle, botConfigImpl)
|
||||
dingBotService := services.NewDingBotService(configConfig, dingTalkBotBiz)
|
||||
v := server.ProvideAllDingBotServices(dingBotService)
|
||||
dingTalkBotServer := server.NewDingTalkBotServer(v)
|
||||
servers := server.NewServers(configConfig, app, dingTalkBotServer)
|
||||
code := m.Run()
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
func Test_GetUserInfo(t *testing.T) {
|
||||
var c entitys.TaskConfig
|
||||
config := `{"param": {"type": "object", "required": ["number"], "properties": {"number": {"type": "string", "description": "订单编号/流水号"}}}, "request": {"url": "http://www.baidu.com/${number}", "headers": {"Authorization": "${authorization}"}, "method": "GET"}}`
|
||||
err := json.Unmarshal([]byte(config), &c)
|
||||
t.Log(err)
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ package zltx
|
|||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
"ai_scheduler/internal/data/model"
|
||||
|
||||
toolZoarb "ai_scheduler/internal/domain/tools/zltx/order_after_reseller_batch"
|
||||
"ai_scheduler/internal/domain/workflow/runtime"
|
||||
"ai_scheduler/internal/entitys"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ func SetTaskRecExt(requireData *entitys.RequireData, rec *entitys.Recognize) {
|
|||
rec.Ext = pkg.JsonByteIgonErr(TaskExt)
|
||||
}
|
||||
|
||||
func GetTaskRecExt(rec *entitys.Recognize) (ext *entitys.TaskExt, err error) {
|
||||
err = json.Unmarshal(rec.Ext, ext)
|
||||
func GetTaskRecExt(rec *entitys.Recognize) (ext entitys.TaskExt, err error) {
|
||||
err = json.Unmarshal(rec.Ext, &ext)
|
||||
return ext, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"ai_scheduler/internal/pkg"
|
||||
"ai_scheduler/internal/pkg/dingtalk"
|
||||
"ai_scheduler/internal/pkg/util"
|
||||
"ai_scheduler/internal/tools_bot"
|
||||
"ai_scheduler/internal/tool_callback"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
|
@ -25,17 +25,17 @@ type CallbackService struct {
|
|||
dingtalkOldClient *dingtalk.OldClient
|
||||
dingtalkContactClient *dingtalk.ContactClient
|
||||
dingtalkNotableClient *dingtalk.NotableClient
|
||||
botTool *tools_bot.BotTool
|
||||
callBackTool *tool_callback.CallBackTool
|
||||
}
|
||||
|
||||
func NewCallbackService(cfg *config.Config, gateway *gateway.Gateway, dingtalkOldClient *dingtalk.OldClient, dingtalkContactClient *dingtalk.ContactClient, dingtalkNotableClient *dingtalk.NotableClient, botTool *tools_bot.BotTool) *CallbackService {
|
||||
func NewCallbackService(cfg *config.Config, gateway *gateway.Gateway, dingtalkOldClient *dingtalk.OldClient, dingtalkContactClient *dingtalk.ContactClient, dingtalkNotableClient *dingtalk.NotableClient, callBackTool *tool_callback.CallBackTool) *CallbackService {
|
||||
return &CallbackService{
|
||||
cfg: cfg,
|
||||
gateway: gateway,
|
||||
dingtalkOldClient: dingtalkOldClient,
|
||||
dingtalkContactClient: dingtalkContactClient,
|
||||
dingtalkNotableClient: dingtalkNotableClient,
|
||||
botTool: botTool,
|
||||
callBackTool: callBackTool,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ func parseInt64(s string) (int64, bool) {
|
|||
|
||||
func (s *CallbackService) handleDingTalkCallback(c *fiber.Ctx, env Envelope) error {
|
||||
// 校验taskId
|
||||
sessionID, ok := s.botTool.GetSessionByTaskID(env.TaskID)
|
||||
sessionID, ok := s.callBackTool.GetSessionByTaskID(env.TaskID)
|
||||
if !ok {
|
||||
return errorcode.ParamErr("missing session_id for task_id: %s", env.TaskID)
|
||||
}
|
||||
|
|
@ -166,7 +166,7 @@ func (s *CallbackService) handleDingTalkCallback(c *fiber.Ctx, env Envelope) err
|
|||
s.sendStreamTxt(sessionID, msg)
|
||||
|
||||
// 删除映射
|
||||
s.botTool.DelTaskMapping(env.TaskID)
|
||||
s.callBackTool.DelTaskMapping(env.TaskID)
|
||||
|
||||
return c.JSON(fiber.Map{"code": 0, "message": "ok"})
|
||||
case ActionBugOptimizationSubmitProcess:
|
||||
|
|
@ -283,7 +283,7 @@ func (s *CallbackService) handleBugOptimizationSubmitUpdate(ctx context.Context,
|
|||
BaseId: data.BaseId,
|
||||
SheetId: data.SheetId,
|
||||
RecordId: data.RecordId,
|
||||
OperatorId: tools_bot.BotBugOptimizationSubmitAdminUnionId,
|
||||
OperatorId: tool_callback.BotBugOptimizationSubmitAdminUnionId,
|
||||
CreatorUnionId: unionId,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,13 @@
|
|||
package tools_bot
|
||||
package tool_callback
|
||||
|
||||
import (
|
||||
"ai_scheduler/internal/config"
|
||||
errors "ai_scheduler/internal/data/error"
|
||||
"ai_scheduler/internal/data/impl"
|
||||
"ai_scheduler/internal/entitys"
|
||||
"ai_scheduler/internal/pkg"
|
||||
"ai_scheduler/internal/pkg/l_request"
|
||||
"ai_scheduler/internal/pkg/utils_ollama"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
|
@ -15,6 +18,23 @@ import (
|
|||
"xorm.io/builder"
|
||||
)
|
||||
|
||||
type CallBackTool struct {
|
||||
config *config.Config
|
||||
llm *utils_ollama.Client
|
||||
sessionImpl *impl.SessionImpl
|
||||
taskMap map[string]string
|
||||
}
|
||||
|
||||
// NewBotTool 创建直连天下订单详情工具
|
||||
func NewCallBackTool(config *config.Config, llm *utils_ollama.Client, sessionImpl *impl.SessionImpl) *CallBackTool {
|
||||
return &CallBackTool{config: config, llm: llm, sessionImpl: sessionImpl, taskMap: make(map[string]string)}
|
||||
}
|
||||
|
||||
// Execute 执行直连天下订单详情查询
|
||||
func (w *CallBackTool) Execute(ctx context.Context, toolName string, requireData *entitys.RequireData) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// BugOptimizationSubmitForm 工单提交表单参数
|
||||
type BugOptimizationSubmitForm struct {
|
||||
Mark string `json:"mark"` // 工单标识
|
||||
|
|
@ -34,7 +54,7 @@ const (
|
|||
)
|
||||
|
||||
// BugOptimizationSubmit 工单提交
|
||||
func (w *BotTool) BugOptimizationSubmit(ctx context.Context, requireData *entitys.RequireData) (err error) {
|
||||
func (w *CallBackTool) BugOptimizationSubmit(ctx context.Context, requireData *entitys.RequireData) (err error) {
|
||||
// 获取用户信息
|
||||
cond := builder.NewCond()
|
||||
cond = cond.And(builder.Eq{"session_id": requireData.Session})
|
||||
|
|
@ -98,7 +118,7 @@ func (w *BotTool) BugOptimizationSubmit(ctx context.Context, requireData *entity
|
|||
|
||||
// SetTaskMapping 设置 task_id 到 session_id 的映射(内存版)。
|
||||
// 后续考虑使用 Redis,确保幂等与过期清理。
|
||||
func (w *BotTool) SetTaskMapping(taskID, sessionID string) {
|
||||
func (w *CallBackTool) SetTaskMapping(taskID, sessionID string) {
|
||||
if taskID == "" || sessionID == "" {
|
||||
return
|
||||
}
|
||||
|
|
@ -106,12 +126,12 @@ func (w *BotTool) SetTaskMapping(taskID, sessionID string) {
|
|||
}
|
||||
|
||||
// GetSessionByTaskID 读取映射
|
||||
func (w *BotTool) GetSessionByTaskID(taskID string) (string, bool) {
|
||||
func (w *CallBackTool) GetSessionByTaskID(taskID string) (string, bool) {
|
||||
v, ok := w.taskMap[taskID]
|
||||
return v, ok
|
||||
}
|
||||
|
||||
// DelTaskMapping 删除 task_id 到 session_id 的映射(内存版)。
|
||||
func (w *BotTool) DelTaskMapping(taskID string) {
|
||||
func (w *CallBackTool) DelTaskMapping(taskID string) {
|
||||
delete(w.taskMap, taskID)
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package tool_callback
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
var ProviderSetCallBackTools = wire.NewSet(
|
||||
NewCallBackTool,
|
||||
)
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package tools_bot
|
||||
|
||||
import (
|
||||
"github.com/google/wire"
|
||||
)
|
||||
|
||||
var ProviderSetBotTools = wire.NewSet(
|
||||
NewBotTool,
|
||||
)
|
||||
Loading…
Reference in New Issue