123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- package fastgpt
- import (
- "context"
- "github.com/suyuan32/simple-admin-common/msg/errormsg"
- "github.com/zeromicro/go-zero/core/errorx"
- "strconv"
- "time"
- apps "wechat-api/mongo_model/apps"
- "wechat-api/internal/svc"
- "wechat-api/internal/types"
- "github.com/zeromicro/go-zero/core/logx"
- )
- type CreateAppLogic struct {
- logx.Logger
- ctx context.Context
- svcCtx *svc.ServiceContext
- }
- func NewCreateAppLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAppLogic {
- return &CreateAppLogic{
- Logger: logx.WithContext(ctx),
- ctx: ctx,
- svcCtx: svcCtx}
- }
- func (l *CreateAppLogic) CreateApp(req *types.CreateAppsReq) (resp *types.BaseMsgResp, err error) {
- organizationId := l.ctx.Value("organizationId").(uint64)
- organizationIdStr := strconv.FormatUint(organizationId, 10)
- user, err := l.svcCtx.MongoModel.UsersModel.FindOneByUsername(context.TODO(), organizationIdStr)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error())
- }
- teamMember, err := l.svcCtx.MongoModel.TeamMembersModel.FindOneByUserId(context.TODO(), user.ID)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt get list failed " + err.Error())
- }
- intro := ""
- if req.Intro != nil {
- intro = *req.Intro
- }
- var apps_info *apps.Apps
- if req.Type == "simple" {
- // 创建默认智能体
- apps_info = &apps.Apps{
- ParentID: nil,
- TeamID: teamMember.TeamID,
- TmbID: teamMember.ID,
- Name: req.Name,
- Type: "simple",
- Version: "v2",
- Avatar: "/imgs/app/avatar/simple.svg",
- Intro: intro,
- TeamTags: []string{},
- Modules: []apps.AppModule{
- {
- NodeID: "userGuide",
- Name: "系统配置",
- Intro: "",
- FlowNodeType: "userGuide",
- Position: apps.Position{
- X: 531.242273606555,
- Y: -486.761172954975,
- },
- Version: "481",
- Inputs: []apps.AppInput{},
- Outputs: []apps.AppOutput{},
- },
- {
- NodeID: "workflowStartNodeId",
- Name: "流程开始",
- Intro: "",
- Avatar: "core/workflow/template/workflowStart",
- FlowNodeType: "workflowStart",
- Position: apps.Position{
- X: 558.40823764155,
- Y: 123.723874291941,
- },
- Version: "481",
- Inputs: []apps.AppInput{
- {
- Key: "userChatInput",
- RenderTypeList: []string{"reference", "textarea"},
- ValueType: "string",
- Label: "workflow:user_question",
- ToolDescription: "workflow:user_question",
- Required: true,
- },
- },
- Outputs: []apps.AppOutput{
- {
- ID: "userChatInput",
- Key: "userChatInput",
- Label: "common:core.module.input.label.user question",
- Type: "static",
- ValueType: "string",
- },
- {
- ID: "userFiles",
- Key: "userFiles",
- Label: "app:workflow.user_file_input",
- Description: "app:workflow.user_file_input_desc",
- Type: "static",
- ValueType: "arrayString",
- },
- },
- },
- {
- NodeID: "7BdojPlukIQw",
- Name: "AI 对话",
- Intro: "AI 大模型对话",
- Avatar: "core/workflow/template/aiChat",
- FlowNodeType: "chatNode",
- ShowStatus: true,
- Position: apps.Position{
- X: 1106.32383879608,
- Y: -350.603067468347,
- },
- Version: "4813",
- Inputs: []apps.AppInput{
- {
- Key: "model",
- RenderTypeList: []string{"settingLLMModel", "reference"},
- ValueType: "string",
- Value: "DeepSeek-V3",
- },
- {
- Key: "temperature",
- RenderTypeList: []string{"hidden"},
- ValueType: "number",
- Value: int32(0),
- Min: getInt32(0),
- Max: getInt32(10),
- Step: getInt32(1),
- },
- {
- Key: "maxToken",
- RenderTypeList: []string{"hidden"},
- ValueType: "number",
- Value: int32(2000),
- Min: getInt32(100),
- Max: getInt32(4000),
- Step: getInt32(50),
- },
- {
- Key: "isResponseAnswerText",
- RenderTypeList: []string{"hidden"},
- ValueType: "boolean",
- Value: true,
- },
- {
- Key: "aiChatQuoteRole",
- RenderTypeList: []string{"hidden"},
- ValueType: "string",
- Value: "system",
- },
- {
- Key: "quoteTemplate",
- RenderTypeList: []string{"hidden"},
- ValueType: "string",
- },
- {
- Key: "quotePrompt",
- RenderTypeList: []string{"hidden"},
- ValueType: "string",
- },
- {
- Key: "systemPrompt",
- RenderTypeList: []string{"textarea", "reference"},
- Max: getInt32(3000),
- ValueType: "string",
- Label: "core.ai.Prompt",
- Description: "core.app.tip.systemPromptTip",
- Placeholder: "core.app.tip.chatNodeSystemPromptTip",
- Value: "",
- },
- {
- Key: "history",
- RenderTypeList: []string{"numberInput", "reference"},
- ValueType: "chatHistory",
- Label: "core.module.input.label.chat history",
- Required: true,
- Min: getInt32(0),
- Max: getInt32(30),
- Value: int32(6),
- },
- {
- Key: "userChatInput",
- RenderTypeList: []string{"reference", "textarea"},
- ValueType: "string",
- Label: "common:core.module.input.label.user question",
- Required: true,
- ToolDescription: "common:core.module.input.label.user question",
- Value: []interface{}{"workflowStartNodeId", "userChatInput"},
- },
- {
- Key: "quoteQA",
- RenderTypeList: []string{"settingDatasetQuotePrompt"},
- Label: "",
- DebugLabel: "common:core.module.Dataset quote.label",
- Description: "",
- ValueType: "datasetQuote",
- },
- {
- Key: "fileUrlList",
- RenderTypeList: []string{"reference", "input"},
- Label: "app:file_quote_link",
- DebugLabel: "app:file_quote_link",
- ValueType: "arrayString",
- Value: [][]interface{}{{"workflowStartNodeId", "userFiles"}},
- },
- {
- Key: "aiChatVision",
- RenderTypeList: []string{"hidden"},
- ValueType: "boolean",
- Value: true,
- },
- },
- Outputs: []apps.AppOutput{
- {
- ID: "history",
- Key: "history",
- Required: true,
- Label: "common:core.module.output.label.New context",
- Description: "common:core.module.output.description.New context",
- ValueType: "chatHistory",
- ValueDesc: "{\n obj: System | Human | AI;\n value: string;\n}[]",
- Type: "static",
- },
- {
- ID: "answerText",
- Key: "answerText",
- Required: true,
- Label: "common:core.module.output.label.Ai response content",
- Description: "common:core.module.output.description.Ai response content",
- ValueType: "string",
- Type: "static",
- },
- },
- },
- },
- Edges: []apps.Edge{
- {
- Source: "workflowStartNodeId",
- Target: "7BdojPlukIQw",
- SourceHandle: "workflowStartNodeId-source-right",
- TargetHandle: "7BdojPlukIQw-target-left",
- },
- },
- PluginData: apps.PluginData{
- ID: mustParseObjectID("67da46b29667c5bf21203554"),
- NodeVersion: "67da46d29667c5bf2120361a",
- },
- InheritPermission: true,
- VersionNumber: int32(0),
- ChatConfig: apps.ChatConfig{
- WelcomeText: "",
- Variables: []interface{}{},
- QuestionGuide: false,
- TTSConfig: apps.TTSConfig{
- Type: "web",
- },
- WhisperConfig: apps.WhisperConfig{
- Open: false,
- AutoSend: false,
- AutoTTSResponse: false,
- },
- ScheduledTriggerConfig: nil,
- ChatInputGuide: apps.ChatInputGuide{
- Open: false,
- TextList: []string{},
- CustomUrl: "",
- },
- Instruction: "",
- ID: mustParseObjectID("67da46d29667c5bf2120361d"),
- },
- UpdateTime: time.Date(2025, 3, 19, 4, 24, 4, 394000000, time.UTC),
- ScheduledTriggerConfig: nil,
- ScheduledTriggerNextTime: nil,
- }
- } else {
- apps_info = &apps.Apps{
- ParentID: nil,
- TeamID: teamMember.TeamID,
- TmbID: teamMember.ID,
- Name: req.Name,
- Type: "advanced",
- Version: "v2",
- Avatar: "/imgs/app/avatar/workflow.svg",
- Intro: intro,
- TeamTags: []string{},
- Modules: []apps.AppModule{
- {
- NodeID: "userGuide",
- Name: "common:core.module.template.system_config",
- Intro: "common:core.module.template.system_config_info",
- Avatar: "core/workflow/template/systemConfig",
- FlowNodeType: "userGuide",
- Position: apps.Position{
- X: 262.273233881709,
- Y: -476.002411365981,
- },
- Version: "481",
- Inputs: []apps.AppInput{
- {
- Key: "welcomeText",
- RenderTypeList: []string{"hidden"},
- ValueType: "string",
- Label: "core.app.Welcome Text",
- Value: "",
- }, {
- Key: "variables",
- RenderTypeList: []string{"hidden"},
- ValueType: "any",
- Label: "core.app.Chat Variable",
- Value: []string{},
- }, {
- Key: "questionGuide",
- RenderTypeList: []string{"hidden"},
- ValueType: "boolean",
- Label: "core.app.Question Guide",
- Value: false,
- }, {
- Key: "tts",
- RenderTypeList: []string{"hidden"},
- ValueType: "any",
- Label: "",
- Value: apps.AppInputValue{
- Type: "web",
- },
- }, {
- Key: "whisper",
- RenderTypeList: []string{"hidden"},
- ValueType: "any",
- Label: "",
- Value: apps.AppInputValue{
- Open: false,
- AutoSend: false,
- AutoTTSResponse: false,
- },
- }, {
- Key: "scheduleTrigger",
- RenderTypeList: []string{"hidden"},
- ValueType: "any",
- Label: "",
- },
- },
- Outputs: []apps.AppOutput{},
- },
- {
- NodeID: "448745",
- Name: "common:core.module.template.work_start",
- Intro: "",
- Avatar: "core/workflow/template/workflowStart",
- FlowNodeType: "workflowStart",
- Position: apps.Position{
- X: 632.368838596004,
- Y: -347.744649294401,
- },
- Version: "481",
- Inputs: []apps.AppInput{
- {
- Key: "userChatInput",
- RenderTypeList: []string{"reference", "textarea"},
- ValueType: "string",
- Label: "common:core.module.input.label.user question",
- ToolDescription: "common:core.module.input.label.user question",
- Required: true,
- },
- },
- Outputs: []apps.AppOutput{
- {
- ID: "userChatInput",
- Key: "userChatInput",
- Label: "common:core.module.input.label.user question",
- Type: "static",
- ValueType: "string",
- },
- },
- },
- },
- Edges: []apps.Edge{},
- PluginData: apps.PluginData{
- ID: mustParseObjectID("67dce247bd93cb6e085a6bda"),
- NodeVersion: "481",
- },
- InheritPermission: true,
- VersionNumber: int32(0),
- UpdateTime: time.Date(2025, 3, 19, 4, 24, 4, 394000000, time.UTC),
- }
- }
- if apps_info != nil {
- err = l.svcCtx.MongoModel.AppsModel.Insert(context.TODO(), apps_info)
- if err != nil {
- return nil, errorx.NewInvalidArgumentError("fastgpt create failed " + err.Error())
- }
- } else {
- return nil, errorx.NewInvalidArgumentError("fastgpt create failed ")
- }
- return &types.BaseMsgResp{Msg: errormsg.Success}, nil
- }
|