diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/ChatBox/ChatBox.tsx | 13 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/MessageComponent.tsx | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/prompts.ts | 2 | ||||
-rw-r--r-- | src/client/views/nodes/ChatBox/tools/RAGTool.ts | 5 | ||||
-rw-r--r-- | src/server/ApiManagers/AssistantManager.ts | 10 |
5 files changed, 18 insertions, 14 deletions
diff --git a/src/client/views/nodes/ChatBox/ChatBox.tsx b/src/client/views/nodes/ChatBox/ChatBox.tsx index 45f5c0a65..d79233fae 100644 --- a/src/client/views/nodes/ChatBox/ChatBox.tsx +++ b/src/client/views/nodes/ChatBox/ChatBox.tsx @@ -251,9 +251,12 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { const docChunkSimpl = JSON.parse(StrCast(doc.chunk_simpl)) as { chunks: SimplifiedChunk[] }; console.log(docChunkSimpl); const foundChunk = docChunkSimpl.chunks.find(chunk => chunk.chunkId === chunkId); + console.log(foundChunk); if (foundChunk) { - switch (getChunkType(foundChunk.chunkType)) { + console.log(getChunkType(foundChunk.chunkType)); + switch (foundChunk.chunkType) { case CHUNK_TYPE.IMAGE: + case CHUNK_TYPE.TABLE: const values = foundChunk.location?.replace(/[\[\]]/g, '').split(','); if (values?.length !== 4) { @@ -262,9 +265,9 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { } const x1 = parseFloat(values[0]) * Doc.NativeWidth(doc); - const y1 = parseFloat(values[1]) * Doc.NativeHeight(doc); + const y1 = parseFloat(values[1]) * Doc.NativeHeight(doc) + foundChunk.startPage * Doc.NativeHeight(doc); const x2 = parseFloat(values[2]) * Doc.NativeWidth(doc); - const y2 = parseFloat(values[3]) * Doc.NativeHeight(doc); + const y2 = parseFloat(values[3]) * Doc.NativeHeight(doc) + foundChunk.startPage * Doc.NativeHeight(doc); const annotationKey = Doc.LayoutFieldKey(doc) + '_annotations'; @@ -290,7 +293,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { }); break; default: - console.log('Chunk type not supported'); + console.log('Chunk type not supported', foundChunk.chunkType); break; } } @@ -339,7 +342,7 @@ export class ChatBox extends ViewBoxAnnotatableComponent<FieldViewProps>() { runInAction(() => { this.history.push({ role: ASSISTANT_ROLE.ASSISTANT, - content: [{ index: 0, type: TEXT_TYPE.NORMAL, text: 'Welcome to the Document Analyser Assistant! Link a document or ask questions to get started.', citation_ids: null }], + content: [{ index: 0, type: TEXT_TYPE.NORMAL, text: `Hey, ${this.userName()} Welcome to the Your Friendly Assistant! Link a document or ask questions about anything to get started.`, citation_ids: null }], processing_info: [], }); }); diff --git a/src/client/views/nodes/ChatBox/MessageComponent.tsx b/src/client/views/nodes/ChatBox/MessageComponent.tsx index d0e78c751..812e52ee0 100644 --- a/src/client/views/nodes/ChatBox/MessageComponent.tsx +++ b/src/client/views/nodes/ChatBox/MessageComponent.tsx @@ -16,7 +16,7 @@ const MessageComponentBox: React.FC<MessageComponentProps> = function ({ message const renderContent = (item: MessageContent) => { const i = item.index; - console.log('item', item, 'index', i); + //console.log('item', item, 'index', i); if (item.type === TEXT_TYPE.GROUNDED) { const citation_ids = item.citation_ids || []; return ( diff --git a/src/client/views/nodes/ChatBox/prompts.ts b/src/client/views/nodes/ChatBox/prompts.ts index 845b4d255..76d958daf 100644 --- a/src/client/views/nodes/ChatBox/prompts.ts +++ b/src/client/views/nodes/ChatBox/prompts.ts @@ -27,6 +27,8 @@ export function getReactPrompt(tools: Tool[], summaries: () => string, chatHisto <point>If a tool is needed, ALWAYS select the most appropriate tool based on the user's query.</point> <point>If the query could relate to user documents or require external information (e.g., RAG, search + website scraping, data analysis), USE the appropriate tool to gather that information.</point> <point>If there are no user docs or the user docs have not yielded helpful information, use the search tool to find websites followed by the website scraper tool to get useful infromation from one of those websites. You can use the website scraper (or even the search tool), multiple times to find information from multiple websites either from the same search or different searches.</point> + <point>Always follow the response structure provided in the instructions.</point> + <point>If you are stuck in a loop because a tool isn't helping you even though you think it should, use the 'no_tool' action to proceed with the response and ask the user for more information or clarification or let them know you cannot answer their question and why.</point> </critical_points> <response_structure> diff --git a/src/client/views/nodes/ChatBox/tools/RAGTool.ts b/src/client/views/nodes/ChatBox/tools/RAGTool.ts index 26fa2adc5..fcd0ea43f 100644 --- a/src/client/views/nodes/ChatBox/tools/RAGTool.ts +++ b/src/client/views/nodes/ChatBox/tools/RAGTool.ts @@ -54,9 +54,10 @@ export class RAGTool extends BaseTool<{ hypothetical_document_chunk: string }> { 5. Detailed Citation Guidelines: a. Create a unique citation for each distinct piece of information from the chunks that is used to support grounded_text. + b. ALL TEXT CITATIONS must have direct text in its element content (e.g. <citation ...>DIRECT TEXT HERE</citation>) that is a relevant subset of the original text chunk that is being cited specifically. b. Ensure each citation has a unique index number. c. Specify the correct type: "text", "image", or "table". - d. For text chunks, include only the relevant subset of the original text that the grounded_text is based on. + d. For text chunks, the content of the citation should ALWAYS have the relevant subset of the original text that the grounded_text is based on. e. For image/table chunks, leave the citation content empty. f. One citation can be used for multiple grounded_text tags if they are based on the same chunk information. g. !!!DO NOT OVERCITE - only include citations for information that is directly relevant to the grounded_text. @@ -120,7 +121,7 @@ export class RAGTool extends BaseTool<{ hypothetical_document_chunk: string }> { async getFormattedChunks(relevantChunks: RAGChunk[]): Promise<{ type: string; text?: string; image_url?: { url: string } }[]> { try { const { formattedChunks } = await Networking.PostToServer('/formatChunks', { relevantChunks }); - + console.log('Formatted Chunks:', formattedChunks); if (!formattedChunks) { throw new Error('Failed to format chunks'); } diff --git a/src/server/ApiManagers/AssistantManager.ts b/src/server/ApiManagers/AssistantManager.ts index a59a2d22d..9bc5bf128 100644 --- a/src/server/ApiManagers/AssistantManager.ts +++ b/src/server/ApiManagers/AssistantManager.ts @@ -189,7 +189,7 @@ export default class AssistantManager extends ApiManager { try { // Read file data and convert to base64 - const file_data = fs.readFileSync(public_path, { encoding: 'base64' }); + const file_data: string = fs.readFileSync(public_path, { encoding: 'base64' }); const response = await axios.post( 'http://localhost:8080/createDocument', @@ -265,12 +265,12 @@ export default class AssistantManager extends ApiManager { for (const chunk of relevantChunks) { content.push({ type: 'text', - text: `<chunk chunk_id=${chunk.id} chunk_type=${chunk.metadata.type === 'image' || chunk.metadata.type === 'table' ? 'image' : 'text'}>`, + text: `<chunk chunk_id=${chunk.id} chunk_type=${chunk.metadata.type}>`, }); if (chunk.metadata.type === 'image' || chunk.metadata.type === 'table') { try { - const filePath = serverPathToFile(Directory.parsed_files, chunk.metadata.file_path); + const filePath = serverPathToFile(Directory.chunk_images, chunk.metadata.file_path); const imageBuffer = await readFileAsync(filePath); const base64Image = imageBuffer.toString('base64'); if (base64Image) { @@ -286,10 +286,8 @@ export default class AssistantManager extends ApiManager { } catch (error) { console.error(`Error reading image file for chunk ${chunk.id}:`, error); } - content.push({ type: 'text', text: `\n</chunk>\n` }); - } else { - content.push({ type: 'text', text: `${chunk.metadata.text}\n</chunk>\n` }); } + content.push({ type: 'text', text: `${chunk.metadata.text}\n</chunk>\n` }); } content.push({ type: 'text', text: '</chunks>' }); |