Skip to content

Commit 508c9ca

Browse files
committed
更新文档删除接口返回类型为HttpResponseMessage,修改相关DTO以支持JSON序列化,新增文档类型和元数据结构,优化CreateByText请求体结构。
1 parent e3e5b63 commit 508c9ca

10 files changed

Lines changed: 224 additions & 76 deletions

File tree

DifySharp.Demo.AspNet/Program.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
var response = await api.PostCreateDocumentByTextAsync(
3434
"<your-dataset-id>", // add a dataset id here
3535
new CreateByText.RequestBody(
36-
$"Test Document {uuid}",
37-
"Test Content",
38-
IndexingTechnique.Economy,
39-
DocForm.TextModel,
40-
"",
41-
new ProcessRule(
36+
Name: $"Test Document {uuid}",
37+
Text: "Test Content",
38+
DocType: null,
39+
DocMetadata: null,
40+
IndexingTechnique: IndexingTechnique.Economy,
41+
DocForm: DocForm.TextModel,
42+
DocLanguage: "",
43+
ProcessRule: new ProcessRule(
4244
"automatic",
4345
new Rules(
4446
[
@@ -63,7 +65,7 @@
6365
)
6466
)
6567
),
66-
new CreateByText.RetrievalModel(
68+
RetrievalModel: new CreateByText.RetrievalModel(
6769
CreateByText.SearchMethod.HybridSearch,
6870
false,
6971
new CreateByText.RerankingModel(
@@ -74,8 +76,8 @@
7476
false,
7577
0.9f
7678
),
77-
"",
78-
""
79+
EmbeddingModel: "",
80+
EmbeddingModelProvider: ""
7981
));
8082

8183
var document = response.Document;

DifySharp.Test/Apis/KnowledgeBaseApiTest/ChunkApiTest.cs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public ChunkApiTestFixture()
3434

3535
// crate a document
3636
var createDocRequestBody = new CreateByText.RequestBody(
37-
$"Chunk Api Test Document {uuid}",
38-
"Test Content \n\n Test Content \n\n Test Content",
39-
IndexingTechnique.Economy,
40-
DocForm.TextModel,
41-
"",
42-
new ProcessRule(
37+
Name: $"Chunk Api Test Document {uuid}",
38+
Text: "Test Content \n\n Test Content \n\n Test Content",
39+
DocType: null,
40+
DocMetadata: null,
41+
IndexingTechnique: IndexingTechnique.Economy,
42+
DocForm: DocForm.TextModel,
43+
DocLanguage: "",
44+
ProcessRule: new ProcessRule(
4345
"automatic",
4446
new Rules(
4547
[
@@ -64,7 +66,7 @@ public ChunkApiTestFixture()
6466
)
6567
)
6668
),
67-
new CreateByText.RetrievalModel(
69+
RetrievalModel: new CreateByText.RetrievalModel(
6870
CreateByText.SearchMethod.HybridSearch,
6971
false,
7072
new CreateByText.RerankingModel(
@@ -75,8 +77,8 @@ public ChunkApiTestFixture()
7577
false,
7678
0.9f
7779
),
78-
"",
79-
""
80+
EmbeddingModel: "",
81+
EmbeddingModelProvider: ""
8082
);
8183

8284
Document = Client.PostCreateDocumentByTextAsync(

DifySharp.Test/Apis/KnowledgeBaseApiTest/DocumentApiTest.cs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,17 @@ public async Task TestCreateDocumentByText_ShouldHaveDocumentInfoInResponse()
9393
var response = await Client.PostCreateDocumentByTextAsync(
9494
Dataset.Id,
9595
new CreateByText.RequestBody(
96-
$"Test Document {uuid}",
97-
"Test Content",
98-
IndexingTechnique.Economy,
99-
DocForm.TextModel,
100-
"",
101-
_defaultProcessRule,
102-
_defaultRetrievalModel,
103-
"",
104-
""
96+
Name: $"Test Document {uuid}",
97+
Text: "Test Content",
98+
DocType: null,
99+
DocMetadata: null,
100+
IndexingTechnique: IndexingTechnique.Economy,
101+
DocForm: DocForm.TextModel,
102+
DocLanguage: "",
103+
ProcessRule: _defaultProcessRule,
104+
RetrievalModel: _defaultRetrievalModel,
105+
EmbeddingModel: "",
106+
EmbeddingModelProvider: ""
105107
));
106108

107109

@@ -156,7 +158,7 @@ public async Task TestDeleteDocument_ShouldNotContainsDocumentInDataset()
156158
foreach (var doc in Documents)
157159
{
158160
var response = await Client.DeleteDocument(Dataset.Id, doc.Id);
159-
Assert.Equal("success", response.Result);
161+
Assert.True(response.IsSuccessStatusCode);
160162
}
161163

162164
var documents = await Client.GetDocuments(Dataset.Id);

DifySharp/Apis/KnowledgeBaseApi.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ int batch
132132
/// <param name="documentId"></param>
133133
/// <returns></returns>
134134
[HttpDelete("/v1/datasets/{datasetId}/documents/{documentId}")]
135-
public Task<Delete.ResponseBody> DeleteDocument(
135+
public Task<HttpResponseMessage> DeleteDocument(
136136
string datasetId,
137137
string documentId
138138
);
@@ -191,9 +191,9 @@ string documentId
191191
/// <param name="datasetId">The unique identifier for the dataset.</param>
192192
/// <param name="documentId">The unique identifier for the document within the dataset.</param>
193193
/// <param name="segmentId">The unique identifier for the segment to be deleted.</param>
194-
/// <returns>A task that represents the asynchronous operation. The task result contains the response body of the delete operation.</returns>
194+
/// <returns>A task that represents the asynchronous operation. The task result contains the HTTP response message.</returns>
195195
[HttpDelete("/v1/datasets/{datasetId}/documents/{documentId}/segments/{segmentId}")]
196-
public Task<Delete.ResponseBody> DeleteSegments(
196+
public Task<HttpResponseMessage> DeleteSegments(
197197
string datasetId,
198198
string documentId,
199199
string segmentId
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
namespace DifySharp.KnowledgeBase.Chunk;
1+
using System.Text.Json.Serialization;
2+
3+
namespace DifySharp.KnowledgeBase.Chunk;
24

35
/// <summary>
46
/// Delete a chunk in document
57
/// </summary>
68
public record Delete
79
{
8-
public record ResponseBody(string Result);
10+
public class ResponseBody
11+
{
12+
[JsonPropertyName("result")]
13+
public string? Result { get; set; } = "success";
14+
}
915
}

DifySharp/DTOs/KnowledgeBase/DocForm.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace DifySharp.KnowledgeBase;
1+
using System.Text.Json.Serialization;
2+
3+
namespace DifySharp.KnowledgeBase;
24

35
/// <summary>
46
/// Format of indexed content
@@ -8,15 +10,18 @@ public enum DocForm
810
/// <summary>
911
/// Text documents are directly embedded; <see cref="IndexingTechnique.Economy"/> mode defaults to using this form
1012
/// </summary>
13+
[JsonPropertyName("text_model")]
1114
TextModel,
1215

1316
/// <summary>
1417
/// Parent-child mode
1518
/// </summary>
19+
[JsonPropertyName("hierarchical_model")]
1620
HierarchicalModel,
1721

1822
/// <summary>
1923
/// Q and A Mode: Generates Q and A pairs for segmented documents and then embeds the questions
2024
/// </summary>
25+
[JsonPropertyName("qa_model")]
2126
QaModel,
2227
}

0 commit comments

Comments
 (0)