diff --git a/application/api/answer/routes/base.py b/application/api/answer/routes/base.py index 6176c5a8..e0118b58 100644 --- a/application/api/answer/routes/base.py +++ b/application/api/answer/routes/base.py @@ -179,6 +179,12 @@ class BaseAnswerResource: log_data["structured_output"] = True if schema_info: log_data["schema"] = schema_info + + # clean up text fields to be no longer than 10000 characters + for key, value in log_data.items(): + if isinstance(value, str) and len(value) > 10000: + log_data[key] = value[:10000] + self.user_logs_collection.insert_one(log_data) # End of stream diff --git a/application/api/answer/services/conversation_service.py b/application/api/answer/services/conversation_service.py index e35fcc40..3ea7a136 100644 --- a/application/api/answer/services/conversation_service.py +++ b/application/api/answer/services/conversation_service.py @@ -66,6 +66,11 @@ class ConversationService: if not user_id: raise ValueError("User ID not found in token") current_time = datetime.now(timezone.utc) + + # clean up in sources array such that we save max 1k characters for text part + for source in sources: + if "text" in source and isinstance(source["text"], str): + source["text"] = source["text"][:1000] if conversation_id is not None and index is not None: # Update existing conversation with new query diff --git a/application/api/user/routes.py b/application/api/user/routes.py index ae9ccb31..4167f65b 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -64,7 +64,7 @@ attachments_collection = db["attachments"] try: agents_collection.create_index( - [("shared_publicly", 1)], + [("shared", 1)], name="shared_index", background=True, ) diff --git a/application/logging.py b/application/logging.py index d48fb17e..2c5cde27 100644 --- a/application/logging.py +++ b/application/logging.py @@ -136,6 +136,8 @@ def _log_to_mongodb( mongo = MongoDB.get_client() db = mongo[settings.MONGO_DB_NAME] user_logs_collection = db["stack_logs"] + + log_entry = { "endpoint": endpoint, @@ -147,6 +149,11 @@ def _log_to_mongodb( "stacks": stacks, "timestamp": datetime.datetime.now(datetime.timezone.utc), } + # clean up text fields to be no longer than 10000 characters + for key, value in log_entry.items(): + if isinstance(value, str) and len(value) > 10000: + log_entry[key] = value[:10000] + user_logs_collection.insert_one(log_entry) logging.debug(f"Logged activity to MongoDB: {activity_id}") diff --git a/application/worker.py b/application/worker.py index 23f96bf5..71747005 100755 --- a/application/worker.py +++ b/application/worker.py @@ -471,9 +471,13 @@ def attachment_worker(self, file_info, user): .load_data()[0] .text, ) - + + token_count = num_tokens_from_string(content) - + if token_count > 100000: + content = content[:250000] + token_count = num_tokens_from_string(content) + self.update_state( state="PROGRESS", meta={"current": 80, "status": "Storing in database"} ) diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx index 6379eb0a..3be40df7 100644 --- a/frontend/src/conversation/ConversationBubble.tsx +++ b/frontend/src/conversation/ConversationBubble.tsx @@ -92,8 +92,7 @@ const ConversationBubble = forwardRef< const [editInputBox, setEditInputBox] = useState(''); const messageRef = useRef(null); const [shouldShowToggle, setShouldShowToggle] = useState(false); - const [isLikeClicked, setIsLikeClicked] = useState(false); - const [isDislikeClicked, setIsDislikeClicked] = useState(false); + const [activeTooltip, setActiveTooltip] = useState(null); const [isSidebarOpen, setIsSidebarOpen] = useState(false); const editableQueryRef = useRef(null); @@ -550,104 +549,71 @@ const ConversationBubble = forwardRef< )} {message && (
-
-
- -
-
-
-
- -
-
- {type === 'ERROR' && ( + {type === 'ERROR' ? (
{retryBtn}
- )} - {handleFeedback && ( + ) : ( <> -
-
-
- { - if (feedback === undefined || feedback === null) { - handleFeedback?.('LIKE'); - setIsLikeClicked(true); - setIsDislikeClicked(false); - } else if (feedback === 'LIKE') { - handleFeedback?.(null); - setIsLikeClicked(false); - setIsDislikeClicked(false); - } - }} - onMouseEnter={() => setIsLikeHovered(true)} - onMouseLeave={() => setIsLikeHovered(false)} - > -
-
+
+
+
+ +
+ {handleFeedback && ( + <> +
+
+
+ { + if (feedback === 'LIKE') { + handleFeedback?.(null); + } else { + handleFeedback?.('LIKE'); + } + }} + onMouseEnter={() => setIsLikeHovered(true)} + onMouseLeave={() => setIsLikeHovered(false)} + > +
+
+
-
-
-
- { - if (feedback === undefined || feedback === null) { - handleFeedback?.('DISLIKE'); - setIsDislikeClicked(true); - setIsLikeClicked(false); - } else if (feedback === 'DISLIKE') { - handleFeedback?.(null); - setIsLikeClicked(false); - setIsDislikeClicked(false); - } - }} - onMouseEnter={() => setIsDislikeHovered(true)} - onMouseLeave={() => setIsDislikeHovered(false)} - > +
+
+
+ { + if (feedback === 'DISLIKE') { + handleFeedback?.(null); + } else { + handleFeedback?.('DISLIKE'); + } + }} + onMouseEnter={() => setIsDislikeHovered(true)} + onMouseLeave={() => setIsDislikeHovered(false)} + > +
+
-
-
+ + )} )}