-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChunkApiTest.cs
More file actions
124 lines (107 loc) · 2.75 KB
/
ChunkApiTest.cs
File metadata and controls
124 lines (107 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using DifySharp.Apis;
using DifySharp.KnowledgeBase;
using DifySharp.KnowledgeBase.Chunk;
using DifySharp.KnowledgeBase.Dataset;
using DifySharp.KnowledgeBase.Document;
using JetBrains.Annotations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DatasetCreate = DifySharp.KnowledgeBase.Dataset.Create;
// using Create = DifySharp.KnowledgeBase.Chunk.Create;
namespace DifySharp.Test.Apis.KnowledgeBaseApiTest;
public class ChunkApiTestFixture : KnowledgeBaseApiTestFixture
{
public Dataset Dataset { get; private set; }
public Document Document { get; set; }
public KnowledgeBaseClient Client { get; set; }
public ChunkApiTestFixture()
{
Client = ServiceProvider.GetRequiredKeyedService<KnowledgeBaseClient>("knowledge");
// create a dataset
var uuid = Guid.NewGuid().ToString("N")[..6];
Dataset =
Client.PostCreateDatasetAsync(new DatasetCreate.RequestBody(Name: $"Chunk Api Test Dataset {uuid}"))
.GetAwaiter()
.GetResult();
Assert.NotNull(Dataset);
// crate a document
var createDocRequestBody = new CreateByText.RequestBody(
$"Chunk Api Test Document {uuid}",
"Test Content \n\n Test Content \n\n Test Content",
IndexingTechnique.Economy,
DocForm.TextModel,
"",
new ProcessRule(
"automatic",
new Rules(
[
new PreProcessingRule(
"remove_extra_spaces",
true
),
new PreProcessingRule(
"remove_urls_emails",
true
)
],
new Segmentation(
"\n\n",
1000
),
"paragraph",
new SubChunkSegmentation(
"\n\n",
1000,
200
)
)
),
new CreateByText.RetrievalModel(
CreateByText.SearchMethod.HybridSearch,
false,
new CreateByText.RerankingModel(
"",
""
),
4,
false,
0.9f
),
"",
""
);
Document = Client.PostCreateDocumentByTextAsync(
Dataset.Id,
createDocRequestBody
)
.GetAwaiter()
.GetResult().Document;
Assert.NotNull(Document);
}
public override void Dispose()
{
Client.DeleteDataset(Dataset.Id).GetAwaiter().GetResult();
Client.Dispose();
base.Dispose();
}
}
[TestSubject(typeof(IChunkApi))]
public class ChunkApiTest(
ChunkApiTestFixture fixture,
ILogger<DocumentApiTest> logger
) : IClassFixture<ChunkApiTestFixture>
{
public Dataset Dataset => fixture.Dataset;
public Document Document => fixture.Document;
public IKnowledgeBaseApi Client => fixture.Client;
[Fact]
public async Task TestGetChunk()
{
Assert.NotNull(Dataset);
Assert.NotNull(Document);
Assert.NotNull(Client);
// var response = await Client.GetSegments(Dataset.Id, Document.Id);
//
// Assert.NotNull(response);
}
}