diff options
author | A.J. Shulman <Shulman.aj@gmail.com> | 2025-04-22 12:20:22 -0400 |
---|---|---|
committer | A.J. Shulman <Shulman.aj@gmail.com> | 2025-04-22 12:20:22 -0400 |
commit | 951fe11f0978b36946c5c0c7f2d2cac7b597d311 (patch) | |
tree | f59ce7784dde895e8cf3f8b179ce3f43f26d9ecb /src | |
parent | 8bc8bd13293e64a99b68408ec3d24a50a5dfe4bc (diff) |
improved document creation and limited context window
Diffstat (limited to 'src')
-rw-r--r-- | src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts index eeb9091f8..08351143b 100644 --- a/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts +++ b/src/client/views/nodes/chatbot/tools/DocumentMetadataTool.ts @@ -386,7 +386,8 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp this.documentsById.set(docId, doc); // Get layout doc (the document itself or its layout) - const layoutDoc = Doc.Layout(doc); + // TODO: Check if this works. + const layoutDoc = doc; if (layoutDoc) { this.layoutDocsById.set(docId, layoutDoc); } @@ -448,17 +449,13 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp * @param docId The ID of the document to extract metadata from * @returns An object containing the document's metadata */ - private extractDocumentMetadata(docId: string) { - const doc = this.documentsById.get(docId); - if (!doc) { - return null; - } - - const layoutDoc = this.layoutDocsById.get(docId); - const dataDoc = this.dataDocsById.get(docId); + private extractDocumentMetadata(doc?: Doc) { + if (!doc) return null; + const layoutDoc = doc; + const dataDoc = doc[DocData]; const metadata: Record<string, any> = { - id: docId, + id: doc.dash_document_id || doc.id || '', title: doc.title || '', type: doc.type || '', fields: { @@ -840,11 +837,11 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp string: [], number: [], boolean: [], - doc: [], - list: [], - date: [], - enumeration: [], - other: [], + //doc: [], + //list: [], + //date: [], + //enumeration: [], + //other: [], }, fieldNameMappings: {}, commonFields: { @@ -887,15 +884,15 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp } else if (type === 'boolean') { result.fieldsByType.boolean.push(fieldName); } else if (type === 'doc') { - result.fieldsByType.doc.push(fieldName); + //result.fieldsByType.doc.push(fieldName); } else if (type === 'list') { - result.fieldsByType.list.push(fieldName); + //result.fieldsByType.list.push(fieldName); } else if (type === 'date') { - result.fieldsByType.date.push(fieldName); + //result.fieldsByType.date.push(fieldName); } else if (type === 'enumeration') { - result.fieldsByType.enumeration.push(fieldName); + //result.fieldsByType.enumeration.push(fieldName); } else { - result.fieldsByType.other.push(fieldName); + //result.fieldsByType.other.push(fieldName); } // Categorize by field purpose @@ -1223,7 +1220,7 @@ export class DocumentMetadataTool extends BaseTool<DocumentMetadataToolParamsTyp this.processDocument(createdDoc); // Get the created document's metadata - const createdMetadata = this.getDocumentMetadata(createdDoc.id); + const createdMetadata = this.extractDocumentMetadata(createdDoc); return [ { @@ -1381,13 +1378,14 @@ ${JSON.stringify(createdMetadata, null, 2)}`, */ private getDocumentMetadata(documentId?: string): any { if (documentId) { + const doc = this.documentsById.get(documentId); // Get metadata for a specific document - return this.extractDocumentMetadata(documentId); + return this.extractDocumentMetadata(doc); } else { // Get metadata for all documents const documentsMetadata: Record<string, any> = {}; - for (const docId of this.documentsById.keys()) { - documentsMetadata[docId] = this.extractDocumentMetadata(docId); + for (const doc of this.documentsById.values()) { + documentsMetadata.add(this.extractDocumentMetadata(doc)); } return { |