Browse Source

fix:edit fastgpt API

jimmyyem 6 months ago
parent
commit
2c3bfcc9eb

+ 30 - 3
desc/wechat/agent.api

@@ -86,11 +86,11 @@ type (
 		TmbId *string `json:"tmbId"`
 		Type *string `json:"type"`
 		Status *string `json:"status"`
+		Avatar *string `json:"avatar"`
 		Name *string `json:"name"`
 		VectorModel *string `json:"vectorModel"`
 		AgentModel *string `json:"agentModel"`
 		Intro *string `json:"intro"`
-		Permission *string `json:"permission"`
 	}
 
 	// Dataset info | 知识库详情
@@ -112,7 +112,7 @@ type (
 	}
 
 	Index {
-		defaultIndex *bool `json:"canWrite"`
+		DefaultIndex *bool `json:"defaultIndex"`
 		Type *string `json:"type"`
 		DataId *string  `json:"dataId"`
 		Text *string `json:"text"`
@@ -138,6 +138,26 @@ type (
 		DatasetId DatasetId `json:"datasetId,optional"`
 	}
 
+	CollectionDetailReq {
+		ID *string `json:"id"`
+	}
+
+	CollectionInfoResp {
+		BaseDataInfo
+
+		Data CollectionInfo `json:"data"`
+	}
+
+	DataDetailReq {
+		ID *string `json:"id"`
+	}
+
+	DataDetailResp {
+		BaseDataInfo
+
+		Data DataInfo `json:"data"`
+	}
+
 	CollectionSimpleInfo {
 		ID *string  `json:"id"`
 		ParentID *string `json:"parentId"`
@@ -157,7 +177,6 @@ type (
 		DatasetId *string `json:"datasetId"`
 		CollectionId *string `json:"collectionId"`
 		SourceName *string `json:"sourceName"`
-		SourceId *string `json:"sourceId"`
 		CanWrite *bool `json:"canWrite"`
 		IsOwner *bool `json:"isOwner"`
 	}
@@ -282,10 +301,18 @@ service Wechat {
     @handler getAgentCollectionList
     post /agent/collection/list (CollectionListReq) returns (CollectionListResp)
 
+	// Get collect detail | 获取collection详情
+	@handler getAgentCollectionInfo
+	post /agent/collection/detail (CollectionDetailReq) returns (CollectionInfoResp)
+
 	// Get data list | 获取data列表
 	@handler getAgentDataList
 	post /agent/data/list (DataListReq) returns (DataListResp)
 
+	// Get data detail | 获取data详情
+	@handler getAgentDataDetail
+	post /agent/data/detail (DataDetailReq) returns (DataDetailResp)
+
 	// Create data | 添加data
 	@handler createAgentData
 	post /agent/data/create (CreateDataInfoReq) returns (BaseDataInfo)

+ 17 - 17
hook/fastgpt/collection.go

@@ -106,24 +106,24 @@ type GetCollectionListReq struct {
 }
 
 type CollectionInfo struct {
-	ID        string      `json:"_id"`
-	ParentID  interface{} `json:"parentId"`
-	TeamID    string      `json:"teamId"`
-	TmbID     string      `json:"tmbId"`
+	ID        string `json:"_id"`
+	ParentID  string `json:"parentId"`
+	TeamID    string `json:"teamId"`
+	TmbID     string `json:"tmbId"`
 	DatasetID struct {
-		ID          string      `json:"_id"`
-		ParentID    interface{} `json:"parentId"`
-		TeamID      string      `json:"teamId"`
-		TmbID       string      `json:"tmbId"`
-		Type        string      `json:"type"`
-		Status      string      `json:"status"`
-		Avatar      string      `json:"avatar"`
-		Name        string      `json:"name"`
-		VectorModel string      `json:"vectorModel"`
-		AgentModel  string      `json:"agentModel"`
-		Intro       string      `json:"intro"`
-		Permission  string      `json:"permission"`
-		UpdateTime  time.Time   `json:"updateTime"`
+		ID          string    `json:"_id"`
+		ParentID    string    `json:"parentId"`
+		TeamID      string    `json:"teamId"`
+		TmbID       string    `json:"tmbId"`
+		Type        string    `json:"type"`
+		Status      string    `json:"status"`
+		Avatar      string    `json:"avatar"`
+		Name        string    `json:"name"`
+		VectorModel string    `json:"vectorModel"`
+		AgentModel  string    `json:"agentModel"`
+		Intro       string    `json:"intro"`
+		Permission  string    `json:"permission"`
+		UpdateTime  time.Time `json:"updateTime"`
 	} `json:"datasetId"`
 	Type          string    `json:"type"`
 	Name          string    `json:"name"`

+ 44 - 0
internal/handler/agent/get_agent_collection_info_handler.go

@@ -0,0 +1,44 @@
+package agent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/agent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /agent/collection/detail agent GetAgentCollectionInfo
+//
+// Get collect detail | 获取collection详情
+//
+// Get collect detail | 获取collection详情
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: CollectionDetailReq
+//
+// Responses:
+//  200: CollectionInfoResp
+
+func GetAgentCollectionInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.CollectionDetailReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := agent.NewGetAgentCollectionInfoLogic(r.Context(), svcCtx)
+		resp, err := l.GetAgentCollectionInfo(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/agent/get_agent_data_detail_handler.go

@@ -0,0 +1,44 @@
+package agent
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/agent"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /agent/data/detail agent GetAgentDataDetail
+//
+// Get data detail | 获取data详情
+//
+// Get data detail | 获取data详情
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: DataDetailReq
+//
+// Responses:
+//  200: DataDetailResp
+
+func GetAgentDataDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DataDetailReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := agent.NewGetAgentDataDetailLogic(r.Context(), svcCtx)
+		resp, err := l.GetAgentDataDetail(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 10 - 0
internal/handler/routes.go

@@ -153,11 +153,21 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/agent/collection/detail",
+					Handler: agent.GetAgentCollectionInfoHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/agent/data/list",
 					Handler: agent.GetAgentDataListHandler(serverCtx),
 				},
 				{
 					Method:  http.MethodPost,
+					Path:    "/agent/data/detail",
+					Handler: agent.GetAgentDataDetailHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
 					Path:    "/agent/data/create",
 					Handler: agent.CreateAgentDataHandler(serverCtx),
 				},

+ 71 - 0
internal/logic/agent/get_agent_collection_info_logic.go

@@ -0,0 +1,71 @@
+package agent
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/hook/fastgpt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAgentCollectionInfoLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetAgentCollectionInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentCollectionInfoLogic {
+	return &GetAgentCollectionInfoLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetAgentCollectionInfoLogic) GetAgentCollectionInfo(req *types.CollectionDetailReq) (*types.CollectionInfoResp, error) {
+	resp, err := fastgpt.GetCollectionDetail(*req.ID)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt get collection failed " + err.Error())
+	}
+
+	if resp.Code == 200 {
+		return &types.CollectionInfoResp{
+			BaseDataInfo: types.BaseDataInfo{
+				Code: 0,
+				Msg:  errormsg.Success,
+			},
+			Data: types.CollectionInfo{
+				ID:            &resp.Data.ID,
+				ParentID:      &resp.Data.ParentID,
+				TmbId:         &resp.Data.TmbID,
+				Type:          &resp.Data.Type,
+				Name:          &resp.Data.Name,
+				TrainingType:  &resp.Data.TrainingType,
+				ChunkSize:     &resp.Data.ChunkSize,
+				ChunkSplitter: &resp.Data.ChunkSplitter,
+				QaPrompt:      &resp.Data.QaPrompt,
+				RawTextLength: &resp.Data.RawTextLength,
+				CanWrite:      &resp.Data.CanWrite,
+				SourceName:    &resp.Data.SourceName,
+				DatasetId: types.DatasetId{
+					ID:          &resp.Data.DatasetID.ID,
+					ParentID:    &resp.Data.DatasetID.ParentID,
+					TeamId:      &resp.Data.DatasetID.TeamID,
+					TmbId:       &resp.Data.DatasetID.TmbID,
+					Type:        &resp.Data.DatasetID.Type,
+					Status:      &resp.Data.DatasetID.Status,
+					Avatar:      &resp.Data.DatasetID.Avatar,
+					Name:        &resp.Data.DatasetID.Name,
+					VectorModel: &resp.Data.DatasetID.VectorModel,
+					AgentModel:  &resp.Data.DatasetID.AgentModel,
+					Intro:       &resp.Data.DatasetID.Intro,
+				},
+			},
+		}, nil
+	}
+
+	return nil, errorx.NewInvalidArgumentError(resp.StatusText)
+}

+ 66 - 0
internal/logic/agent/get_agent_data_detail_logic.go

@@ -0,0 +1,66 @@
+package agent
+
+import (
+	"context"
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/zeromicro/go-zero/core/errorx"
+	"wechat-api/hook/fastgpt"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAgentDataDetailLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewGetAgentDataDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAgentDataDetailLogic {
+	return &GetAgentDataDetailLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx}
+}
+
+func (l *GetAgentDataDetailLogic) GetAgentDataDetail(req *types.DataDetailReq) (*types.DataDetailResp, error) {
+	resp, err := fastgpt.GetDataDetail(*req.ID)
+	if err != nil {
+		return nil, errorx.NewInvalidArgumentError("fastgpt get data failed " + err.Error())
+	}
+
+	if resp.Code == 200 {
+		indexes := make([]types.Index, 0, len(resp.Data.Indexes))
+		for _, val := range resp.Data.Indexes {
+			indexes = append(indexes, types.Index{
+				DefaultIndex: &val.DefaultIndex,
+				Text:         &val.Text,
+				DataId:       &val.DataID,
+				ID:           &val.ID,
+			})
+		}
+
+		return &types.DataDetailResp{
+			BaseDataInfo: types.BaseDataInfo{
+				Code: 0,
+				Msg:  errormsg.Success,
+			},
+			Data: types.DataInfo{
+				ID:           &resp.Data.ID,
+				Q:            &resp.Data.Q,
+				A:            &resp.Data.A,
+				ChunkIndex:   &resp.Data.ChunkIndex,
+				DatasetId:    &resp.Data.DatasetID,
+				CollectionId: &resp.Data.CollectionID,
+				SourceName:   &resp.Data.SourceName,
+				CanWrite:     &resp.Data.CanWrite,
+				IsOwner:      &resp.Data.IsOwner,
+				Indexes:      indexes,
+			},
+		}, nil
+	}
+
+	return nil, errorx.NewInvalidArgumentError(resp.StatusText)
+}

+ 24 - 3
internal/types/types.go

@@ -447,11 +447,11 @@ type DatasetId struct {
 	TmbId       *string `json:"tmbId"`
 	Type        *string `json:"type"`
 	Status      *string `json:"status"`
+	Avatar      *string `json:"avatar"`
 	Name        *string `json:"name"`
 	VectorModel *string `json:"vectorModel"`
 	AgentModel  *string `json:"agentModel"`
 	Intro       *string `json:"intro"`
-	Permission  *string `json:"permission"`
 }
 
 // Dataset info | 知识库详情
@@ -474,7 +474,7 @@ type DatasetInfo struct {
 }
 
 type Index struct {
-	DefaultIndex *bool   `json:"canWrite"`
+	DefaultIndex *bool   `json:"defaultIndex"`
 	Type         *string `json:"type"`
 	DataId       *string `json:"dataId"`
 	Text         *string `json:"text"`
@@ -501,6 +501,28 @@ type CollectionInfo struct {
 	DatasetId      DatasetId `json:"datasetId,optional"`
 }
 
+// swagger:model CollectionDetailReq
+type CollectionDetailReq struct {
+	ID *string `json:"id"`
+}
+
+// swagger:model CollectionInfoResp
+type CollectionInfoResp struct {
+	BaseDataInfo
+	Data CollectionInfo `json:"data"`
+}
+
+// swagger:model DataDetailReq
+type DataDetailReq struct {
+	ID *string `json:"id"`
+}
+
+// swagger:model DataDetailResp
+type DataDetailResp struct {
+	BaseDataInfo
+	Data DataInfo `json:"data"`
+}
+
 // swagger:model CollectionSimpleInfo
 type CollectionSimpleInfo struct {
 	ID             *string `json:"id"`
@@ -522,7 +544,6 @@ type DataInfo struct {
 	DatasetId    *string `json:"datasetId"`
 	CollectionId *string `json:"collectionId"`
 	SourceName   *string `json:"sourceName"`
-	SourceId     *string `json:"sourceId"`
 	CanWrite     *bool   `json:"canWrite"`
 	IsOwner      *bool   `json:"isOwner"`
 }