Skip to content

Commit

Permalink
Misc fixes:
Browse files Browse the repository at this point in the history
- Fix getting file filters for not found conversations
- Allow iamge rendering in automation emails
- Fix nearest 15th minute calculation in automations creation
  • Loading branch information
sabaimran committed Jun 14, 2024
1 parent 971f1cd commit 25d8cdd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/khoj/interface/web/config_automation.html
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,11 @@ <h2 class="section-title">
}
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
Expand Down
3 changes: 3 additions & 0 deletions src/khoj/routers/api_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
5 changes: 4 additions & 1 deletion src/khoj/routers/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion src/khoj/routers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 25d8cdd

Please sign in to comment.