-
Notifications
You must be signed in to change notification settings - Fork 79
/
llmodel.go
124 lines (101 loc) · 2.52 KB
/
llmodel.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package wrobot
import (
"github.com/gin-gonic/gin"
"github.com/opentdp/wrest-chat/dbase/llmodel"
"github.com/opentdp/wrest-chat/wclient/robot"
)
type LLModel struct{}
// @Summary 模型列表
// @Produce json
// @Tags BOT::大语言模型
// @Param body body llmodel.FetchAllParam true "获取模型列表参数"
// @Success 200 {array} tables.LLModel
// @Router /bot/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 BOT::大语言模型
// @Param body body llmodel.FetchParam true "获取模型参数"
// @Success 200 {object} tables.LLModel
// @Router /bot/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 BOT::大语言模型
// @Param body body llmodel.CreateParam true "添加模型参数"
// @Success 200
// @Router /bot/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)
robot.Reset()
} else {
c.Set("Error", err)
}
}
// @Summary 修改模型
// @Produce json
// @Tags BOT::大语言模型
// @Param body body llmodel.UpdateParam true "修改模型参数"
// @Success 200
// @Router /bot/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", "更新成功")
robot.Reset()
} else {
c.Set("Error", err)
}
}
// @Summary 删除模型
// @Produce json
// @Tags BOT::大语言模型
// @Param body body llmodel.DeleteParam true "删除模型参数"
// @Success 200
// @Router /bot/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", "删除成功")
robot.Reset()
} else {
c.Set("Error", err)
}
}