-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
99 lines (87 loc) · 2.67 KB
/
Program.cs
File metadata and controls
99 lines (87 loc) · 2.67 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
using DifySharp;
using DifySharp.Chat.ChatMessages;
using DifySharp.Extensions;
using DifySharp.KnowledgeBase;
using DifySharp.KnowledgeBase.Document;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDifySharp(o =>
{
o.Secrets =
[
new DifyApiSecret("<your-knowledge-base-secret>", "knowledge", DifyApiType.KNOWLEDGE_BASE),
new DifyApiSecret("<your-chat-application-secret>", "chat", DifyApiType.CHAT)
];
}); // add you api key here
var app = builder.Build();
app.MapGet("/", async (IServiceProvider sp) =>
{
var api = sp.GetRequiredKeyedService<KnowledgeBaseClient>("knowledge"); // get client instance by name in configuration
var uuid = Guid.NewGuid().ToString("N")[..6];
var response = await api.PostCreateDocumentByTextAsync("", // add a dataset id here
new CreateByText.RequestBody(
$"Test Document {uuid}",
"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
),
"",
""
));
var document = response.Document;
return new
{
document
};
});
app.MapGet("/ChatApiDemo/ChatMessagesBlocking", async (IServiceProvider sp) =>
{
// get chat client instance by name in configuration
var client = sp.GetRequiredKeyedService<ChatClient>("chat");
// send chat message in blocking mode
var response = await client.PostChatMessageBlocking(new ChatMessage.RequestBody
{
Query = "ping",
User = "test-user"
});
return new
{
response.Answer,
};
});
app.Run();