From 25d8cdd9cd4cbe1d919425bcc8a11dd322975e70 Mon Sep 17 00:00:00 2001 From: sabaimran Date: Fri, 14 Jun 2024 16:20:22 +0530 Subject: [PATCH] Misc fixes: - Fix getting file filters for not found conversations - Allow iamge rendering in automation emails - Fix nearest 15th minute calculation in automations creation --- src/khoj/interface/web/config_automation.html | 5 +++++ src/khoj/routers/api_chat.py | 3 +++ src/khoj/routers/email.py | 5 ++++- src/khoj/routers/helpers.py | 4 +++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/khoj/interface/web/config_automation.html b/src/khoj/interface/web/config_automation.html index 387dfa2a..82d4179b 100644 --- a/src/khoj/interface/web/config_automation.html +++ b/src/khoj/interface/web/config_automation.html @@ -723,6 +723,11 @@ } var hours = parseInt(hours); var minutes = parseInt(minutes); + minutes = Math.round(minutes / 15) * 15; + if (minutes === 60) { + hours = (hours % 12) + 1; + minutes = 0; + } var timePeriod = hours >= 12 ? 'PM' : 'AM'; hours = hours % 12; hours = hours ? hours : 12; // 0 should be 12 diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index 15c55b1f..43b1cc0c 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -79,6 +79,9 @@ def get_file_filter(request: Request, conversation_id: str) -> Response: conversation = ConversationAdapters.get_conversation_by_user( request.user.object, conversation_id=int(conversation_id) ) + if not conversation: + return Response(content=json.dumps({"status": "error", "message": "Conversation not found"}), status_code=404) + # get all files from "computer" file_list = EntryAdapters.get_all_filenames_by_source(request.user.object, "computer") file_filters = [] diff --git a/src/khoj/routers/email.py b/src/khoj/routers/email.py index 6b271ad4..71c6724b 100644 --- a/src/khoj/routers/email.py +++ b/src/khoj/routers/email.py @@ -91,7 +91,7 @@ async def send_query_feedback(uquery, kquery, sentiment, user_email): return {"message": "Sent Email"} -def send_task_email(name, email, query, result, subject): +def send_task_email(name, email, query, result, subject, is_image=False): if not is_resend_enabled(): logger.debug("Email sending disabled") return @@ -100,6 +100,9 @@ def send_task_email(name, email, query, result, subject): template = env.get_template("task.html") + if is_image: + result = f"![{subject}]({result})" + html_result = markdown_it.MarkdownIt().render(result) html_content = template.render(name=name, subject=subject, query=query, result=html_result) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index 01e0b8c7..56c1c524 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -1009,16 +1009,18 @@ def scheduled_chat( # Extract the AI response from the chat API response cleaned_query = re.sub(r"^/automated_task\s*", "", query_to_run).strip() + is_image = False if raw_response.headers.get("Content-Type") == "application/json": response_map = raw_response.json() ai_response = response_map.get("response") or response_map.get("image") + is_image = response_map.get("image") is not None else: ai_response = raw_response.text # Notify user if the AI response is satisfactory if should_notify(original_query=scheduling_request, executed_query=cleaned_query, ai_response=ai_response): if is_resend_enabled(): - send_task_email(user.get_short_name(), user.email, cleaned_query, ai_response, subject) + send_task_email(user.get_short_name(), user.email, cleaned_query, ai_response, subject, is_image) else: return raw_response