Skip to content

Commit

Permalink
feat: 添加AI模型接口
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Feb 26, 2024
1 parent 0105f50 commit 202caa9
Show file tree
Hide file tree
Showing 3 changed files with 420 additions and 7 deletions.
125 changes: 125 additions & 0 deletions httpd/console/llmodel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package console

import (
"github.com/gin-gonic/gin"

"github.com/opentdp/wechat-rest/dbase/llmodel"
)

type LLModel struct{}

// @Summary 模型列表
// @Produce json
// @Tags 中台::大语言模型
// @Param body body llmodel.FetchAllParam true "获取模型列表参数"
// @Success 200 {object} []tables.LLModel
// @Router /capi/llmodel./list [post]
func (*LLModel) list(c *gin.Context) {

var rq *llmodel.FetchAllParam

if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}

if lst, err := llmodel.FetchAll(rq); err == nil {
c.Set("Payload", lst)
} else {
c.Set("Error", err)
}

}

// @Summary 获取模型
// @Produce json
// @Tags 中台::大语言模型
// @Param body body llmodel.FetchParam true "获取模型参数"
// @Success 200 {object} tables.LLModel
// @Router /capi/llmodel./detail [post]
func (*LLModel) detail(c *gin.Context) {

var rq *llmodel.FetchParam

if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}

if res, err := llmodel.Fetch(rq); err == nil {
c.Set("Payload", res)
} else {
c.Set("Error", err)
}

}

// @Summary 添加模型
// @Produce json
// @Tags 中台::大语言模型
// @Param body body llmodel.CreateParam true "添加模型参数"
// @Success 200
// @Router /capi/llmodel./create [post]
func (*LLModel) create(c *gin.Context) {

var rq *llmodel.CreateParam

if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}

if id, err := llmodel.Create(rq); err == nil {
c.Set("Message", "添加成功")
c.Set("Payload", id)
} else {
c.Set("Error", err)
}

}

// @Summary 修改模型
// @Produce json
// @Tags 中台::大语言模型
// @Param body body llmodel.UpdateParam true "修改模型参数"
// @Success 200
// @Router /capi/llmodel./update [post]
func (*LLModel) update(c *gin.Context) {

var rq *llmodel.UpdateParam

if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}

if err := llmodel.Update(rq); err == nil {
c.Set("Message", "更新成功")
} else {
c.Set("Error", err)
}

}

// @Summary 删除模型
// @Produce json
// @Tags 中台::大语言模型
// @Param body body llmodel.DeleteParam true "删除模型参数"
// @Success 200
// @Router /capi/llmodel./delete [post]
func (*LLModel) delete(c *gin.Context) {

var rq *llmodel.DeleteParam

if err := c.ShouldBind(&rq); err != nil {
c.Set("Error", err)
return
}

if err := llmodel.Delete(rq); err == nil {
c.Set("Message", "删除成功")
} else {
c.Set("Error", err)
}

}
21 changes: 14 additions & 7 deletions httpd/console/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,25 @@ func Route() {
rg.POST("chatroom/update", chatroom.update)
rg.POST("chatroom/delete", chatroom.delete)

profile := Profile{}
rg.POST("profile/list", profile.list)
rg.POST("profile/create", profile.create)
rg.POST("profile/detail", profile.detail)
rg.POST("profile/update", profile.update)
rg.POST("profile/delete", profile.delete)

keyword := Keyword{}
rg.POST("keyword/list", keyword.list)
rg.POST("keyword/create", keyword.create)
rg.POST("keyword/detail", keyword.detail)
rg.POST("keyword/update", keyword.update)
rg.POST("keyword/delete", keyword.delete)

llmodel := LLModel{}
rg.POST("llmodel/list", llmodel.list)
rg.POST("llmodel/create", llmodel.create)
rg.POST("llmodel/detail", llmodel.detail)
rg.POST("llmodel/update", llmodel.update)
rg.POST("llmodel/delete", llmodel.delete)

profile := Profile{}
rg.POST("profile/list", profile.list)
rg.POST("profile/create", profile.create)
rg.POST("profile/detail", profile.detail)
rg.POST("profile/update", profile.update)
rg.POST("profile/delete", profile.delete)

}
Loading

0 comments on commit 202caa9

Please sign in to comment.