有没有办法让这个方法适合重写?
Is there a way to make this method suitable to override?
我已经在基于 Microsoft Bot Framework v4 (c#) 的机器人中实现了转录功能。对于存储类型,我使用了 Azure Table 存储。一切都按预期工作。从那里我希望机器人严格从应用服务中的配置选项卡获取对存储的访问凭据。
但是在我实现这个之后,它说我的方法不再适合重写。
protected override async Task OnMessageActivityAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
// First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);
// Top intent tell us which cognitive service to use.
var topIntent = recognizerResult.GetTopScoringIntent();
// Next, we call the dispatcher with the top intent.
await DispatchToTopIntentAsync(configuration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
}
我在 OnMessageActivityAsync 方法中添加配置参数后出现此错误。但是我需要那里的参数,因为我在 DispatchToTopIntentAsync:
中使用了它
// Suche nach der richtigen KnowledgeBase
private async Task DispatchToTopIntentAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
{
switch (intent)
{
case "q_SEKAI_Allgemein":
await ProcessSEKAI_AllgemeinAsync(configuration, turnContext, cancellationToken);
break;
case "q_SEKAI_HomeOffice":
await ProcessSEKAI_HomeOfficeAsync(configuration, turnContext, cancellationToken);
break;
case "q_SEKAI_MixedReality":
await ProcessSEKAI_MixedRealityAsync(configuration, turnContext, cancellationToken);
break;
default:
// Wird ausgeführt, wenn keine KnowledgeBase gefunden wird
_logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
await TableStorageEintrag(configuration, turnContext, cancellationToken);
break;
}
}
在这部分中,机器人决定哪个知识库最适合进一步的工作。
但是我该如何解决这个问题呢?如果您需要更多信息,请随时询问。然后我会尽快编辑我的 post :)
(此截图参考了此post的回答)
您不能更改基础虚拟 class 的参数并期望覆盖它。
正确的签名如下,给出于MSDN
protected virtual Task OnMessageActivityAsync(
ITurnContext<IMessageActivity> turnContext,
CancellationToken cancellationToken);
能否在 class
的构造函数中注入 IConfigration
private readonly IConfiguration _iConfiguration;
// Inject it here
public ConstructorOfYourClass(IConfiguration iConfiguration) {
_iConfiguration = iConfiguration;
}
protected override async Task OnMessageActivityAsync(
ITurnContext<IMessageActivity> turnContext,
CancellationToken cancellationToken) {
.......
// Use it here
await DispatchToTopIntentAsync(_iConfiguration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
}
我已经在基于 Microsoft Bot Framework v4 (c#) 的机器人中实现了转录功能。对于存储类型,我使用了 Azure Table 存储。一切都按预期工作。从那里我希望机器人严格从应用服务中的配置选项卡获取对存储的访问凭据。
但是在我实现这个之后,它说我的方法不再适合重写。
protected override async Task OnMessageActivityAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
// First, we use the dispatch model to determine which cognitive service (LUIS or QnA) to use.
var recognizerResult = await _botServices.Dispatch.RecognizeAsync(turnContext, cancellationToken);
// Top intent tell us which cognitive service to use.
var topIntent = recognizerResult.GetTopScoringIntent();
// Next, we call the dispatcher with the top intent.
await DispatchToTopIntentAsync(configuration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
}
我在 OnMessageActivityAsync 方法中添加配置参数后出现此错误。但是我需要那里的参数,因为我在 DispatchToTopIntentAsync:
中使用了它// Suche nach der richtigen KnowledgeBase
private async Task DispatchToTopIntentAsync(IConfiguration configuration, ITurnContext<IMessageActivity> turnContext, string intent, RecognizerResult recognizerResult, CancellationToken cancellationToken)
{
switch (intent)
{
case "q_SEKAI_Allgemein":
await ProcessSEKAI_AllgemeinAsync(configuration, turnContext, cancellationToken);
break;
case "q_SEKAI_HomeOffice":
await ProcessSEKAI_HomeOfficeAsync(configuration, turnContext, cancellationToken);
break;
case "q_SEKAI_MixedReality":
await ProcessSEKAI_MixedRealityAsync(configuration, turnContext, cancellationToken);
break;
default:
// Wird ausgeführt, wenn keine KnowledgeBase gefunden wird
_logger.LogInformation($"Dispatch unrecognized intent: {intent}.");
await TableStorageEintrag(configuration, turnContext, cancellationToken);
break;
}
}
在这部分中,机器人决定哪个知识库最适合进一步的工作。
但是我该如何解决这个问题呢?如果您需要更多信息,请随时询问。然后我会尽快编辑我的 post :)
(此截图参考了此post的回答)
您不能更改基础虚拟 class 的参数并期望覆盖它。 正确的签名如下,给出于MSDN
protected virtual Task OnMessageActivityAsync(
ITurnContext<IMessageActivity> turnContext,
CancellationToken cancellationToken);
能否在 class
的构造函数中注入 IConfigrationprivate readonly IConfiguration _iConfiguration;
// Inject it here
public ConstructorOfYourClass(IConfiguration iConfiguration) {
_iConfiguration = iConfiguration;
}
protected override async Task OnMessageActivityAsync(
ITurnContext<IMessageActivity> turnContext,
CancellationToken cancellationToken) {
.......
// Use it here
await DispatchToTopIntentAsync(_iConfiguration, turnContext, topIntent.intent, recognizerResult, cancellationToken);
}