diff --git a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx index 3ee0e258..88a4fcae 100644 --- a/src/interface/web/app/components/chatInputArea/chatInputArea.tsx +++ b/src/interface/web/app/components/chatInputArea/chatInputArea.tsx @@ -257,9 +257,6 @@ export const ChatInputArea = forwardRef((pr setConvertedAttachedFiles(data); }); - const totalSize = Array.from(files).reduce((acc, file) => acc + file.size, 0); - const totalSizeInMB = totalSize / (1024 * 1024); - // Set focus to the input for user message after uploading files chatInputRef?.current?.focus(); } @@ -612,6 +609,7 @@ export const ChatInputArea = forwardRef((pr > str: + chat_history = "" + for chat in conversation_history.get("chat", [])[-n:]: + if chat["by"] == "khoj" and chat["intent"].get("type") in ["remember", "reminder", "summarize"]: + chat_history += f"User: {chat['intent']['query']}\n" + + if chat["intent"].get("inferred-queries"): + chat_history += f'{agent_name}: {{"queries": {chat["intent"].get("inferred-queries")}}}\n' + + chat_history += f"{agent_name}: {chat['message']}\n\n" + elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")): + chat_history += f"User: {chat['intent']['query']}\n" + chat_history += f"{agent_name}: [generated image redacted for space]\n" + elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")): + chat_history += f"User: {chat['intent']['query']}\n" + chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n" + elif chat["by"] == "you": + raw_attached_files = chat.get("attachedFiles") + if raw_attached_files: + attached_files: Dict[str, str] = {} + for file in raw_attached_files: + attached_files[file["name"]] = file["content"] + + attached_file_context = gather_raw_attached_files(attached_files) + chat_history += f"User: {attached_file_context}\n" + + return chat_history + + def construct_tool_chat_history( previous_iterations: List[InformationCollectionIteration], tool: ConversationCommand = None ) -> Dict[str, list]: @@ -540,35 +569,6 @@ def get_image_from_url(image_url: str, type="pil"): return ImageWithType(content=None, type=None) -def construct_chat_history(conversation_history: dict, n: int = 4, agent_name="AI") -> str: - chat_history = "" - for chat in conversation_history.get("chat", [])[-n:]: - if chat["by"] == "khoj" and chat["intent"].get("type") in ["remember", "reminder", "summarize"]: - chat_history += f"User: {chat['intent']['query']}\n" - - if chat["intent"].get("inferred-queries"): - chat_history += f'{agent_name}: {{"queries": {chat["intent"].get("inferred-queries")}}}\n' - - chat_history += f"{agent_name}: {chat['message']}\n\n" - elif chat["by"] == "khoj" and ("text-to-image" in chat["intent"].get("type")): - chat_history += f"User: {chat['intent']['query']}\n" - chat_history += f"{agent_name}: [generated image redacted for space]\n" - elif chat["by"] == "khoj" and ("excalidraw" in chat["intent"].get("type")): - chat_history += f"User: {chat['intent']['query']}\n" - chat_history += f"{agent_name}: {chat['intent']['inferred-queries'][0]}\n" - elif chat["by"] == "you": - raw_attached_files = chat.get("attachedFiles") - if raw_attached_files: - attached_files: Dict[str, str] = {} - for file in raw_attached_files: - attached_files[file["name"]] = file["content"] - - attached_file_context = gather_raw_attached_files(attached_files) - chat_history += f"User: {attached_file_context}\n" - - return chat_history - - def commit_conversation_trace( session: list[ChatMessage], response: str | list[dict],