修改rag的实体类

This commit is contained in:
Cold
2025-12-02 14:59:07 +08:00
committed by 张斌
parent cd3571554f
commit 5d4c8c8711
6 changed files with 78 additions and 40 deletions

View File

@@ -3,12 +3,13 @@ package ragflow
import (
"context"
"fmt"
"strings"
)
// 数据集内文件管理
// 参考: https://ragflow.com.cn/docs/dev/http_api_reference#数据集内文件管理
// Document 文档结构体
// ... (rest of the code remains the same)
type Document struct {
Id string `json:"id"`
DatasetId string `json:"dataset_id"`
@@ -39,22 +40,27 @@ type UploadDocumentReq struct {
// ListDocumentsReq 列出文档请求
type ListDocumentsReq struct {
Page int `json:"page,omitempty"`
PageSize int `json:"page_size,omitempty"`
OrderBy string `json:"orderby,omitempty"`
Desc bool `json:"desc,omitempty"`
Keywords string `json:"keywords,omitempty"`
Id string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
CreateTimeFrom int64 `json:"create_time_from,omitempty"`
CreateTimeTo int64 `json:"create_time_to,omitempty"`
Page int `json:"page,omitempty"` // 页码,默认 1
PageSize int `json:"page_size,omitempty"` // 每页数量,默认 30
OrderBy string `json:"orderby,omitempty"` // 排序字段create_time默认或 update_time
Desc bool `json:"desc,omitempty"` // 是否降序,默认 true
Keywords string `json:"keywords,omitempty"` // 关键词过滤(匹配文档标题)
Id string `json:"id,omitempty"` // 文档 ID 过滤
Name string `json:"name,omitempty"` // 文档名称过滤
CreateTimeFrom int64 `json:"create_time_from,omitempty"` // 创建时间起始Unix 时间戳0 表示无限制
CreateTimeTo int64 `json:"create_time_to,omitempty"` // 创建时间截止Unix 时间戳0 表示无限制
Suffix []string `json:"suffix,omitempty"` // 文件后缀过滤,如 ["pdf", "txt", "docx"]
Run []string `json:"run,omitempty"` // 处理状态过滤,支持 ["UNSTART", "RUNNING", "CANCEL", "DONE", "FAIL"] 或数字格式 ["0", "1", "2", "3", "4"]
}
// ListDocumentsRes 列出文档响应
// 注意:响应结构与其他 List 接口不同data 是一个对象而非数组
type ListDocumentsRes struct {
Code int `json:"code"`
Data []*Document `json:"data"`
Total int `json:"total"`
Code int `json:"code"` // 状态码0 表示成功
Data struct {
Docs []*Document `json:"docs"` // 文档列表
TotalDatasets int `json:"total_datasets"` // 总文档数
} `json:"data"`
}
// DeleteDocumentsReq 删除文档请求
@@ -64,7 +70,7 @@ type DeleteDocumentsReq struct {
// ListDocuments 列出文档
func (c *Client) ListDocuments(ctx context.Context, datasetId string, req *ListDocumentsReq) (*ListDocumentsRes, error) {
path := fmt.Sprintf("/api/v1/datasets/%s/documents?", datasetId)
path := fmt.Sprintf("/api/v1/datasets/%s/documents", datasetId)
params := map[string]interface{}{}
if req.Page > 0 {
params["page"] = req.Page
@@ -96,11 +102,33 @@ func (c *Client) ListDocuments(ctx context.Context, datasetId string, req *ListD
params["create_time_to"] = req.CreateTimeTo
}
// 构造查询字符串
query := buildQueryString(params)
var queryParts []string
if query != "" {
path += "?" + query
queryParts = append(queryParts, query)
}
// 处理数组参数suffix文件后缀过滤
// API 要求多个值时重复参数名suffix=pdf&suffix=txt
// 这里使用 fmt.Sprintf 来构造每个参数值
for _, suffix := range req.Suffix {
queryParts = append(queryParts, fmt.Sprintf("suffix=%s", suffix))
}
// 处理数组参数run处理状态过滤
// 支持数字格式("0"-"4")或文本格式("UNSTART", "RUNNING", "CANCEL", "DONE", "FAIL"
// 这里使用 fmt.Sprintf 来构造每个参数值
for _, run := range req.Run {
queryParts = append(queryParts, fmt.Sprintf("run=%s", run))
}
// 构造最终请求路径
if len(queryParts) > 0 {
path += "?" + strings.Join(queryParts, "&")
}
// 发送请求并处理响应
var res ListDocumentsRes
if err := c.request(ctx, "GET", path, nil, &res); err != nil {
return nil, err