From 0c716d87a3b9ece5b0fa77ffb8f9c008ecf78fda Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 23 Jun 2025 15:44:31 -0400
Subject: fixed gptpopup to do something more reasonable when asked to tag
 documents.

---
 src/client/views/pdf/GPTPopup/GPTPopup.tsx | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

(limited to 'src/client/views/pdf/GPTPopup/GPTPopup.tsx')

diff --git a/src/client/views/pdf/GPTPopup/GPTPopup.tsx b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
index 660284397..ec269cc6c 100644
--- a/src/client/views/pdf/GPTPopup/GPTPopup.tsx
+++ b/src/client/views/pdf/GPTPopup/GPTPopup.tsx
@@ -11,7 +11,7 @@ import { ClientUtils } from '../../../../ClientUtils';
 import { Doc } from '../../../../fields/Doc';
 import { NumCast, StrCast } from '../../../../fields/Types';
 import { Networking } from '../../../Network';
-import { DescriptionSeperator, DocSeperator, GPTCallType, GPTDocCommand, gptAPICall, gptImageCall } from '../../../apis/gpt/GPT';
+import { DataSeperator, DescriptionSeperator, DocSeperator, GPTCallType, GPTDocCommand, gptAPICall, gptImageCall } from '../../../apis/gpt/GPT';
 import { DocUtils } from '../../../documents/DocUtils';
 import { Docs } from '../../../documents/Documents';
 import { SettingsManager } from '../../../util/SettingsManager';
@@ -145,20 +145,22 @@ export class GPTPopup extends ObservableReactComponent<object> {
                     break;
             } // prettier-ignore
 
-            gptOutput.split('======').filter(item => item.trim() !== '')  // Split output into individual document contents
-                .map(docContentRaw => textToDocMap.get(docContentRaw.replace(/\n/g, ' ').trim())) // the find the corresponding Doc using textToDoc map
-                .filter(doc => doc).map(doc => doc!) // filter out undefined values
-                .forEach((doc, index) => {
+            gptOutput.split(DescriptionSeperator).filter(item => item.trim() !== '')  // Split output into individual document contents
+                .map(docContentRaw => docContentRaw.replace(/\n/g, ' ').trim())
+                .map(docContentRaw => ({doc: textToDocMap.get(docContentRaw.split(DataSeperator)[0]), data: docContentRaw.split(DataSeperator)[1] })) // the find the corresponding Doc using textToDoc map
+                .filter(({doc}) => doc).map(({doc, data}) => ({doc:doc!, data})) // filter out undefined values
+                .forEach(({doc, data}, index) => {
                     switch (questionType) {
                         case GPTDocCommand.Sort:
                             doc[ChatSortField] = index;
                             break;
                         case GPTDocCommand.AssignTags:
-                            if (args) {
-                                const hashTag = args.startsWith('#') ? args : '#' + args[0].toLowerCase() + args.slice(1);
-                                const filterTag = Doc.MyFilterHotKeys.map(key => StrCast(key.toolType)).find(key => key.includes(args)) ?? hashTag;
-                                TagItem.addTagToDoc(doc, filterTag);
-                            }
+                            TagItem.addTagToDoc(doc, data.startsWith('#') ? data : '#'+data);
+                            // if (args) {
+                            //     const hashTag = args.startsWith('#') ? args : '#' + args[0].toLowerCase() + args.slice(1);
+                            //     const filterTag = Doc.MyFilterHotKeys.map(key => StrCast(key.toolType)).find(key => key.includes(args)) ?? hashTag;
+                            //     TagItem.addTagToDoc(doc, filterTag);
+                            // }
                             break;
                         case GPTDocCommand.Filter:
                             TagItem.addTagToDoc(doc, GPTPopup.ChatTag);
@@ -241,7 +243,7 @@ export class GPTPopup extends ObservableReactComponent<object> {
         gptAPICall(userPrompt, GPTCallType.COMMANDTYPE, undefined, true).then((commandType, args = commandType.split(' ').slice(1).join(' ')) =>
             (async () => {
                 switch (this.NumberToCommandType(commandType)) {
-                    case GPTDocCommand.AssignTags:
+                    case GPTDocCommand.AssignTags:return this._documentDescriptions?.then(descs => gptAPICall(userPrompt, GPTCallType.TAGDOCS, descs)) ?? "";
                     case GPTDocCommand.Filter:    return this._documentDescriptions?.then(descs => gptAPICall(userPrompt, GPTCallType.SUBSETDOCS, descs)) ?? "";
                     case GPTDocCommand.Sort:      return this._documentDescriptions?.then(descs => gptAPICall(userPrompt, GPTCallType.SORTDOCS, descs)) ?? "";
                     default:                      return Doc.getDescription(DocumentView.SelectedDocs().lastElement()).then(desc => gptAPICall(userPrompt, GPTCallType.DOCINFO, desc));
-- 
cgit v1.2.3-70-g09d2

