From 10994013511e9e5a159e8437136a4e80bbe09964 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Thu, 3 Apr 2025 14:14:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E6=B7=BB=E5=8A=A0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E6=B7=BB=E5=8A=A0=E5=88=B6=E4=BD=9Cppt?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/im.go | 1 + handler/tool.go | 45 ++++++++++++++++++++++++++++++++++++++ proto/status.go | 9 ++++++++ service/spark/spark-ppt.go | 35 +++++++++++++++++++++++++++++ 4 files changed, 90 insertions(+) diff --git a/dao/im.go b/dao/im.go index ebbdd6d..06806d7 100644 --- a/dao/im.go +++ b/dao/im.go @@ -12,6 +12,7 @@ type Session struct { gorm.Model UserID int `gorm:"column:user_id"` //只能由用户创建 Name string `gorm:"column:name"` + Type int `gorm:"column:type"` //会话类型:1为通用聊天会话,2为提示词会话,3为制作ppt会话 Context json.RawMessage `gorm:"column:context;type:json"` //会话上下文 } diff --git a/handler/tool.go b/handler/tool.go index fda8380..78b65ae 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -57,6 +57,8 @@ func SetUpToolGroup(router *gin.Engine) { toolGroup.POST("/send_mail", SendMailTool) toolGroup.POST("/dashboard", DashBoardStatistics) toolGroup.POST("/spark_ppt_theme_list", GetSparkPPTThemeList) + toolGroup.POST("/spark_create_outline", CreateSparkPPTSOutline) + toolGroup.POST("/spark_create_ppt", CreateSparkPPT) } func SetDeviceStatusV2(c *gin.Context) { @@ -418,6 +420,8 @@ func DashBoardStatistics(c *gin.Context) { } func GetSparkPPTThemeList(c *gin.Context) { + //id := c.Param("id") + //userID, _ := strconv.Atoi(id) var req proto.GetSparkPPTThemeReq if err := c.ShouldBind(&req); err == nil { if req.Style == "" || req.Color == "" || req.Industry == "" { @@ -456,3 +460,44 @@ func GetSparkPPTThemeList(c *gin.Context) { return } } + +func CreateSparkPPTSOutline(c *gin.Context) { + id := c.Param("id") + userID, _ := strconv.Atoi(id) + var req proto.SparkCreateOutlineRequest + if err := c.ShouldBind(&req); err == nil { + if req.Function == "" || req.Query == "" { + c.JSON(http.StatusOK, gin.H{"error": "function or query is empty", "code": proto.ParameterError, "message": "failed"}) + return + } + if req.FileUrl != "" && req.FileName == "" { + c.JSON(http.StatusOK, gin.H{"error": "file name is empty", "code": proto.ParameterError, "message": "failed"}) + return + } + outlineResp, err2 := spark.SparkDoCreateOutline(&req, userID) + if err2 != nil { + c.JSON(http.StatusOK, gin.H{"error": "create outline error", "code": proto.ParameterError, "message": "failed"}) + return + } + c.JSON(http.StatusOK, gin.H{"code": proto.SuccessCode, "message": "success", "data": outlineResp}) + } else { + c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + return + } +} + +func CreateSparkPPT(c *gin.Context) { + id := c.Param("id") + userID, _ := strconv.Atoi(id) + var req proto.SparkCreatePPTByOutlineUserRequest + if err := c.ShouldBind(&req); err == nil { + if req.Function == "" || req.Query == "" { + c.JSON(http.StatusOK, gin.H{"error": "function or query is empty", "code": proto.ParameterError, "message": "failed"}) + return + } + spark.SparkDoCreatePPTByOutline(&req, userID) + } else { + c.JSON(http.StatusOK, gin.H{"error": "parameter error", "code": proto.ParameterError, "message": "failed"}) + return + } +} diff --git a/proto/status.go b/proto/status.go index da871e2..b03f369 100644 --- a/proto/status.go +++ b/proto/status.go @@ -104,6 +104,8 @@ const ( UserToModelImageMsgType = 3 //模型发送文件对话 ModelToUserFileMsgType = 4 + //用户与模型制作ppt的会话 + UserToModelPPTMsgType = 5 //用户与模型制作ppt的会话 ) // 豆包返回的数据停止原因 @@ -152,3 +154,10 @@ const ( UserFileTypeConfig = "config" // 配置文件 UserMaxUploadSize = 1024 * 1024 * 100 ) + +// 会话类型 +const ( + SessionTypeUserWithModelGeneration = 1 // 用户与模型通用会话 + SessionTypeUserPrompt = 2 // 用户与模型提示词 + SessionTypeUserCreatePPT = 3 // 用户与模型制作PPT +) diff --git a/service/spark/spark-ppt.go b/service/spark/spark-ppt.go index bcc463a..2d11d37 100644 --- a/service/spark/spark-ppt.go +++ b/service/spark/spark-ppt.go @@ -2,6 +2,7 @@ package spark import ( "StuAcaWorksAI/proto" + "StuAcaWorksAI/service" "StuAcaWorksAI/worker" "encoding/json" "log" @@ -191,3 +192,37 @@ func SparkGetPPTInfoBySID(model *proto.ModelParam, userReq *proto.SparkCreatePPT log.Println("Spark create ppt by outline Response struct:", response) return response, err } + +// 处理制作大纲请求 +func SparkDoCreateOutline(userReq *proto.SparkCreateOutlineRequest, userID int) (proto.SparkCreateOutlineResponse, error) { + var modelParam proto.ModelParam + var err error + //获取模型 + models, funcs, mferr := service.FindFuncModelListByFunctionV2(userReq.Function) + if mferr != nil { + return proto.SparkCreateOutlineResponse{}, mferr + } + model := models[0] + err = json.Unmarshal([]byte(model.Parameter), &modelParam) + if err != nil { + return proto.SparkCreateOutlineResponse{}, err + } + modelParam.Url = model.Url + modelParam.System = funcs[0].Info //系统功能 + var outline proto.SparkCreateOutlineResponse + + //获取主题列表 + if userReq.FileUrl == "" { + outline, err = SparkCreateOutline(&modelParam, userReq) //根据query生成大纲 + } else { + outline, err = SparkCreateOutlineByDoc(&modelParam, userReq) //根据文档生成大纲 + } + //进行保存 + + return outline, err +} + +// 处理制作PPT请求 +func SparkDoCreatePPTByOutline(userReq *proto.SparkCreatePPTByOutlineUserRequest, userID int) { + +}