@@ -26,27 +26,14 @@ const actionDefinition: ActionDefinition = {
2626 } ,
2727 outputParameters : [
2828 {
29- key : 'searchStatus' ,
30- title : 'Search Status' ,
31- description :
32- 'Status of the search. If the search was successful, the status will be "found". If the search was unsuccessful, the status will be "not_found".' ,
29+ key : 'textResponse' ,
30+ title : 'Text response' ,
31+ description : 'The text response of the search result.' ,
3332 type : 'string' ,
3433 validation : {
3534 required : true ,
3635 } ,
3736 } ,
38- {
39- key : 'faqQuestion' ,
40- title : 'FAQ Question' ,
41- description : 'Question from the FAQ list.' ,
42- type : 'string' ,
43- } ,
44- {
45- key : 'faqAnswer' ,
46- title : 'FAQ Answer' ,
47- description : 'Answer from the FAQ list.' ,
48- type : 'string' ,
49- } ,
5037 ] ,
5138} ;
5239export default actionDefinition ;
@@ -77,29 +64,53 @@ export async function handler({ input, configuration }: ActionContext): Promise<
7764 ] ) ;
7865
7966 // Convert the chat result to the output parameters
80- const result : any = {
81- searchStatus : 'not_found' ,
82- faqQuestion : undefined ,
83- faqAnswer : undefined ,
84- } ;
67+ let textResponse : string ;
8568 const functionCall = chatResult . additional_kwargs ?. function_call ;
8669 if ( functionCall ) {
8770 const faq = faqList [ getIndexFromFunctionName ( functionCall . name ) ] ;
88- result . searchStatus = 'found' ;
89- result . faqQuestion = faq . question ;
90- result . faqAnswer = faq . answer ;
71+
72+ textResponse =
73+ 'Here is an FAQ that is most relevant to your question prompt:\n\n' +
74+ `*Question*: ${ faq . question } \n` +
75+ `*Answer*: ${ faq . answer } \n\n` +
76+ `If this is not the FAQ you are looking for, please report the missing FAQ to the manager.` ;
77+
78+ await logRequest (
79+ configuration . jsonKey ,
80+ configuration . faqLogSheetId ,
81+ configuration . questionPrompt ,
82+ 'found' ,
83+ faq . question ,
84+ faq . answer ,
85+ ) ;
86+ } else {
87+ textResponse =
88+ 'Sorry, I could not find any relevant FAQs on the list.\n\nPlease report the missing FAQ to the manager.' ;
89+
90+ await logRequest ( configuration . jsonKey , configuration . faqLogSheetId , input . questionPrompt , 'not_found' ) ;
9191 }
9292
93- // Log the search to a separate Google Sheet
94- const logSheet = await authorizeAndGetSheet ( configuration . jsonKey , configuration . faqLogSheetId ) ;
93+ // Return the output parameters
94+ return {
95+ textResponse,
96+ } ;
97+ }
98+
99+ // Log the search to a separate Google Sheet
100+ async function logRequest (
101+ jsonKey : string ,
102+ faqLogSheetId : string ,
103+ questionPrompt : string ,
104+ searchStatus : string ,
105+ faqQuestion : string = '' ,
106+ faqAnswer : string = '' ,
107+ ) {
108+ const logSheet = await authorizeAndGetSheet ( jsonKey , faqLogSheetId ) ;
95109 await logSheet . addRow ( {
96- 'Question Prompt' : input . questionPrompt ,
97- 'Search Status' : result . searchStatus ,
98- 'FAQ Question' : result . faqQuestion ,
99- 'FAQ Answer' : result . faqAnswer ,
110+ 'Question Prompt' : questionPrompt ,
111+ 'Search Status' : searchStatus ,
112+ 'FAQ Question' : faqQuestion ,
113+ 'FAQ Answer' : faqAnswer ,
100114 'Search Timestamp' : new Date ( ) . toISOString ( ) ,
101115 } ) ;
102-
103- // Return the output parameters
104- return result ;
105116}
0 commit comments