Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove almost all dialogue templates #879

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 2 additions & 143 deletions lib/templates/dialogue.genie
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,16 @@ import './commands.genie';
// common dialogue elements
import './dlg/shared.genie';
import './dlg/results.genie';
import './dlg/coref-actions.genie';

// specific interactions
// keep this in alphabetical order
import './dlg/action-confirm.genie';
import './dlg/action-results.genie';
import './dlg/aggregation-results.genie';
import './dlg/coref-questions.genie';
import './dlg/empty-search.genie';
import './dlg/initial-request.genie';
import './dlg/list-proposal.genie';
import './dlg/recommendation.genie';
import './dlg/refinement.genie';
import './dlg/related-questions.genie';
import './dlg/search-questions.genie';
import './dlg/slot-fill.genie';
import './dlg/streams.genie';

Expand Down Expand Up @@ -193,21 +188,11 @@ $agent : S.AgentReplyRecord = {
| ctx:ctx_reinit ('how can i help you' | 'what are you interested in' | 'what can i do for you') '?'
) => S.makeAgentReply(ctx, S.makeSimpleState(ctx, 'sys_greet', null), null, null),

?anything_else {
ctx:ctx_cancel anything_else_phrase
=> S.makeAgentReply(ctx, S.makeSimpleState(ctx, 'sys_anything_else', null), null, null, { end: false }),

ctx:ctx_end 'alright ,' ('bye !' | 'good bye !')
=> S.makeAgentReply(ctx, S.makeSimpleState(ctx, 'sys_end', null)),
}
!anything_else {
ctx:ctx_cancel 'alright, let me know if I can help you with anything else!'
=> S.makeAgentReply(ctx, S.makeSimpleState(ctx, 'sys_end', null)),
}
ctx:ctx_cancel 'alright, let me know if I can help you with anything else!'
=> S.makeAgentReply(ctx, S.makeSimpleState(ctx, 'sys_end', null)),

// action results
action_success_phrase;
?anything_else action:action_success_phrase anything_else_phrase => S.setEndBit(action, false);
ctx:ctx_completed_action_error sorry_preamble phrase:action_error_phrase => phrase;

// query results
Expand All @@ -228,11 +213,6 @@ $agent : S.AgentReplyRecord = {
ctx:ctx_empty_search_command error:empty_search_error
=> D.makeEmptySearchError(ctx, error);

// query refinement (through proposal or search question)
?multiwoz prop:system_generic_proposal => prop;
!inference ctx:ctx_search_command questions:search_question
=> D.makeSearchQuestion(ctx, questions);

// slot filling of actions
ctx:ctx_incomplete_action_after_search questions:slot_fill_question
=> D.makeSlotFillQuestion(ctx, questions);
Expand Down Expand Up @@ -297,15 +277,11 @@ $user : Ast.DialogueState = {
=> D.actionConfirmAcceptPhrase(ctx);
ctx:ctx_sys_confirm_action reject_phrase [weight=0.1]
=> D.actionConfirmRejectPhrase(ctx);
ctx:ctx_sys_confirm_action reject_phrase ('can you try' | 'how about') answer:imprecise_slot_fill_answer_phrase ('instead ?' | '') [weight=0.1]
=> D.actionConfirmChangeParam(ctx, answer);

// action and non-list query results
( ctx:ctx_sys_action_success thanks_phrase ('goodbye !' | '')
| ctx:ctx_sys_display_result thanks_phrase ('goodbye !' | '')
) => S.makeSimpleState(ctx, 'cancel', null);
ctx:ctx_sys_action_success questions:simple_user_search_question
=> D.actionSuccessQuestion(ctx, questions);

( ctx:ctx_sys_display_result repeat_command_phrase
| ctx:ctx_sys_action_error repeat_command_on_error_phrase
Expand All @@ -332,124 +308,7 @@ $user : Ast.DialogueState = {
| ctx:ctx_sys_action_error nevermind_phrase
) => S.makeSimpleState(ctx, 'cancel', null);

/*
FIXME this template is too slow, so it is temporarily commented out
ctx:ctx_sys_action_error ('i see ,' | 'okay' | 'okay ,' | 'yeah' | 'yeah ,') ('can you try' | 'how about') answer:imprecise_slot_fill_answer_phrase '?'
=> D.actionErrorChangeParam(ctx, answer);
*/

// empty search errors
ctx:ctx_sys_empty_search req:precise_empty_search_change_request with { functionName = ctx.currentTableFunction }
=> D.preciseEmptySearchChangeRequest(ctx, req);
ctx:ctx_sys_empty_search req:imprecise_empty_search_change_request
=> D.impreciseEmptySearchChangeRequest(ctx, req);
ctx:ctx_sys_empty_search accept_phrase
=> D.acceptEmptySearchOffer(ctx);

// search questions
ctx:ctx_sys_search_question answer:precise_search_question_answer with { functionName = ctx.currentFunction }
=> D.preciseSearchQuestionAnswer(ctx, answer);
ctx:ctx_sys_search_question answer:imprecise_search_question_answer [weight=0.2]
=> D.impreciseSearchQuestionAnswer(ctx, answer);

// slot fill questions
ctx:ctx_sys_slot_fill answer:precise_slot_fill_answer with { functionName = ctx.nextFunction }
=> D.preciseSlotFillAnswer(ctx, answer);
ctx:ctx_sys_slot_fill answer:imprecise_slot_fill_answer
=> D.impreciseSlotFillAnswer(ctx, answer);

// asking for a recommendation
?multiwoz {
ctx:ctx_sys_recommend_many ask_recommend_phrase
=> S.makeSimpleState(ctx, 'ask_recommend', null);
ctx:ctx_sys_search_question ask_recommend_phrase
=> S.makeSimpleState(ctx, 'ask_recommend', null);
}

// refinement from a query proposal
ctx:ctx_sys_propose_refined_query accept_phrase [weight=0.5]
=> D.positiveProposalReply(ctx); // ctx.aux contains the proposal from the agent
ctx:ctx_sys_propose_refined_query reply:negative_proposal_reply with { functionName = ctx.currentFunction } [weight=0.5]
=> D.negativeProposalReply(ctx, reply);

// accepting recommendations
ctx:ctx_sys_recommend_one accept_phrase [weight=0.7]
=> D.positiveRecommendationReply($loader, ctx, null, null);
ctx:ctx_sys_recommend_one acceptedAction:recommendation_accept_phrase_with_action [weight=0.7]
=> D.positiveRecommendationReply($loader, ctx, acceptedAction, null);
?multiwoz ctx:ctx_sys_recommend_one name:recommendation_accept_phrase_by_name [weight=0.7]
=> D.positiveRecommendationReply($loader, ctx, name[1], name[0]);

// accepting recommendation to learn more
( ctx:ctx_sys_recommend_one tell_me_more_phrase [weight=0.5]
| ctx:ctx_sys_recommend_one accept_phrase tell_me_more_phrase [weight=0.5]
) => D.recommendationLearnMoreReply(ctx, null);
ctx:ctx_sys_recommend_one name:list_proposal_tell_me_more
=> D.recommendationLearnMoreReply(ctx, name);

// refinement from a recommendation
ctx:ctx_sys_recommend_one reply:negative_proposal_reply with { functionName = ctx.currentFunction } [weight=0.6]
=> D.negativeRecommendationReply(ctx, reply);

// cancelling the transaction from a recommendation
// "thanks" without "yes" or "no" is always good
ctx:ctx_sys_recommend_one thanks_phrase ('goodbye !' | '')
=> D.recommendationCancelReply(ctx, true);
// "ok thanks" is good if there was no question
ctx:ctx_sys_recommend_one ok_thanks_phrase ('goodbye !' | '')
=> D.recommendationCancelReply(ctx, !ctx.aux.action && !ctx.aux.hasLearnMore);
// "no thanks" is good if there was a question
ctx:ctx_sys_recommend_one no_thanks_phrase ('goodbye !' | '')
=> D.recommendationCancelReply(ctx, ctx.aux.action || ctx.aux.hasLearnMore);

// continuing with a question
// a "related question" is one that uses a different Thingpedia primitive (connected
// by the #[related_question] annotation)
ctx:ctx_sys_recommend_one question:related_question => question;
// a "user search question" is one that uses the same Thingpedia primitive, and adds
// a filter on ID
ctx:ctx_sys_recommend_one questions:user_search_question with { functionName = ctx.currentFunction }
=> D.recommendationSearchQuestionReply(ctx, questions);
ctx:ctx_sys_learn_more_what questions:user_search_question with { functionName = ctx.currentFunction }
=> D.learnMoreSearchQuestionReply(ctx, questions);
ctx:ctx_sys_display_result questions:user_search_question with { functionName = ctx.currentFunction }
=> D.displayResultSearchQuestionReply(ctx, questions);

// accepting list proposals
ctx:ctx_sys_recommend_many reply:positive_list_proposal_reply [weight=10 * 0.7]
=> D.positiveListProposalReply($loader, ctx, reply);
?multiwoz ctx:ctx_sys_recommend_many action:list_proposal_accept_phrase_with_action_by_name [weight=10 * 0.7]
=> D.positiveListProposalReplyActionByName($loader, ctx, action);

// accepting list proposal to learn more
ctx:ctx_sys_recommend_many name:list_proposal_tell_me_more
=> D.listProposalLearnMoreReply(ctx, name);

// refinement from a list proposal
ctx:ctx_sys_recommend_many reply:negative_proposal_reply with { functionName = ctx.currentFunction } [weight=0.6]
=> D.negativeListProposalReply(ctx, reply);

// continuing with a question
ctx:ctx_sys_recommend_many question:related_question => question;
ctx:ctx_sys_recommend_many questions:user_search_question_for_list with { functionName = ctx.currentFunction }
=> D.listProposalSearchQuestionReply(ctx, questions);

// streams
!nostream {
ctx:ctx_sys_action_success stream:add_separate_stream
=> D.addStream(ctx, stream);
ctx:ctx_sys_recommend_one stream:add_separate_stream_to_query
=> D.addStream(ctx, stream);
ctx:ctx_sys_recommend_many stream:add_separate_stream_to_query
=> D.addStream(ctx, stream);
ctx:ctx_sys_display_result stream:add_separate_stream_to_query
=> D.addStream(ctx, stream);

ctx:ctx_sys_recommend_one with { is_monitorable = true } make_monitor_phrase
=> D.makeMonitor(ctx, { monitorItemID : false });
ctx:ctx_sys_recommend_many with { is_monitorable = true } make_monitor_phrase
=> D.makeMonitor(ctx, { monitorItemID : false });
ctx:ctx_sys_display_result with { is_monitorable = true } make_monitor_phrase
=> D.makeMonitor(ctx, { monitorItemID : false });
}
}
27 changes: 1 addition & 26 deletions lib/templates/dialogue_acts/action-confirm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@

import assert from 'assert';

import { Ast, Type } from 'thingtalk';

import * as C from '../ast_manip';
import { Type } from 'thingtalk';

import {
ContextInfo,
makeAgentReply,
makeSimpleState,
setOrAddInvocationParam,
addNewItem,
} from '../state_manip';


Expand All @@ -53,29 +49,8 @@ function actionConfirmRejectPhrase(ctx : ContextInfo) {
return makeSimpleState(clone, 'cancel', null);
}

function actionConfirmChangeParam(ctx : ContextInfo, answer : Ast.Value|C.InputParamSlot) {
if (!ctx.next)
return null;

if (answer instanceof Ast.Value)
return null;

// don't accept in params that don't apply to this specific action
const arg = ctx.nextFunction!.getArgument(answer.ast.name);
if (!arg || !arg.is_input || !arg.type.equals(answer.ast.value.getType()))
return null;

const clone = ctx.next.clone();
const action = C.getInvocation(clone);
if (!action || !(action instanceof Ast.Invocation)) return null;

setOrAddInvocationParam(action, answer.ast.name, answer.ast.value);
return addNewItem(ctx, 'execute', null, 'confirmed', clone);
}

export {
makeActionConfirmationPhrase,
actionConfirmAcceptPhrase,
actionConfirmRejectPhrase,
actionConfirmChangeParam
};
78 changes: 0 additions & 78 deletions lib/templates/dialogue_acts/action-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ import {
ContextInfo,
makeAgentReply,
makeSimpleState,
setOrAddInvocationParam,
addNewItem,
} from '../state_manip';
import {
isInfoPhraseCompatibleWithResult
Expand Down Expand Up @@ -192,32 +190,6 @@ function checkThingpediaErrorMessage(ctx : ContextInfo, msg : ErrorMessage) {
return ctx;
}

function checkActionErrorMessage(ctx : ContextInfo, action : Ast.Invocation) {
// check the action is the same we actually executed, and all the parameters we're mentioning
// match the actual parameters of the action
if (!C.isSameFunction(ctx.currentFunction!, action.schema!))
return null;
const ctxInvocation = C.getInvocation(ctx.current!);
for (const newParam of action.in_params) {
if (newParam.value.isUndefined)
continue;

let found = false;
for (const oldParam of ctxInvocation.in_params) {
if (newParam.name === oldParam.name) {
if (!newParam.value.equals(oldParam.value))
return null;
found = true;
break;
}
}
if (!found)
return null;
}

return ctx;
}

function makeActionErrorPhrase(ctx : ContextInfo, questions : C.ParamSlot[]) {
const schema = ctx.currentFunction!;
for (const q of questions) {
Expand All @@ -239,60 +211,10 @@ function makeActionErrorPhrase(ctx : ContextInfo, questions : C.ParamSlot[]) {
return makeAgentReply(ctx, makeSimpleState(ctx, 'sys_action_error_question', questions.map((q) => q.name)));
}

function actionErrorChangeParam(ctx : ContextInfo, answer : Ast.Value|C.InputParamSlot) {
const schema = ctx.currentFunction!;
const questions = ctx.state.dialogueActParam as string[] || [];
let ipslot : C.InputParamSlot;
if (answer instanceof Ast.Value) {
if (questions.length !== 1)
return null;
const arg = schema.getArgument(questions[0]);
if (!arg || !arg.is_input || !arg.type.equals(answer.getType()))
return null;
ipslot = {
schema,
ptype: answer.getType(),
ast: new Ast.InputParam(null, questions[0], answer)
};
} else {
ipslot = answer;
if (!C.isSameFunction(ipslot.schema, schema))
return null;
}
// TODO implement this template for queries
if (schema.functionType !== 'action')
return null;

const clone = ctx.current!.clone();
const action = C.getInvocation(clone);
if (!action || !(action instanceof Ast.Invocation))
return null;
setOrAddInvocationParam(action, ipslot.ast.name, ipslot.ast.value);
return addNewItem(ctx, 'execute', null, 'accepted', clone);
}

function actionSuccessQuestion(ctx : ContextInfo, questions : C.ParamSlot[]) {
if (ctx.resultInfo && ctx.resultInfo.hasStream)
return null;

for (const q of questions) {
if (!C.isSameFunction(q.schema, ctx.currentFunction!))
return null;
const arg = ctx.currentFunction!.getArgument(q.name);
if (!arg || arg.is_input)
return null;
}
return makeSimpleState(ctx, 'action_question', questions.map((q) => q.name));
}

export {
makeThingpediaActionSuccessPhrase,
makeCompleteActionSuccessPhrase,
makeGenericActionSuccessPhrase,
checkThingpediaErrorMessage,
checkActionErrorMessage,
makeActionErrorPhrase,

actionErrorChangeParam,
actionSuccessQuestion
};
Loading