@@ -90,18 +90,18 @@ const ChatContext = createContext<{
9090 rateChatCompletion : ( isPositive : boolean , queryId : string | null ) => void ;
9191 productsWithClicks : ChunkIdWithIndex [ ] ;
9292} > ( {
93- askQuestion : async ( ) => { } ,
93+ askQuestion : async ( ) => { } ,
9494 currentQuestion : "" ,
9595 isLoading : false ,
9696 loadingText : "" ,
9797 messages : [ ] ,
98- setCurrentQuestion : ( ) => { } ,
99- cancelGroupChat : ( ) => { } ,
100- clearConversation : ( ) => { } ,
101- chatWithGroup : ( ) => { } ,
102- switchToChatAndAskQuestion : async ( ) => { } ,
103- stopGeneratingMessage : ( ) => { } ,
104- rateChatCompletion : ( ) => { } ,
98+ setCurrentQuestion : ( ) => { } ,
99+ cancelGroupChat : ( ) => { } ,
100+ clearConversation : ( ) => { } ,
101+ chatWithGroup : ( ) => { } ,
102+ switchToChatAndAskQuestion : async ( ) => { } ,
103+ stopGeneratingMessage : ( ) => { } ,
104+ rateChatCompletion : ( ) => { } ,
105105 productsWithClicks : [ ] ,
106106} ) ;
107107
@@ -465,7 +465,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
465465 } ) ;
466466 }
467467
468- if ( props . chatFilters ) {
468+ if ( props . chatFilters && ( ! groupIds || groupIds . length === 0 ) ) {
469469 if ( props . chatFilters . must ) {
470470 if ( ! filters . must ) {
471471 filters . must = [ ] ;
@@ -572,78 +572,79 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
572572 }
573573 } ) ;
574574
575- const skipSearchPromise = retryOperation ( async ( ) => {
576- if ( props . type === "ecommerce" && ! curGroup && messages . length > 1 ) {
577- return await trieveSDK . getToolCallFunctionParams ( {
578- user_message_text : `Here's the previous message thread so far: ${ messages . map (
579- ( message ) => {
580- if (
581- message . type === "system" &&
582- message . additional ?. length &&
583- props . type === "ecommerce"
584- ) {
585- const chunks = message . additional
586- . map ( ( chunk ) => {
587- return JSON . stringify ( {
588- title : chunk . metadata ?. title || "" ,
589- description : chunk . chunk_html || "" ,
590- price : chunk . num_value
591- ? `${ props . defaultCurrency || "" } ${ chunk . num_value } `
592- : "" ,
593- link : chunk . link || "" ,
594- } ) ;
595- } )
596- . join ( "\n\n" ) ;
597- return `\n\n${ chunks } ${ message . text } ` ;
598- } else {
599- return `\n\n${ message . text } ` ;
600- }
601- } ,
602- ) } \n\n${ props . searchToolCallOptions ?. userMessageTextPrefix ?? defaultSearchToolCallOptions . userMessageTextPrefix } : ${ questionProp || currentQuestion } .`,
603- image_url : imageUrl ? imageUrl : null ,
604- audio_input : curAudioBase64 ? curAudioBase64 : null ,
605- tool_function : {
606- name : "skip_search" ,
607- description :
608- props . searchToolCallOptions ?. toolDescription ??
609- ( defaultSearchToolCallOptions . toolDescription as string ) ,
610- parameters : [
611- {
612- name : "skip_search" ,
613- parameter_type : "boolean" ,
614- description :
615- "Set to true if the query is asking about products which were shown to them previously in the message thread only incldue if they are referenced by name. Set to false if the query is asking about the general catalog products or for different/other products differing from the ones shown previously. Only set this to true if the query contains a title that was in the previous messages" ,
616- } ,
617- ] ,
618- } ,
619- } ) ;
620- } } )
621-
622- const imageFiltersPromise = retryOperation ( async ( ) => {
623- if ( imageUrl ) {
624- return await trieveSDK . getToolCallFunctionParams ( {
625- user_message_text : questionProp || currentQuestion ,
626- image_url : imageUrl ? imageUrl : null ,
627- tool_function : {
628- name : "get_image_filters" ,
629- description :
630- "Decide whether to either edit an image based on the user's query. Always return false if the user's query does not require or request for an image to be edited." ,
631- parameters : [
632- {
633- name : "image" ,
634- parameter_type : "boolean" ,
635- description :
636- "Whether to edit an image based on the user's query. If the user asks to edit, try-on, generate, show, or visualize based on an image, return true, otherwise return false. Furthermore if the user asks how does something look or to try something on, return true." ,
575+ const skipSearchPromise = retryOperation ( async ( ) => {
576+ if ( props . type === "ecommerce" && ! curGroup && messages . length > 1 ) {
577+ return await trieveSDK . getToolCallFunctionParams ( {
578+ user_message_text : `Here's the previous message thread so far: ${ messages . map (
579+ ( message ) => {
580+ if (
581+ message . type === "system" &&
582+ message . additional ?. length &&
583+ props . type === "ecommerce"
584+ ) {
585+ const chunks = message . additional
586+ . map ( ( chunk ) => {
587+ return JSON . stringify ( {
588+ title : chunk . metadata ?. title || "" ,
589+ description : chunk . chunk_html || "" ,
590+ price : chunk . num_value
591+ ? `${ props . defaultCurrency || "" } ${ chunk . num_value } `
592+ : "" ,
593+ link : chunk . link || "" ,
594+ } ) ;
595+ } )
596+ . join ( "\n\n" ) ;
597+ return `\n\n${ chunks } ${ message . text } ` ;
598+ } else {
599+ return `\n\n${ message . text } ` ;
600+ }
637601 } ,
638- ] ,
639- } ,
640- } ) ;
641- } else {
642- return {
643- parameters : null ,
644- } ;
645- }
646- } ) ;
602+ ) } \n\n${ props . searchToolCallOptions ?. userMessageTextPrefix ?? defaultSearchToolCallOptions . userMessageTextPrefix } : ${ questionProp || currentQuestion } .`,
603+ image_url : imageUrl ? imageUrl : null ,
604+ audio_input : curAudioBase64 ? curAudioBase64 : null ,
605+ tool_function : {
606+ name : "skip_search" ,
607+ description :
608+ props . searchToolCallOptions ?. toolDescription ??
609+ ( defaultSearchToolCallOptions . toolDescription as string ) ,
610+ parameters : [
611+ {
612+ name : "skip_search" ,
613+ parameter_type : "boolean" ,
614+ description :
615+ "Set to true if the query is asking about products which were shown to them previously in the message thread only incldue if they are referenced by name. Set to false if the query is asking about the general catalog products or for different/other products differing from the ones shown previously. Only set this to true if the query contains a title that was in the previous messages" ,
616+ } ,
617+ ] ,
618+ } ,
619+ } ) ;
620+ }
621+ } )
622+
623+ const imageFiltersPromise = retryOperation ( async ( ) => {
624+ if ( imageUrl ) {
625+ return await trieveSDK . getToolCallFunctionParams ( {
626+ user_message_text : questionProp || currentQuestion ,
627+ image_url : imageUrl ? imageUrl : null ,
628+ tool_function : {
629+ name : "get_image_filters" ,
630+ description :
631+ "Decide whether to either edit an image based on the user's query. Always return false if the user's query does not require or request for an image to be edited." ,
632+ parameters : [
633+ {
634+ name : "image" ,
635+ parameter_type : "boolean" ,
636+ description :
637+ "Whether to edit an image based on the user's query. If the user asks to edit, try-on, generate, show, or visualize based on an image, return true, otherwise return false. Furthermore if the user asks how does something look or to try something on, return true." ,
638+ } ,
639+ ] ,
640+ } ,
641+ } ) ;
642+ } else {
643+ return {
644+ parameters : null ,
645+ } ;
646+ }
647+ } ) ;
647648
648649 const tagFiltersPromise = retryOperation ( async ( ) => {
649650 if (
@@ -656,13 +657,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
656657 user_message_text :
657658 questionProp || currentQuestion
658659 ? `Get filters from the following messages: ${ messages
659- . slice ( 0 , - 1 )
660- . filter ( ( message ) => {
661- return message . type == "user" ;
662- } )
663- . map (
664- ( message ) => `\n\n${ message . text } ` ,
665- ) } \n\n ${ questionProp || currentQuestion } `
660+ . slice ( 0 , - 1 )
661+ . filter ( ( message ) => {
662+ return message . type == "user" ;
663+ } )
664+ . map (
665+ ( message ) => `\n\n${ message . text } ` ,
666+ ) } \n\n ${ questionProp || currentQuestion } `
666667 : null ,
667668 image_url : imageUrl ? imageUrl : null ,
668669 audio_input : curAudioBase64 ? curAudioBase64 : null ,
@@ -695,7 +696,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
695696 } ) ;
696697
697698 const [ priceFiltersResp , imageFiltersResp , tagFiltersResp , skipSearchResp ] =
698- await Promise . all ( [
699+ await Promise . all ( [
699700 priceFiltersPromise ,
700701 imageFiltersPromise ,
701702 tagFiltersPromise ,
@@ -727,7 +728,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
727728 }
728729
729730 useImage = ( imageFiltersResp ?. parameters &&
730- ( imageFiltersResp . parameters as any ) [ "image" ] === true && imageUrl ) as boolean ;
731+ ( imageFiltersResp . parameters as any ) [ "image" ] === true && imageUrl ) as boolean ;
731732
732733 const match_any_tags = [ ] ;
733734 if ( tagFiltersResp ?. parameters ) {
@@ -915,13 +916,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
915916 : null ;
916917 const imageUrls = props . relevanceToolCallOptions ?. includeImages
917918 ? (
918- ( firstChunk ?. image_urls ?. filter (
919- ( stringOrNull ) : stringOrNull is string =>
920- Boolean ( stringOrNull ) ,
921- ) ||
922- [ ] ) ??
923- [ ]
924- ) . splice ( 0 , 1 )
919+ ( firstChunk ?. image_urls ?. filter (
920+ ( stringOrNull ) : stringOrNull is string =>
921+ Boolean ( stringOrNull ) ,
922+ ) ||
923+ [ ] ) ??
924+ [ ]
925+ ) . splice ( 0 , 1 )
925926 : undefined ;
926927 const jsonOfFirstChunk = {
927928 title : ( firstChunk ?. metadata as any ) ?. title ?? "" ,
@@ -1030,25 +1031,25 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
10301031 ] ,
10311032 } ;
10321033
1033- try {
1034- const topImageGroupIds = topGroupIds . slice ( 0 , 3 ) ;
1035- const getChunksPromises = topImageGroupIds . map ( ( groupId ) =>
1036- trieveSDK . getChunksInGroup ( {
1037- groupId,
1038- page : 1 ,
1039- } ) ,
1040- ) ;
1041- const groupChunks = await Promise . all ( getChunksPromises ) ;
1042- referenceImageUrls = groupChunks . map (
1043- ( group ) => group . chunks [ 0 ] ?. image_urls ?. [ 0 ] || [ ] ,
1044- ) as string [ ] ;
1045- referenceChunks = groupChunks . map (
1046- ( group ) => group . chunks [ 0 ] || [ ] ,
1047- ) as Chunk [ ] ;
1048- } catch ( e ) {
1049- console . error ( "Error getting reference images:" , e ) ;
1050- referenceImageUrls = [ ] ;
1051- }
1034+ try {
1035+ const topImageGroupIds = topGroupIds . slice ( 0 , 3 ) ;
1036+ const getChunksPromises = topImageGroupIds . map ( ( groupId ) =>
1037+ trieveSDK . getChunksInGroup ( {
1038+ groupId,
1039+ page : 1 ,
1040+ } ) ,
1041+ ) ;
1042+ const groupChunks = await Promise . all ( getChunksPromises ) ;
1043+ referenceImageUrls = groupChunks . map (
1044+ ( group ) => group . chunks [ 0 ] ?. image_urls ?. [ 0 ] || [ ] ,
1045+ ) as string [ ] ;
1046+ referenceChunks = groupChunks . map (
1047+ ( group ) => group . chunks [ 0 ] || [ ] ,
1048+ ) as Chunk [ ] ;
1049+ } catch ( e ) {
1050+ console . error ( "Error getting reference images:" , e ) ;
1051+ referenceImageUrls = [ ] ;
1052+ }
10521053 } catch ( e ) {
10531054 console . error ( "error getting determine_relevance" , e ) ;
10541055 }
@@ -1109,7 +1110,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
11091110
11101111 return false ;
11111112 } ;
1112-
1113+
11131114 if ( referenceImageUrls . length > 0 ) {
11141115 if ( await handleImageEdit ( ) ) {
11151116 return ;
0 commit comments