From 8aba855e547a306b94b4c3bed2b8c9acd4f67f67 Mon Sep 17 00:00:00 2001 From: ashjnaik Date: Fri, 29 Mar 2024 10:46:29 -0700 Subject: [PATCH 1/3] Passing sessionAttributes - To make it into the plugins --- lambda/es-proxy-layer/lib/llm.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lambda/es-proxy-layer/lib/llm.js b/lambda/es-proxy-layer/lib/llm.js index 05bdf287..dd5eaf37 100644 --- a/lambda/es-proxy-layer/lib/llm.js +++ b/lambda/es-proxy-layer/lib/llm.js @@ -192,12 +192,14 @@ async function get_qa_sagemaker(req, promptTemplateStr, context) { } // Invoke LLM via custom Lambda abstraction -async function invoke_lambda(prompt, model_params, settings) { +async function invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes) { const lambda = new Lambda(customSdkConfig('C006', { region })); const body = JSON.stringify({ prompt, parameters: model_params, settings, + sessionId, + sessionAttributes, }); qnabot.log(`Invoking Lambda: ${process.env.LLM_LAMBDA_ARN}`); @@ -231,7 +233,11 @@ async function generate_query_lambda(req, promptTemplateStr) { const settings = req._settings; const [, , , prompt] = await make_qenerate_query_prompt(req, promptTemplateStr); qnabot.log(`Prompt: \nGENERATE QUERY PROMPT==>\n${prompt}\n<==PROMPT`); - return invoke_lambda(prompt, model_params, settings); + + // Extract sessionId and sessionAttributes from the request + const sessionId = req._event.sessionId; + const sessionAttributes = req._event.sessionState.sessionAttributes; + return invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes); } async function get_qa_lambda(req, promptTemplateStr, context) { const model_params = JSON.parse(req._settings.LLM_QA_MODEL_PARAMS || default_params_stg); @@ -241,6 +247,10 @@ async function get_qa_lambda(req, promptTemplateStr, context) { const query = get_query(req); const [, , , prompt] = await make_qa_prompt(req, promptTemplateStr, context, input, query); qnabot.log(`QUESTION ANSWERING PROMPT: \nPROMPT==>\n${prompt}\n<==PROMPT`); + + // Extract sessionId and sessionAttributes from the request + const sessionId = req._event.sessionId; + const sessionAttributes = req._event.sessionState.sessionAttributes; return invoke_lambda(prompt, model_params, settings); } From f6a59af8f69fbaf3839176f232209013f5c1c71c Mon Sep 17 00:00:00 2001 From: ashjnaik Date: Fri, 29 Mar 2024 10:50:24 -0700 Subject: [PATCH 2/3] Changed the invoke_lambda parameter --- lambda/es-proxy-layer/lib/llm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lambda/es-proxy-layer/lib/llm.js b/lambda/es-proxy-layer/lib/llm.js index dd5eaf37..ef7e6f35 100644 --- a/lambda/es-proxy-layer/lib/llm.js +++ b/lambda/es-proxy-layer/lib/llm.js @@ -251,7 +251,7 @@ async function get_qa_lambda(req, promptTemplateStr, context) { // Extract sessionId and sessionAttributes from the request const sessionId = req._event.sessionId; const sessionAttributes = req._event.sessionState.sessionAttributes; - return invoke_lambda(prompt, model_params, settings); + return invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes); } function clean_standalone_query(query) { From e282a4d2ee9a7f3a9f634e503aed00488d99359f Mon Sep 17 00:00:00 2001 From: ashjnaik Date: Tue, 2 Apr 2024 14:25:41 -0700 Subject: [PATCH 3/3] Add sessionState instead of just sessionAttributes --- lambda/es-proxy-layer/lib/llm.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lambda/es-proxy-layer/lib/llm.js b/lambda/es-proxy-layer/lib/llm.js index ef7e6f35..8e16b053 100644 --- a/lambda/es-proxy-layer/lib/llm.js +++ b/lambda/es-proxy-layer/lib/llm.js @@ -192,14 +192,14 @@ async function get_qa_sagemaker(req, promptTemplateStr, context) { } // Invoke LLM via custom Lambda abstraction -async function invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes) { +async function invoke_lambda(prompt, model_params, settings, sessionId, sessionState) { const lambda = new Lambda(customSdkConfig('C006', { region })); const body = JSON.stringify({ prompt, parameters: model_params, settings, sessionId, - sessionAttributes, + sessionState, }); qnabot.log(`Invoking Lambda: ${process.env.LLM_LAMBDA_ARN}`); @@ -234,10 +234,10 @@ async function generate_query_lambda(req, promptTemplateStr) { const [, , , prompt] = await make_qenerate_query_prompt(req, promptTemplateStr); qnabot.log(`Prompt: \nGENERATE QUERY PROMPT==>\n${prompt}\n<==PROMPT`); - // Extract sessionId and sessionAttributes from the request + // Extract sessionId and sessionState from the request const sessionId = req._event.sessionId; - const sessionAttributes = req._event.sessionState.sessionAttributes; - return invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes); + const sessionState = req._event.sessionState; + return invoke_lambda(prompt, model_params, settings, sessionId, sessionState); } async function get_qa_lambda(req, promptTemplateStr, context) { const model_params = JSON.parse(req._settings.LLM_QA_MODEL_PARAMS || default_params_stg); @@ -248,10 +248,10 @@ async function get_qa_lambda(req, promptTemplateStr, context) { const [, , , prompt] = await make_qa_prompt(req, promptTemplateStr, context, input, query); qnabot.log(`QUESTION ANSWERING PROMPT: \nPROMPT==>\n${prompt}\n<==PROMPT`); - // Extract sessionId and sessionAttributes from the request + // Extract sessionId and sessionState from the request const sessionId = req._event.sessionId; - const sessionAttributes = req._event.sessionState.sessionAttributes; - return invoke_lambda(prompt, model_params, settings, sessionId, sessionAttributes); + const sessionState = req._event.sessionState; + return invoke_lambda(prompt, model_params, settings, sessionId, sessionState); } function clean_standalone_query(query) {