mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 23:48:56 +01:00
Improve scheduled task text rendered in UI
This commit is contained in:
parent
0e01362469
commit
6736551ba3
4 changed files with 24 additions and 8 deletions
|
@ -280,7 +280,7 @@
|
|||
<h3 class="card-title">Tasks</h3>
|
||||
</div>
|
||||
<div class="card-description-row">
|
||||
<p id="tasks-settings-card-description" class="card-description">Manage your scheduled tasks handled by Khoj</p>
|
||||
<p id="tasks-settings-card-description" class="card-description">Manage your scheduled tasks</p>
|
||||
</div>
|
||||
<table id="scheduled-tasks-table">
|
||||
<thead>
|
||||
|
|
|
@ -3,6 +3,7 @@ import json
|
|||
import logging
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import time
|
||||
import uuid
|
||||
from typing import Any, Callable, List, Optional, Union
|
||||
|
@ -397,7 +398,11 @@ def get_jobs(request: Request) -> Response:
|
|||
|
||||
# Collate all tasks assigned by user that are still active
|
||||
tasks_info = [
|
||||
{"id": task.id, "name": task.name, "next": task.next_run_time.strftime("%Y-%m-%d %H:%M")}
|
||||
{
|
||||
"id": task.id,
|
||||
"name": re.sub(r"^/task\s*", "", task.name),
|
||||
"next": task.next_run_time.strftime("%Y-%m-%d %H:%M"),
|
||||
}
|
||||
for task in tasks
|
||||
if task.id.startswith(f"job_{user.uuid}_")
|
||||
]
|
||||
|
|
|
@ -3,6 +3,7 @@ import hashlib
|
|||
import json
|
||||
import logging
|
||||
import math
|
||||
import re
|
||||
from datetime import datetime
|
||||
from typing import Dict, Optional
|
||||
from urllib.parse import unquote
|
||||
|
@ -425,10 +426,11 @@ async def websocket_endpoint(
|
|||
f"Unable to schedule reminder. Ensure the reminder doesn't already exist."
|
||||
)
|
||||
continue
|
||||
unprefixed_inferred_query = re.sub(r"^\/task\s*", "", inferred_query)
|
||||
next_run_time = job.next_run_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
llm_response = f"""
|
||||
### 🕒 Scheduled Job
|
||||
- Query: **"{inferred_query}"**
|
||||
### 🕒 Scheduled Task
|
||||
- Query: **"{unprefixed_inferred_query}"**
|
||||
- Schedule: `{crontime}`
|
||||
- Next Run At: **{next_run_time}** UTC.
|
||||
""".strip()
|
||||
|
@ -689,10 +691,11 @@ async def chat(
|
|||
status_code=500,
|
||||
)
|
||||
|
||||
unprefixed_inferred_query = re.sub(r"^\/task\s*", "", inferred_query)
|
||||
next_run_time = job.next_run_time.strftime("%Y-%m-%d %H:%M:%S")
|
||||
llm_response = f"""
|
||||
### 🕒 Scheduled Job
|
||||
- Query: **"{inferred_query}"**
|
||||
### 🕒 Scheduled Task
|
||||
- Query: **"{unprefixed_inferred_query}"**
|
||||
- Schedule: `{crontime}`
|
||||
- Next Run At: **{next_run_time}** UTC.'
|
||||
""".strip()
|
||||
|
|
|
@ -3,6 +3,7 @@ import base64
|
|||
import io
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from functools import partial
|
||||
|
@ -858,8 +859,15 @@ def should_notify(original_query: str, executed_query: str, ai_response: str) ->
|
|||
with timer("Chat actor: Decide to notify user of AI response", logger):
|
||||
try:
|
||||
response = send_message_to_model_wrapper_sync(to_notify_or_not)
|
||||
return "no" not in response.lower()
|
||||
should_notify_result = "no" not in response.lower()
|
||||
logger.info(
|
||||
f'Decided to {"not " if not should_notify_result else ""}notify user of scheduled task response.'
|
||||
)
|
||||
return should_notify_result
|
||||
except:
|
||||
logger.warning(
|
||||
f"Fallback to notify user of scheduled task response as failed to infer should notify or not."
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
|
@ -895,7 +903,7 @@ def scheduled_chat(executing_query: str, scheduling_query: str, user: KhojUser,
|
|||
return None
|
||||
|
||||
# Extract the AI response from the chat API response
|
||||
cleaned_query = scheduling_query.replace("/task", "", 1).strip()
|
||||
cleaned_query = re.sub(r"^/task\s*", "", scheduling_query).strip()
|
||||
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")
|
||||
|
|
Loading…
Reference in a new issue