diff --git a/config/env/env.dev b/config/env/env.dev index 66d477b9..88dfc406 100644 --- a/config/env/env.dev +++ b/config/env/env.dev @@ -12,4 +12,4 @@ LOGIN_REDIRECT_URL= OPENAI_API_KEY= PINECONE_API_KEY= EMAIL_HOST_USER=balancer-noreply@codeforphilly.org -EMAIL_HOST_PASSWORD=lrclncfsoeyldbzo \ No newline at end of file +EMAIL_HOST_PASSWORD= \ No newline at end of file diff --git a/frontend/.env b/frontend/.env index 38d1ea0e..2bfce617 100644 --- a/frontend/.env +++ b/frontend/.env @@ -1,2 +1,2 @@ -VITE_API_BASE_URL=https://balancertestsite.com/ -# VITE_API_BASE_URL=http://localhost:8000 \ No newline at end of file +# VITE_API_BASE_URL=https://balancertestsite.com/ +VITE_API_BASE_URL=http://localhost:8000 \ No newline at end of file diff --git a/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx b/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx index 01876fc5..9aab59a6 100644 --- a/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx +++ b/frontend/src/pages/DrugSummary/DrugSummaryForm.tsx @@ -116,7 +116,7 @@ const DrugSummaryForm = () => { const sendMessage = (message: ChatLogItem[]) => { const baseUrl = import.meta.env.VITE_API_BASE_URL; - const url = `${baseUrl}/chatgpt/chat`; + const url = `${baseUrl}/v1/api/embeddings/ask_embeddings`; const apiMessages = message.map((messageObject) => { let role = ""; @@ -128,15 +128,14 @@ const DrugSummaryForm = () => { return { role: role, content: messageObject.message }; }); + setIsLoading(true); systemMessage.content += `If applicable, please use the following content to ask questions. If not applicable, please answer to the best of your ability: ${pageContent}`; const apiRequestBody = { - prompt: [systemMessage, ...apiMessages], + message: [apiMessages], }; - setIsLoading(true); - axios .post(url, apiRequestBody) .then((response) => { @@ -219,9 +218,11 @@ const DrugSummaryForm = () => { )) )} - {isLoading && ( + {!isLoading && (
-
+
+ Let's me think +
)}
@@ -265,7 +266,7 @@ const DrugSummaryForm = () => { type="submit" className=" h-12 rounded-xl border bg-blue-500 px-3 py-1.5 font-satoshi text-white hover:bg-blue-400" > - Send + Send. diff --git a/frontend/src/services/parsing/ParseWithSource.tsx b/frontend/src/services/parsing/ParseWithSource.tsx new file mode 100644 index 00000000..46517581 --- /dev/null +++ b/frontend/src/services/parsing/ParseWithSource.tsx @@ -0,0 +1,88 @@ +import { Link } from "react-router-dom"; +import { EmbeddingInfo } from "./chat"; + +interface ParseStringWithLinksProps { + text: string; + chunkData: EmbeddingInfo[]; +} +const ParseStringWithLinks: React.FC = ({ + text, + chunkData, +}) => { + const parseText = (text: string) => { + // Regular expression to find ***[GUID, Page X, Chunk Y]*** + const regex = /\*\*\*\[([^\]]+)\]\*\*\*/g; + + // Create a map of chunk information for easy lookup + const chunkMap = new Map< + string, + { name: string; page_number: number; chunk_number: number; text: string } + >(); + chunkData.forEach(({ file_id, name, page_number, chunk_number, text }) => { + const key = `${file_id}-${page_number}-${chunk_number}`; + chunkMap.set(key, { name, page_number, chunk_number, text }); + // console.log( + // `Set chunkMap[${key}] = { name: ${name}, page_number: ${page_number}, chunk_number: ${chunk_number}, text: ${text} }` + // ); + }); + + // console.log("chunkMap:", chunkMap); + + // Use replace method to process the text and insert links + const processedText = text.split(regex).map((part, index) => { + // If the index is odd, it means this part is between *** *** + if (index % 2 === 1) { + // Extract GUID, page number, and chunk number from the matched part + const guidMatch = part.match(/([a-f0-9\-]{36})/); + const pageNumberMatch = part.match(/Page\s*(?:Number:)?\s*(\d+)/i); + const chunkNumberMatch = part.match(/Chunk\s*(\d+)/i); + + // console.log("Matched Part:", part); + // console.log("GUID Match:", guidMatch); + // console.log("Page Number Match:", pageNumberMatch); + // console.log("Chunk Number Match:", chunkNumberMatch); + + if (guidMatch && pageNumberMatch && chunkNumberMatch) { + const guid = guidMatch[1]; + const pageNumber = pageNumberMatch[1]; + const chunkNumber = chunkNumberMatch[1]; + + const chunkKey = `${guid}-${pageNumber}-${chunkNumber}`; + const chunkData = chunkMap.get(chunkKey); + + if (chunkData) { + const { name, text: chunkText } = chunkData; + const tooltipContent = `Document Name: ${name}, Page: ${pageNumber}, Chunk: ${chunkNumber}, Text: ${chunkText}`; + // console.log("chunkKey:", chunkKey); + // console.log("tooltipContent:", tooltipContent); + + return ( + + {`${pageNumber}`} + + ); + } + } + } + + return ( + ") }} + /> + ); + }); + + // console.log("processedText:", processedText); + return <>{processedText}; + }; + // console.log("processedText:",
{parseText(text)}
); + return
{parseText(text)}
; +}; + +export default ParseStringWithLinks; diff --git a/frontend/src/services/parsing/chat.ts b/frontend/src/services/parsing/chat.ts new file mode 100644 index 00000000..928eeb87 --- /dev/null +++ b/frontend/src/services/parsing/chat.ts @@ -0,0 +1,37 @@ +export interface ChatLogItem { + type: string; + message: string | SearchResult; +} + +export interface SearchResult { + question: string; + llm_response: string; + embeddings_info: EmbeddingInfo[]; + } + +export interface GetAllPrompts { + id: number | string; + guid: string; + PromptText: string; + IsActive: null | boolean; + Area: string; + CreatedAt: Date; + LastModified: Date; + } + + export interface EmbeddingInfo { + name: string; + text: string; + chunk_number: number; + file_id: number; + page_number: number; + distance: number; + } + + export interface ChatLog { + type: string; + message: string; + userId?: number; + first_name?: string; + timestamp: string; +}