Skip to content

Commit

Permalink
feature: add parameters to chat with single product
Browse files Browse the repository at this point in the history
  • Loading branch information
cdxker committed Jan 10, 2025
1 parent bdb54e7 commit 5ab7556
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
22 changes: 21 additions & 1 deletion clients/search-component/src/utils/hooks/chat-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {

const clearConversation = () => {
setCurrentTopic("");
setCurrentGroup(null);
setMessages([]);
};

Expand Down Expand Up @@ -201,7 +202,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
llm_options: {
completion_first: false,
},
page_size: props.searchOptions?.page_size ?? 5,
page_size: props.searchOptions?.page_size ?? 8,
score_threshold: props.searchOptions?.score_threshold || null,
use_group_search: props.useGroupSearch,
filters:
Expand Down Expand Up @@ -258,6 +259,25 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
const askQuestion = async (question?: string, group?: ChunkGroup) => {
setIsDoneReading(false);

if (props.groupTrackingId) {

const fetchedGroup = await trieveSDK.getGroupByTrackingId({
trackingId: props.groupTrackingId
});
if (fetchedGroup) {
group = {
created_at: fetchedGroup.created_at,
updated_at: fetchedGroup.updated_at,
dataset_id: fetchedGroup.dataset_id,
description: fetchedGroup.description,
id: fetchedGroup.id,
metadata: fetchedGroup.metadata,
name: props.cleanGroupName ? props.cleanGroupName : fetchedGroup.name,
tag_set: fetchedGroup.tag_set,
} as ChunkGroup;
}
}

if (!currentGroup && group) {
chatWithGroup(group);
setCurrentGroup(group);
Expand Down
6 changes: 5 additions & 1 deletion clients/search-component/src/utils/hooks/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ export type ModalProps = {
showFloatingInput?: boolean;
inlineHeader?: string;
suggestedQueriesContext: string;
groupTrackingId?: string;
cleanGroupName?: string;
};

const defaultProps = {
Expand Down Expand Up @@ -153,7 +155,9 @@ const defaultProps = {
showFloatingInput: false,
inline: false,
inlineHeader: "AI Assistant by Trieve",
suggestedQueriesContext: "You are an ecommerce sales assistant to help people buy items."
suggestedQueriesContext: "You are an ecommerce sales assistant to help people buy items.",
groupTrackingId: undefined,
cleanGroupName: undefined,
};

const ModalContext = createContext<{
Expand Down
2 changes: 1 addition & 1 deletion server/src/handlers/message_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ pub async fn get_suggested_queries(
context_sentence,
number_of_suggestions_to_create,
query_style,
number_of_suggestions_to_create,
number_of_suggestions_to_create,
query_style,
query_style,
query_style,
Expand Down
3 changes: 2 additions & 1 deletion server/src/public/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@

if (params.inline) {
const inlineRoot = document.querySelector("#inline-root");

params.groupTrackingId = params.singleProductOptions.groupTrackingId;
params.cleanGroupName = params.singleProductOptions.productName;
renderToDiv(inlineRoot, {
...params,
})
Expand Down

0 comments on commit 5ab7556

Please sign in to comment.