@@ -75,6 +75,7 @@ const ChatContext = createContext<{
7575 groupIds ?: string [ ] ,
7676 systemPrompt ?: string ,
7777 displayUserMessage ?: boolean ,
78+ imageUrl ?: string ,
7879 ) => Promise < void > ;
7980 isLoading : boolean ;
8081 loadingText : string ;
@@ -139,6 +140,8 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
139140 const [ productsWithClicks , setProductsWithClicks ] = useState <
140141 ChunkIdWithIndex [ ]
141142 > ( [ ] ) ;
143+ let localImageUrl = imageUrl ;
144+
142145
143146 const createTopic = async ( {
144147 question,
@@ -520,7 +523,6 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
520523 let referenceImageUrls : string [ ] = [ ] ;
521524 let referenceChunks : Chunk [ ] = [ ] ;
522525
523-
524526 if ( ! groupIds || groupIds . length === 0 ) {
525527 chatMessageAbortController . current = new AbortController ( ) ;
526528 const toolCallTimeout = setTimeout (
@@ -540,7 +542,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
540542 if ( props . type === "ecommerce" && ! curGroup ) {
541543 return await trieveSDK . getToolCallFunctionParams ( {
542544 user_message_text : questionProp || currentQuestion ,
543- image_url : imageUrl ? imageUrl : null ,
545+ image_url : localImageUrl ? localImageUrl : null ,
544546 audio_input : curAudioBase64 ? curAudioBase64 : null ,
545547 tool_function : {
546548 name : "get_price_filters" ,
@@ -600,7 +602,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
600602 }
601603 } ,
602604 ) } \n\n${ props . searchToolCallOptions ?. userMessageTextPrefix ?? defaultSearchToolCallOptions . userMessageTextPrefix } : ${ questionProp || currentQuestion } .`,
603- image_url : imageUrl ? imageUrl : null ,
605+ image_url : localImageUrl ? localImageUrl : null ,
604606 audio_input : curAudioBase64 ? curAudioBase64 : null ,
605607 tool_function : {
606608 name : "skip_search" ,
@@ -621,10 +623,10 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
621623 } )
622624
623625 const imageFiltersPromise = retryOperation ( async ( ) => {
624- if ( imageUrl ) {
626+ if ( localImageUrl ) {
625627 return await trieveSDK . getToolCallFunctionParams ( {
626628 user_message_text : questionProp || currentQuestion ,
627- image_url : imageUrl ? imageUrl : null ,
629+ image_url : localImageUrl ? localImageUrl : null ,
628630 tool_function : {
629631 name : "get_image_filters" ,
630632 description :
@@ -665,7 +667,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
665667 ( message ) => `\n\n${ message . text } ` ,
666668 ) } \n\n ${ questionProp || currentQuestion } `
667669 : null ,
668- image_url : imageUrl ? imageUrl : null ,
670+ image_url : localImageUrl ? localImageUrl : null ,
669671 audio_input : curAudioBase64 ? curAudioBase64 : null ,
670672 tool_function : {
671673 name : "get_filters" ,
@@ -715,7 +717,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
715717 text : transcribedQuery ?? "" ,
716718 additional : null ,
717719 queryId : null ,
718- imageUrl : imageUrl ? imageUrl : null ,
720+ imageUrl : localImageUrl ? localImageUrl : null ,
719721 } ,
720722 {
721723 type : "system" ,
@@ -728,7 +730,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
728730 }
729731
730732 useImage = ( imageFiltersResp ?. parameters &&
731- ( imageFiltersResp . parameters as any ) [ "image" ] === true && imageUrl ) as boolean ;
733+ ( imageFiltersResp . parameters as any ) [ "image" ] === true && localImageUrl ) as boolean ;
732734
733735 const match_any_tags = [ ] ;
734736 if ( tagFiltersResp ?. parameters ) {
@@ -1057,7 +1059,6 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
10571059 }
10581060
10591061 const handleImageEdit = async ( ) => {
1060- console . log ( "REFERENCE IMAGE URLS" , referenceImageUrls ) ;
10611062 if ( useImage ) {
10621063 setLoadingText ( "Editing image..." ) ;
10631064
@@ -1066,7 +1067,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
10661067 input_images : [
10671068 {
10681069 image_src : {
1069- url : imageUrl ,
1070+ url : localImageUrl ,
10701071 } ,
10711072 file_name : "input_image" ,
10721073 } ,
@@ -1302,7 +1303,13 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
13021303 groupIds ?: string [ ] ,
13031304 systemPrompt ?: string ,
13041305 displayUserMessage ?: boolean ,
1306+ imageUrl ?: string ,
13051307 ) => {
1308+ if ( imageUrl ) {
1309+ localImageUrl = imageUrl ;
1310+ setImageUrl ( imageUrl ) ;
1311+ }
1312+
13061313 const questionProp = question ;
13071314 setIsDoneReading ( false ) ;
13081315 setCurrentQuestion ( "" ) ;
@@ -1356,7 +1363,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
13561363 ( displayUserMessage ?? true ) ? questionProp || currentQuestion : "" ,
13571364 additional : null ,
13581365 queryId : null ,
1359- imageUrl : imageUrl ? imageUrl : null ,
1366+ imageUrl : localImageUrl ? localImageUrl : null ,
13601367 } ,
13611368 {
13621369 type : "system" ,
@@ -1373,7 +1380,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
13731380 text : "Loading..." ,
13741381 additional : null ,
13751382 queryId : null ,
1376- imageUrl : imageUrl ? imageUrl : null ,
1383+ imageUrl : localImageUrl ? localImageUrl : null ,
13771384 } ,
13781385 {
13791386 type : "system" ,
@@ -1399,6 +1406,7 @@ function ChatProvider({ children }: { children: React.ReactNode }) {
13991406 systemPrompt,
14001407 } ) ;
14011408 }
1409+ setImageUrl ( "" ) ;
14021410 } ;
14031411
14041412 const switchToChatAndAskQuestion = async ( query : string ) => {
0 commit comments