-
Notifications
You must be signed in to change notification settings - Fork 0
/
BotServices.cs
55 lines (50 loc) · 2.21 KB
/
BotServices.cs
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.Bot.Builder.AI.QnA;
using Microsoft.Bot.Builder.AI.QnA.Models;
using Microsoft.Extensions.Configuration;
using System;
namespace Microsoft.BotBuilderSamples
{
public class BotServices : IBotServices
{
public BotServices(IConfiguration configuration)
{
InitializeService(configuration);
}
public IQnAMakerClient QnAMakerService { get; private set; }
private void InitializeService(IConfiguration configuration)
{
var QnAEndpointHostName = configuration["QnAEndpointHostName"];
var QnAEndpointKey = configuration["QnAEndpointKey"];
var QnAKnowledgebaseId = configuration["QnAKnowledgebaseId"];
var ProjectName = configuration["ProjectName"];
var LanguageEndpointKey = configuration["LanguageEndpointKey"];
var LanguageEndpointHostName = configuration["LanguageEndpointHostName"];
if (!String.IsNullOrEmpty(LanguageEndpointHostName) && !String.IsNullOrEmpty(LanguageEndpointKey) && !String.IsNullOrEmpty(ProjectName))
{
QnAMakerService = new CustomQuestionAnswering(new QnAMakerEndpoint
{
KnowledgeBaseId = ProjectName,
Host = LanguageEndpointHostName,
EndpointKey = LanguageEndpointKey,
QnAServiceType = ServiceType.Language
});
}
else if (!String.IsNullOrEmpty(QnAEndpointHostName) && !String.IsNullOrEmpty(QnAEndpointKey) && !String.IsNullOrEmpty(QnAKnowledgebaseId))
{
QnAMakerService = new QnAMaker(new QnAMakerEndpoint
{
KnowledgeBaseId = QnAKnowledgebaseId,
Host = QnAEndpointHostName,
EndpointKey = QnAEndpointKey,
QnAServiceType = ServiceType.QnAMaker
});
}
else
{
throw new ArgumentException("Please fill in the configuration parameters.");
}
}
}
}