feat(kol): AI assist HTTP endpoints
This commit is contained in:
@@ -15,6 +15,7 @@ type KolManageHandler struct {
|
|||||||
profileSvc *app.KolProfileService
|
profileSvc *app.KolProfileService
|
||||||
pkgSvc *app.KolPackageService
|
pkgSvc *app.KolPackageService
|
||||||
promptSvc *app.KolPromptService
|
promptSvc *app.KolPromptService
|
||||||
|
assistSvc *app.KolAssistService
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKolManageHandler(a *bootstrap.App) *KolManageHandler {
|
func NewKolManageHandler(a *bootstrap.App) *KolManageHandler {
|
||||||
@@ -24,6 +25,7 @@ func NewKolManageHandler(a *bootstrap.App) *KolManageHandler {
|
|||||||
profileSvc: profileSvc,
|
profileSvc: profileSvc,
|
||||||
pkgSvc: app.NewKolPackageService(profileSvc, a.KolPackages, a.KolPrompts),
|
pkgSvc: app.NewKolPackageService(profileSvc, a.KolPackages, a.KolPrompts),
|
||||||
promptSvc: app.NewKolPromptService(a.DB, profileSvc, a.KolPackages, a.KolPrompts, a.KolPromptAsset),
|
promptSvc: app.NewKolPromptService(a.DB, profileSvc, a.KolPackages, a.KolPrompts, a.KolPromptAsset),
|
||||||
|
assistSvc: app.NewKolAssistService(profileSvc, a.KolAssists, a.LLM, a.RabbitMQ),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +323,54 @@ func (h *KolManageHandler) PublishPrompt(c *gin.Context) {
|
|||||||
response.Success(c, gin.H{"ok": true})
|
response.Success(c, gin.H{"ok": true})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *KolManageHandler) AssistSubmit(c *gin.Context) {
|
||||||
|
var req app.AssistRequest
|
||||||
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
|
response.Error(c, response.ErrBadRequest(40001, "invalid_params", err.Error()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
actor, ok := actorFromRequest(c)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
taskID, err := h.assistSvc.Submit(c.Request.Context(), actor, req)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, app.KolAssistSubmitResponse{TaskID: taskID})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *KolManageHandler) AssistGet(c *gin.Context) {
|
||||||
|
taskID := c.Param("id")
|
||||||
|
if taskID == "" {
|
||||||
|
response.Error(c, response.ErrBadRequest(40001, "invalid_id", "task id must not be empty"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
actor, ok := actorFromRequest(c)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
task, err := h.assistSvc.Get(c.Request.Context(), actor, taskID)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
data, err := app.NewKolAssistTaskResponse(task)
|
||||||
|
if err != nil {
|
||||||
|
response.Error(c, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
response.Success(c, data)
|
||||||
|
}
|
||||||
|
|
||||||
func actorFromRequest(c *gin.Context) (auth.Actor, bool) {
|
func actorFromRequest(c *gin.Context) (auth.Actor, bool) {
|
||||||
actor, ok := auth.ActorFromCtx(c.Request.Context())
|
actor, ok := auth.ActorFromCtx(c.Request.Context())
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
@@ -71,6 +71,8 @@ func RegisterRoutes(app *bootstrap.App) {
|
|||||||
kolManage.DELETE("/prompts/:id", kolManageHandler.DeletePrompt)
|
kolManage.DELETE("/prompts/:id", kolManageHandler.DeletePrompt)
|
||||||
kolManage.POST("/prompts/:id/draft", kolManageHandler.SaveDraft)
|
kolManage.POST("/prompts/:id/draft", kolManageHandler.SaveDraft)
|
||||||
kolManage.POST("/prompts/:id/publish", kolManageHandler.PublishPrompt)
|
kolManage.POST("/prompts/:id/publish", kolManageHandler.PublishPrompt)
|
||||||
|
kolManage.POST("/assist", kolManageHandler.AssistSubmit)
|
||||||
|
kolManage.GET("/assist/:id", kolManageHandler.AssistGet)
|
||||||
|
|
||||||
articles := protected.Group("/tenant/articles")
|
articles := protected.Group("/tenant/articles")
|
||||||
artHandler := NewArticleHandler(app)
|
artHandler := NewArticleHandler(app)
|
||||||
|
|||||||
Reference in New Issue
Block a user