11// src/components/Chat/Chat.tsx
2+ import { useDownloadPresignedUrlQuery } from '~/hooks/queries/useDownloadPresignedUrl'
3+ import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
4+ import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
5+ import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
6+ import { useLogConversation } from '@/hooks/queries/useLogConversation'
7+ import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
8+ import { useRouteChat } from '@/hooks/queries/useRouteChat'
9+ import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
10+
211import { Button , Text } from '@mantine/core'
312import {
413 IconAlertCircle ,
@@ -29,7 +38,6 @@ import { v4 as uuidv4 } from 'uuid'
2938
3039import HomeContext from '~/pages/api/home/home.context'
3140
32- import { useDownloadPresignedUrlQuery } from '~/hooks/queries/useDownloadPresignedUrl'
3341import { ChatInput } from './ChatInput'
3442import { ChatLoader } from './ChatLoader'
3543import { ErrorMessageDiv } from './ErrorMessageDiv'
@@ -57,13 +65,6 @@ import { Montserrat } from 'next/font/google'
5765import Head from 'next/head'
5866import { useRouter } from 'next/router'
5967import { useAuth } from 'react-oidc-context'
60- import { useFetchEnabledDocGroups } from '@/hooks/queries/useFetchEnabledDocGroups'
61- import { useFetchLLMProviders } from '@/hooks/queries/useFetchLLMProviders'
62- import { useDeleteMessages } from '@/hooks/queries/useDeleteMessages'
63- import { useLogConversation } from '@/hooks/queries/useLogConversation'
64- import { useQueryRewrite } from '@/hooks/queries/useQueryRewrite'
65- import { useRouteChat } from '@/hooks/queries/useRouteChat'
66- import { useUpdateConversation } from '@/hooks/queries/useUpdateConversation'
6768import { CropwizardLicenseDisclaimer } from '~/pages/cropwizard-licenses'
6869
6970import { get_user_permission } from '~/components/UIUC-Components/runAuthCheck'
@@ -110,45 +111,41 @@ export const Chat = memo(
110111 const auth = useAuth ( )
111112 const router = useRouter ( )
112113 const queryClient = useQueryClient ( )
114+ const getCurrentPageName = ( ) => {
115+ // /CS-125/dashboard --> CS-125
116+ return router . asPath . slice ( 1 ) . split ( '/' ) [ 0 ] as string
117+ }
118+ const bannerS3Path = courseMetadata ?. banner_image_s3 || undefined
119+
120+ // React Query hooks
113121 const { refetch : refetchLLMProviders } = useFetchLLMProviders ( {
114122 projectName : courseName ,
115123 } )
116124 const { mutateAsync : runQueryRewriteAsync } = useQueryRewrite ( )
117125 const { mutateAsync : routeChatAsync } = useRouteChat ( )
118- // const
119- const bannerS3Path = courseMetadata ?. banner_image_s3 || undefined
120126 const { data : bannerUrl } = useDownloadPresignedUrlQuery (
121127 bannerS3Path ,
122128 courseName ,
123129 )
124- const getCurrentPageName = ( ) => {
125- // /CS-125/dashboard --> CS-125
126- return router . asPath . slice ( 1 ) . split ( '/' ) [ 0 ] as string
127- }
128- const [ chat_ui ] = useState ( new ChatUI ( new MLCEngine ( ) ) )
129-
130- const [ inputContent , setInputContent ] = useState < string > ( '' )
131-
132- const [ enabledDocumentGroups , setEnabledDocumentGroups ] = useState <
133- string [ ]
134- > ( [ 'All Documents' ] ) // Default to 'All Documents' so retrieval can work immediately
135- const [ enabledTools , setEnabledTools ] = useState < string [ ] > ( [ ] )
136-
137130 const logConversationMutation = useLogConversation ( getCurrentPageName ( ) )
138-
139131 const {
140132 data : documentGroupsHook ,
141133 isSuccess : isSuccessDocumentGroups ,
142134 // isError: isErrorDocumentGroups,
143135 } = useFetchEnabledDocGroups ( getCurrentPageName ( ) )
144-
145136 const {
146137 data : toolsHook ,
147138 isSuccess : isSuccessTools ,
148139 isLoading : isLoadingTools ,
149140 isError : isErrorTools ,
150141 error : toolLoadingError ,
151142 } = useFetchAllWorkflows ( getCurrentPageName ( ) )
143+ const updateConversationMutation = useUpdateConversation (
144+ currentEmail ,
145+ queryClient ,
146+ courseName ,
147+ )
148+ const deleteMessagesMutation = useDeleteMessages ( currentEmail , courseName )
152149
153150 const permission = get_user_permission ( courseMetadata , auth )
154151
@@ -172,6 +169,16 @@ export const Chat = memo(
172169 dispatch : homeDispatch ,
173170 } = useContext ( HomeContext )
174171
172+ // const
173+ const [ chat_ui ] = useState ( new ChatUI ( new MLCEngine ( ) ) )
174+
175+ const [ inputContent , setInputContent ] = useState < string > ( '' )
176+
177+ const [ enabledDocumentGroups , setEnabledDocumentGroups ] = useState <
178+ string [ ]
179+ > ( [ 'All Documents' ] ) // Default to 'All Documents' so retrieval can work immediately
180+ const [ enabledTools , setEnabledTools ] = useState < string [ ] > ( [ ] )
181+
175182 useEffect ( ( ) => {
176183 const loadModel = async ( ) => {
177184 if ( selectedConversation ?. model && ! chat_ui . isModelLoading ( ) ) {
@@ -206,13 +213,6 @@ export const Chat = memo(
206213 const chatContainerRef = useRef < HTMLDivElement > ( null )
207214 const textareaRef = useRef < HTMLTextAreaElement > ( null )
208215 const editedMessageIdRef = useRef < string | undefined > ( undefined )
209- const updateConversationMutation = useUpdateConversation (
210- currentEmail ,
211- queryClient ,
212- courseName ,
213- )
214-
215- const deleteMessagesMutation = useDeleteMessages ( currentEmail , courseName )
216216
217217 // Document Groups
218218 useEffect ( ( ) => {
0 commit comments