123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- package fastgpt
- import (
- "errors"
- )
- type DataResp struct {
- Code int `json:"code"`
- StatusText string `json:"statusText"`
- Message string `json:"message"`
- Data string `json:"data,optional"`
- }
- type CreateBulkDataReq struct {
- CollectionID string `json:"collectionId"`
- TrainingMode string `json:"trainingMode"`
- Prompt string `json:"prompt,optional"`
- BillID string `json:"billId,optional"`
- Data []DataQuestion `json:"data"`
- }
- type DataQuestion struct {
- Q string `json:"q"`
- A string `json:"a,optional"`
- Indexes []Index `json:"indexes,omitempty,optional"`
- }
- type Index struct {
- DataId string `json:"dataId,optional"`
- DefaultIndex bool `json:"defaultIndex,optional"`
- Text string `json:"text"`
- }
- type CreateBulkDataResp struct {
- Code int `json:"code"`
- StatusText string `json:"statusText"`
- Data struct {
- InsertLen uint64 `json:"insertLen"`
- OverToken []any `json:"overToken"`
- Repeat []any `json:"repeat"`
- Error []any `json:"error"`
- } `json:"data"`
- }
- type GetDataListReq struct {
- PageNum int `json:"pageNum,optional"`
- PageSize int `json:"pageSize,optional"`
- CollectionId string `json:"collectionId,optional"`
- SearchText string `json:"searchText,optional"`
- }
- type DataInfo struct {
- ID string `json:"id"`
- TeamID string `json:"teamId"`
- Q string `json:"q"`
- A string `json:"a"`
- ChunkIndex uint64 `json:"chunkIndex"`
- Indexes []struct {
- DefaultIndex bool `json:"defaultIndex"`
- DataID string `json:"dataId"`
- Text string `json:"text"`
- ID string `json:"_id"`
- } `json:"indexes"`
- DatasetID string `json:"datasetId"`
- CollectionID string `json:"collectionId"`
- SourceName string `json:"sourceName"`
- SourceID string `json:"sourceId"`
- IsOwner bool `json:"isOwner"`
- CanWrite bool `json:"canWrite"`
- }
- type DataListResp struct {
- Code int `json:"code"`
- StatusText string `json:"statusText"`
- Message string `json:"message"`
- Data struct {
- PageNum int `json:"pageNum"`
- PageSize int `json:"pageSize"`
- Data []struct {
- ID string `json:"_id"`
- DatasetID string `json:"datasetId"`
- CollectionID string `json:"collectionId"`
- Q string `json:"q"`
- A string `json:"a"`
- ChunkIndex uint64 `json:"chunkIndex"`
- } `json:"data,optional"`
- Total int `json:"total"`
- } `json:"data,optional"`
- }
- type DataDetail struct {
- Code int `json:"code"`
- StatusText string `json:"statusText"`
- Message string `json:"message"`
- Data DataInfo `json:"data,optional"`
- }
- type UpdateDataReq struct {
- DataId string `json:"dataId" validate:"required"`
- Q string `json:"q" validate:"required"`
- A string `json:"a" validate:"required"`
- Indexes []Index `json:"indexes,omitempty,optional"`
- }
- // GetDataDetail 获取数据详情
- func GetDataDetail(id string) (data *DataDetail, err error) {
- resp, err := NewResty().
- R().
- SetResult(&data).
- SetQueryParam("id", id).
- Get("core/dataset/data/detail")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
- // GetDataList 获取数据列表
- func GetDataList(params *GetDataListReq) (dataList *DataListResp, err error) {
- resp, err := NewResty().
- R().
- SetResult(&dataList).
- SetBody(params).
- Post("core/dataset/data/list")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
- // CreateBulkData 批量创建数据
- func CreateBulkData(data *CreateBulkDataReq) (response *CreateBulkDataResp, err error) {
- resp, err := NewResty().
- R().
- SetResult(&response).
- SetBody(*data).
- Post("core/dataset/data/pushData")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
- // DiyCreateBulkData 批量创建数据
- func DiyCreateBulkData(token string, data *CreateBulkDataReq) (response *CreateBulkDataResp, err error) {
- resp, err := NewDiyResty(token).
- R().
- SetResult(&response).
- SetBody(*data).
- Post("core/dataset/data/pushData")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
- // UpdateData 修改数据
- func UpdateData(data *UpdateDataReq) (response *DataResp, err error) {
- resp, err := NewResty().
- R().
- SetResult(&response).
- SetBody(*data).
- Put("core/dataset/data/update")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
- // DeleteData 删除数据
- func DeleteData(id string) (response *DataResp, err error) {
- resp, err := NewResty().
- R().
- SetResult(&response).
- SetQueryParam("id", id).
- Delete("core/dataset/data/delete")
- if err != nil {
- return nil, err
- }
- if resp.IsError() {
- return nil, errors.New(resp.String())
- }
- return
- }
|