From ffa86b9a430fe6c681b5474900836b2f608dbebb Mon Sep 17 00:00:00 2001 From: cdxker Date: Thu, 9 Jan 2025 22:02:43 -0800 Subject: [PATCH] feature: add more context to suggested questions --- .../src/utils/hooks/useFollowupQuestions.ts | 8 ++++++-- clients/search-component/src/utils/trieve.ts | 3 ++- server/src/handlers/message_handler.rs | 6 ------ server/src/public/product.html | 4 ++-- server/static/output.css | 4 ---- 5 files changed, 10 insertions(+), 15 deletions(-) diff --git a/clients/search-component/src/utils/hooks/useFollowupQuestions.ts b/clients/search-component/src/utils/hooks/useFollowupQuestions.ts index 2488104e0..4dd01faaa 100644 --- a/clients/search-component/src/utils/hooks/useFollowupQuestions.ts +++ b/clients/search-component/src/utils/hooks/useFollowupQuestions.ts @@ -6,7 +6,7 @@ import { useChatState } from "./chat-context"; export const useFollowupQuestions = () => { const { trieveSDK, currentGroup, props } = useModalState(); - const { currentQuestion } = useChatState(); + const { messages } = useChatState(); const [isLoading, setIsLoading] = useState(false); const [suggestedQuestions, setSuggestedQuestions] = useState< SuggestedQueriesResponse["queries"] @@ -14,9 +14,13 @@ export const useFollowupQuestions = () => { const getQuestions = async () => { setIsLoading(true); + const prevMessage = messages.filter((msg) => { + return msg.type == "user" + }).slice(-1)[0]; + const queries = await getSuggestedQuestions({ trieve: trieveSDK, - query: currentQuestion, + query: prevMessage.text, count: props.numberOfSuggestions ?? 3, group: currentGroup }); diff --git a/clients/search-component/src/utils/trieve.ts b/clients/search-component/src/utils/trieve.ts index 8316cd168..7d41c141c 100644 --- a/clients/search-component/src/utils/trieve.ts +++ b/clients/search-component/src/utils/trieve.ts @@ -294,8 +294,9 @@ export const getSuggestedQuestions = async ({ { ...(query && { query }), suggestion_type: "question", - search_type: "semantic", + search_type: "hybrid", suggestions_to_create: count, + context: `.The users previous query was "${query}", all responses should look like that.`, ...(group && group?.tracking_id && { filters: { diff --git a/server/src/handlers/message_handler.rs b/server/src/handlers/message_handler.rs index 9d37a403b..d6e04ef4f 100644 --- a/server/src/handlers/message_handler.rs +++ b/server/src/handlers/message_handler.rs @@ -930,12 +930,6 @@ pub async fn get_suggested_queries( }; let context_sentence = match data.context.clone() { Some(context) => { - if context.split_whitespace().count() > 15 || context.len() > 200 { - return Err(ServiceError::BadRequest( - "Context must be under 15 words and 200 characters".to_string(), - )); - } - format!( "\n\nSuggest things with the following context in mind: {}.\n\n", context diff --git a/server/src/public/product.html b/server/src/public/product.html index 135a964e9..b769a6e05 100644 --- a/server/src/public/product.html +++ b/server/src/public/product.html @@ -88,7 +88,7 @@

> {% for i in range(5) %}
-
+
@@ -120,7 +120,7 @@

newDiv.classList.add("w-64", "flex-shrink-0", "mt-auto"); newDiv.setAttribute("x-key", i); newDiv.innerHTML = ` -
+
diff --git a/server/static/output.css b/server/static/output.css index a07e94de1..e4ace83c1 100644 --- a/server/static/output.css +++ b/server/static/output.css @@ -655,10 +655,6 @@ video { height: 1.5rem; } -.h-72 { - height: 18rem; -} - .h-full { height: 100%; }