浏览代码

fix:edit agent list

jimmyyem 8 月之前
父节点
当前提交
2f43801417

+ 2 - 0
desc/wechat/agent.api

@@ -21,8 +21,10 @@ type (
         Examples  *string `json:"examples,optional"`
 
 		DatasetId *string `json:"dataset_id,optional"`
+		Dataset DatasetInfo `json:"dataset,optional"`
 
 		CollectionId *string `json:"collection_id,optional"`
+		Collection CollectionInfo `json:"collection,optional"`
     }
 
     // The response data of agent list | Agent列表数据

+ 34 - 0
internal/logic/agent/get_agent_by_id_logic.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"wechat-api/ent"
 	"wechat-api/ent/agent"
+	"wechat-api/hook/fastgpt"
 
 	"wechat-api/internal/svc"
 	"wechat-api/internal/types"
@@ -36,6 +37,37 @@ func (l *GetAgentByIdLogic) GetAgentById(req *types.IDReq) (*types.AgentInfoResp
 		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
 	}
 
+	var dataset types.DatasetInfo
+	if data.DatasetID != "" {
+		datasetResp, err := fastgpt.GetDatasetDetail(data.DatasetID)
+		if err != nil {
+			return nil, err
+		}
+		dataset.ID = &datasetResp.Data.ID
+		dataset.ParentID = &datasetResp.Data.ParentID
+		dataset.Name = &datasetResp.Data.Name
+		dataset.TeamId = &datasetResp.Data.TeamID
+		dataset.TmbId = &datasetResp.Data.TmbID
+		dataset.Intro = &datasetResp.Data.Intro
+		dataset.Type = &datasetResp.Data.Type
+		dataset.Avatar = &datasetResp.Data.Avatar
+		dataset.Status = &datasetResp.Data.Status
+	}
+
+	var collection types.CollectionInfo
+	if data.CollectionID != "" {
+		collectionResp, err := fastgpt.GetCollectionDetail(data.CollectionID)
+		if err != nil {
+			return nil, err
+		}
+		collection.ID = &collectionResp.Data.ID
+		collection.ParentID = &collectionResp.Data.ParentID
+		collection.TmbId = &collectionResp.Data.TmbID
+		collection.Name = &collectionResp.Data.Name
+		collection.Type = &collectionResp.Data.Type
+		collection.SourceName = &collectionResp.Data.SourceName
+	}
+
 	return &types.AgentInfoResp{
 		BaseDataInfo: types.BaseDataInfo{
 			Code: 0,
@@ -53,7 +85,9 @@ func (l *GetAgentByIdLogic) GetAgentById(req *types.IDReq) (*types.AgentInfoResp
 			Background:   &data.Background,
 			Examples:     &data.Examples,
 			DatasetId:    &data.DatasetID,
+			Dataset:      dataset,
 			CollectionId: &data.CollectionID,
+			Collection:   collection,
 		},
 	}, nil
 }

+ 4 - 0
internal/logic/agent/get_agent_list_logic.go

@@ -55,6 +55,8 @@ func (l *GetAgentListLogic) GetAgentList(req *types.AgentListReq) (*types.AgentL
 	resp.Msg = errormsg.Success
 	resp.Data.Total = data.PageDetails.Total
 
+	dataset, collection := types.DatasetInfo{}, types.CollectionInfo{}
+
 	for _, v := range data.List {
 		resp.Data.Data = append(resp.Data.Data,
 			types.AgentInfo{
@@ -69,7 +71,9 @@ func (l *GetAgentListLogic) GetAgentList(req *types.AgentListReq) (*types.AgentL
 				Background:   &v.Background,
 				Examples:     &v.Examples,
 				DatasetId:    &v.DatasetID,
+				Dataset:      dataset,
 				CollectionId: &v.CollectionID,
+				Collection:   collection,
 			})
 	}
 

+ 5 - 3
internal/types/types.go

@@ -382,9 +382,11 @@ type AgentInfo struct {
 	// background | 背景介绍
 	Background *string `json:"background,optional"`
 	// examples | 对话案例
-	Examples     *string `json:"examples,optional"`
-	DatasetId    *string `json:"dataset_id,optional"`
-	CollectionId *string `json:"collection_id,optional"`
+	Examples     *string        `json:"examples,optional"`
+	DatasetId    *string        `json:"dataset_id,optional"`
+	Dataset      DatasetInfo    `json:"dataset,optional"`
+	CollectionId *string        `json:"collection_id,optional"`
+	Collection   CollectionInfo `json:"collection,optional"`
 }
 
 // The response data of agent list | Agent列表数据