@@ -9,26 +9,21 @@ import {
99 DialogSurface ,
1010 DialogTitle ,
1111 Tag ,
12- Tooltip ,
1312 makeStyles ,
1413} from "@fluentui/react-components" ;
1514import { DocDialog } from "../documentViewer/documentViewer" ;
1615import { Textarea } from "@fluentai/textarea" ;
1716import type { TextareaSubmitEvents , TextareaValueData } from "@fluentai/textarea" ;
1817import { CopilotChat , UserMessage , CopilotMessage } from "@fluentai/react-copilot-chat" ;
19- import { ChatAdd24Regular , DocumentOnePageLink20Regular } from "@fluentui/react-icons" ;
20- import { AttachmentTag } from "@fluentai/attachments" ;
18+ import { ChatAdd24Regular } from "@fluentui/react-icons" ;
2119import styles from "./chatRoom.module.scss" ;
22- import { CopilotProvider , FeedbackButtons , Suggestion } from "@fluentai/react-copilot" ;
23- import { Result , SingleDocument , Tokens } from "../../api/apiTypes/singleDocument" ;
24- //import { getDocument } from "../../api/documentsService";
20+ import { CopilotProvider , Suggestion } from "@fluentai/react-copilot" ;
21+ import { Tokens } from "../../api/apiTypes/singleDocument" ;
2522import { Completion , PostFeedback } from "../../api/chatService" ;
2623import { FeedbackForm } from "./FeedbackForm" ;
2724import { Document } from "../../api/apiTypes/documentResults" ;
2825import { AppContext } from "../../AppContext" ;
2926import { useTranslation } from "react-i18next" ;
30- import ReactMarkdown from "react-markdown" ;
31- import { renderToStaticMarkup } from "react-dom/server" ;
3227import { marked } from 'marked' ;
3328const DefaultChatModel = "chat_4o" ;
3429
@@ -48,12 +43,10 @@ interface ChatRoomProps {
4843}
4944
5045export function ChatRoom ( { searchResultDocuments, selectedDocuments, chatWithDocument, disableOptionsPanel, clearChatFlag } : ChatRoomProps ) {
51- const customStyles = useStyles ( ) ;
5246 const { t } = useTranslation ( ) ;
5347 const [ chatSessionId , setChatSessionId ] = useState < string | null > ( null ) ;
5448 const [ isLoading , setIsLoading ] = useState < boolean > ( false ) ;
5549 const [ disableSources , setDisableSources ] = useState < boolean > ( false ) ;
56- const [ error , setError ] = useState < unknown > ( ) ;
5750 const [ model , setModel ] = useState < string > ( "chat_35" ) ;
5851 const [ source , setSource ] = useState < string > ( "rag" ) ;
5952 const [ temperature , setTemperature ] = useState < number > ( 0.8 ) ;
@@ -105,7 +98,7 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
10598 if ( clearChatFlag ) {
10699 clearChat ( ) ;
107100 }
108- } , [ clearChatFlag ] ) ; // Runs whenever clearChat changes
101+ } , [ clearChatFlag ] ) ;
109102
110103
111104
@@ -124,85 +117,30 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
124117
125118 const makeApiRequest = async ( question : string ) => {
126119 setTextAreaValue ( "" ) ;
127- //Force Textarea re-render to reset internal showCount
128120 setTextareaKey ( prev => prev + 1 ) ;
129121 setDisableSources ( true ) ;
130122 setIsLoading ( true ) ;
131123
132- // A simple function to check if the text contains Markdown
133- const isMarkdown = ( text : string ) => {
134- const markdownPattern = / ( ^ | \s ) ( # { 1 , 6 } | \* \* | _ _ | [ - * ] | \d + \. \s | \[ .* \] \( .* \) | ` ` ` | ` [ ^ ` ] * ` ) / ;
135- return markdownPattern . test ( text ) ;
136- } ;
137-
138124 const userTimestamp = new Date ( ) ;
139- // Ensure we have a chatSessionId or create one if null/undefined
140-
141-
142- let currentSessionId = chatSessionId ; // Get the current value of chatSessionId
125+
126+ let currentSessionId = chatSessionId ;
143127 if ( ! currentSessionId ) {
144- const newSessionId = uuidv4 ( ) ; // Generate a new UUID if no session exists
145- setChatSessionId ( newSessionId ) ; // Save it for future renders
146- currentSessionId = newSessionId ; // Immediately use the new session ID in this function
147-
128+ const newSessionId = uuidv4 ( ) ;
129+ setChatSessionId ( newSessionId ) ;
130+ currentSessionId = newSessionId ;
148131 }
149- const markdownToHtmlString = ( markdown : string ) => {
150- return renderToStaticMarkup ( < ReactMarkdown > { markdown } </ ReactMarkdown > ) ;
151- } ;
152- const markdown = `| Data Point | Value | Document Name | Page Number |
153- |----------------|-----------|-------------------|------------------|
154- | Households with accessibility needs | 23.1 million | Accessibility in Housing Report | Page 1 |
155- | Households with mobility-related disabilities | 19% of U.S. households | Accessibility in Housing Report | Page 1 |
156- | Households without entry-level bedroom or full bathroom planning to add features | 1% | Accessibility in Housing Report | Page 3 |
157- | Households planning to make homes more accessible | 5% | Accessibility in Housing Report | Page 3 |
158- | Households with someone using mobility devices | 13% | Accessibility in Housing Report | Page 1 |
159- | Households with serious difficulty hearing | 12% | Accessibility in Housing Report | Page 24 |
160- | Households with serious difficulty seeing | 12% | Accessibility in Housing Report | Page 24 |
161- | Households with difficulty walking or climbing stairs | 12% | Accessibility in Housing Report | Page 24 |
162- | Households with difficulty dressing or bathing | 12% | Accessibility in Housing Report | Page 24 |
163- | Households with difficulty doing errands alone | 12% | Accessibility in Housing Report | Page 24 |
164- | Households with full bathrooms on entry level | 58% | Accessibility in Housing Report | Page 11 |
165- | Households with bedrooms on entry level | 46% | Accessibility in Housing Report | Page 11 |
166- | Total single-family loans acquired by Fannie Mae in 2021 | $2.6 trillion | Annual Housing Report 2022 | Page 36 |
167- | Total single-family loans acquired by Freddie Mac in 2021 | $2.6 trillion | Annual Housing Report 2022 | Page 36 |
168- | Percentage of loans with LTV > 95% | 13.5% | Annual Housing Report 2022 | Page 44 |
169- | Percentage of loans with LTV <= 60% | 15.6% | Annual Housing Report 2022 | Page 44 |
170- | Total NPLs sold by Enterprises through December 2023 | 168,364 | FHFA Non-Performing Loan Sales Report | Page 2 |
171- | Average delinquency of NPLs sold | 2.8 years | FHFA Non-Performing Loan Sales Report | Page 2 |
172- | Average current mark-to-market LTV ratio of NPLs | 83% | FHFA Non-Performing Loan Sales Report | Page 2 |` ;
173-
174- const htmlString = await marked . parse ( markdown ) ;
175- const htmlString2 = markdownToHtmlString ( markdown ) ;
176132
177133 setConversationAnswers ( ( prevAnswers ) => [
178134 ...prevAnswers ,
179135 [ question , {
180- answer : t ( 'components.chat.fetching-answer' ) , suggestingQuestions : [ ] ,
136+ answer : t ( 'components.chat.fetching-answer' ) ,
137+ suggestingQuestions : [ ] ,
181138 documentIds : [ ] ,
182139 keywords : [ ]
183140 } ] ,
184141 ] ) ;
185142
186-
187-
188-
189-
190- let filterByDocumentIds : string [ ] = [ ] ;
191-
192-
193- const transformDocuments = ( documents : any [ ] ) => {
194- return documents . map ( doc => doc . documentId ) ; // Extracting documentId from each document
195- } ;
196- const formattedDocuments = transformDocuments ( selectedDocuments ) ;
197-
198-
199- if ( button === "Selected Document" && selectedDocument ) {
200- filterByDocumentIds = [ selectedDocument [ 0 ] . documentId ] ;
201- } else if ( button === "Search Results" ) {
202- filterByDocumentIds = searchResultDocuments . map ( ( document ) => document . documentId ) ;
203- } else if ( button === "Selected Documents" ) {
204- filterByDocumentIds = selectedDocuments . map ( ( document ) => document . documentId ) ;
205- }
143+ const formattedDocuments = selectedDocuments . map ( doc => doc . documentId ) ;
206144
207145 try {
208146 const request : ChatRequest = {
@@ -212,24 +150,18 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
212150 } ;
213151
214152 const response : ChatApiResponse = await Completion ( request ) ;
215-
216- setIsLoading ( false ) ;
217-
218153 const answerTimestamp = new Date ( ) ;
219154
220155 if ( response && response . answer ) {
221156 const formattedAnswer = removeNewlines ( response . answer ) ;
222157 const chatResp = await marked . parse ( formattedAnswer ) ;
223158
224- // Update the conversation with the formatted answer
225159 setConversationAnswers ( ( prevAnswers ) => {
226160 const newAnswers = [ ...prevAnswers ] ;
227161 newAnswers [ newAnswers . length - 1 ] = [ question , { ...response , answer : chatResp } , userTimestamp , answerTimestamp ] ;
228162 return newAnswers ;
229163 } ) ;
230164 } else {
231- console . error ( "Invalid response received:" , response ) ;
232- // Update with error message
233165 setConversationAnswers ( ( prevAnswers ) => {
234166 const newAnswers = [ ...prevAnswers ] ;
235167 newAnswers [ newAnswers . length - 1 ] = [ question , {
@@ -242,10 +174,6 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
242174 } ) ;
243175 }
244176 } catch ( error ) {
245- console . error ( "Error in makeApiRequest:" , error ) ;
246- setIsLoading ( false ) ;
247-
248- // Update conversation with error message
249177 const answerTimestamp = new Date ( ) ;
250178 setConversationAnswers ( ( prevAnswers ) => {
251179 const newAnswers = [ ...prevAnswers ] ;
@@ -303,21 +231,6 @@ export function ChatRoom({ searchResultDocuments, selectedDocuments, chatWithDoc
303231 }
304232 }
305233
306- // const handleOpenReference = async (referenceId: string, chunkTexts: string[]) => {
307- // try {
308- // const response: SingleDocument = await getDocument(referenceId);
309-
310- // if (response && response.result) {
311- // setTokens(response.tokens);
312- // setIsDialogOpen(true);
313- // setDialogMetadata(response.result);
314- // setAllChunkTexts(chunkTexts);
315- // }
316- // } catch (error) {
317- // console.error("Error fetching data: ", error);
318- // }
319- // };
320-
321234 const handleOpenFeedbackForm = ( sources : Reference [ ] ) => {
322235 setReferencesForFeedbackForm ( sources ) ;
323236 setIsFeedbackFormOpen ( true ) ;
0 commit comments