From 1960a85ead8cf8d0e7576fcba9a3316d4bafbb2e Mon Sep 17 00:00:00 2001 From: RockYang Date: Fri, 13 Sep 2024 18:32:13 +0800 Subject: [PATCH] add tid field for chat app role --- api/handler/admin/chat_app_handler.go | 15 +++++++++++++++ api/store/model/chat_role.go | 1 + api/store/vo/chat_role.go | 4 +++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/handler/admin/chat_app_handler.go b/api/handler/admin/chat_app_handler.go index 8b54eec9..e068c645 100644 --- a/api/handler/admin/chat_app_handler.go +++ b/api/handler/admin/chat_app_handler.go @@ -75,13 +75,18 @@ func (h *ChatAppHandler) List(c *gin.Context) { // initialize model mane for role modelIds := make([]int, 0) + typeIds := make([]int, 0) for _, v := range items { if v.ModelId > 0 { modelIds = append(modelIds, v.ModelId) } + if v.Tid > 0 { + typeIds = append(typeIds, v.Tid) + } } modelNameMap := make(map[int]string) + typeNameMap := make(map[int]string) if len(modelIds) > 0 { var models []model.ChatModel tx := h.DB.Where("id IN ?", modelIds).Find(&models) @@ -91,6 +96,15 @@ func (h *ChatAppHandler) List(c *gin.Context) { } } } + if len(typeIds) > 0 { + var appTypes []model.AppType + tx := h.DB.Where("id IN ?", typeIds).Find(&appTypes) + if tx.Error == nil { + for _, m := range appTypes { + typeNameMap[int(m.Id)] = m.Name + } + } + } for _, v := range items { var role vo.ChatRole @@ -100,6 +114,7 @@ func (h *ChatAppHandler) List(c *gin.Context) { role.CreatedAt = v.CreatedAt.Unix() role.UpdatedAt = v.UpdatedAt.Unix() role.ModelName = modelNameMap[role.ModelId] + role.TypeName = typeNameMap[role.Tid] roles = append(roles, role) } } diff --git a/api/store/model/chat_role.go b/api/store/model/chat_role.go index 50e438bf..95dfbce6 100644 --- a/api/store/model/chat_role.go +++ b/api/store/model/chat_role.go @@ -2,6 +2,7 @@ package model type ChatRole struct { BaseModel + Tid int Key string `gorm:"column:marker;unique"` // 角色唯一标识 Name string // 角色名称 Context string `gorm:"column:context_json"` // 角色语料信息 json diff --git a/api/store/vo/chat_role.go b/api/store/vo/chat_role.go index 4bd530f8..ad82d949 100644 --- a/api/store/vo/chat_role.go +++ b/api/store/vo/chat_role.go @@ -4,7 +4,8 @@ import "geekai/core/types" type ChatRole struct { BaseVo - Key string `json:"key"` // 角色唯一标识 + Key string `json:"key"` // 角色唯一标识 + Tid uint `json:"tid"` Name string `json:"name"` // 角色名称 Context []types.Message `json:"context"` // 角色语料信息 HelloMsg string `json:"hello_msg"` // 打招呼的消息 @@ -13,4 +14,5 @@ type ChatRole struct { SortNum int `json:"sort"` // 排序 ModelId int `json:"model_id"` // 绑定模型 ID ModelName string `json:"model_name"` // 模型名称 + TypeName string `json:"type_name"` // 分类名称 }