mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-27 17:35:07 +01:00
Misc fixes:
- Fix getting file filters for not found conversations - Allow iamge rendering in automation emails - Fix nearest 15th minute calculation in automations creation
This commit is contained in:
parent
971f1cd897
commit
25d8cdd9cd
4 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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 = []
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue