mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 13:25:11 +00:00
Add /task command. Use it to disable scheduling tasks from tasks
This takes the load of the task scheduling chat actor / prompt from having to artifically differentiate query to create scheduled task from a scheduled task run.
This commit is contained in:
@@ -528,7 +528,7 @@ User: Hahah, nice! Show a new one every morning at 9:40. My Current Location: Sh
|
|||||||
Khoj: {{
|
Khoj: {{
|
||||||
"Scratchpad": "Shanghai is UTC+8. So, 9:40 in Shanghai is 1:40 UTC. I'll also generalize the search query to get better results.",
|
"Scratchpad": "Shanghai is UTC+8. So, 9:40 in Shanghai is 1:40 UTC. I'll also generalize the search query to get better results.",
|
||||||
"Crontime": "40 1 * * *",
|
"Crontime": "40 1 * * *",
|
||||||
"Query": "Share a funny Calvin and Hobbes or Bill Watterson quote from my notes."
|
"Query": "/task Share a funny Calvin and Hobbes or Bill Watterson quote from my notes."
|
||||||
}}
|
}}
|
||||||
|
|
||||||
## Chat History
|
## Chat History
|
||||||
@@ -537,7 +537,7 @@ User: Every Monday evening share the top posts on Hacker News from last week. Fo
|
|||||||
Khoj: {{
|
Khoj: {{
|
||||||
"Scratchpad": "Nairobi is UTC+3. As evening specified, I'll share at 18:30 your time. Which will be 15:30 UTC.",
|
"Scratchpad": "Nairobi is UTC+3. As evening specified, I'll share at 18:30 your time. Which will be 15:30 UTC.",
|
||||||
"Crontime": "30 15 * * 1",
|
"Crontime": "30 15 * * 1",
|
||||||
"Query": "Top posts last week on Hacker News"
|
"Query": "/task Top posts last week on Hacker News"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
## Chat History
|
## Chat History
|
||||||
@@ -548,7 +548,7 @@ User: Notify me when version 2.0.0 is released. My Current Location: Mexico City
|
|||||||
Khoj: {{
|
Khoj: {{
|
||||||
"Scratchpad": "Mexico City is UTC-6. No time is specified, so I'll notify at 10:00 your time. Which will be 16:00 in UTC. Also I'll ensure the search query doesn't trigger another reminder.",
|
"Scratchpad": "Mexico City is UTC-6. No time is specified, so I'll notify at 10:00 your time. Which will be 16:00 in UTC. Also I'll ensure the search query doesn't trigger another reminder.",
|
||||||
"Crontime": "0 16 * * *",
|
"Crontime": "0 16 * * *",
|
||||||
"Query": "Check if the latest released version of the Khoj python package is >= 2.0.0?"
|
"Query": "/task Check if the latest released version of the Khoj python package is >= 2.0.0?"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
## Chat History
|
## Chat History
|
||||||
@@ -557,7 +557,7 @@ User: Tell me the latest local tech news on the first Sunday of every Month. My
|
|||||||
Khoj: {{
|
Khoj: {{
|
||||||
"Scratchpad": "Dublin is UTC+1. So, 10:00 in Dublin is 8:00 UTC. First Sunday of every month is 1-7. Also I'll enhance the search query.",
|
"Scratchpad": "Dublin is UTC+1. So, 10:00 in Dublin is 8:00 UTC. First Sunday of every month is 1-7. Also I'll enhance the search query.",
|
||||||
"Crontime": "0 9 1-7 * 0",
|
"Crontime": "0 9 1-7 * 0",
|
||||||
"Query": "Find the latest tech, AI and engineering news from around Dublin, Ireland"
|
"Query": "/task Find the latest tech, AI and engineering news from around Dublin, Ireland"
|
||||||
}}
|
}}
|
||||||
|
|
||||||
## Chat History
|
## Chat History
|
||||||
@@ -566,7 +566,7 @@ User: Inform me when the national election results are officially declared. Run
|
|||||||
Khoj: {{
|
Khoj: {{
|
||||||
"Scratchpad": "Trichy is UTC+5:30. So, 4pm in Trichy is 10:30 UTC. Also let's add location details to the search query.",
|
"Scratchpad": "Trichy is UTC+5:30. So, 4pm in Trichy is 10:30 UTC. Also let's add location details to the search query.",
|
||||||
"Crontime": "30 10 * * 4",
|
"Crontime": "30 10 * * 4",
|
||||||
"Query": "Check if the Indian national election results are officially declared."
|
"Query": "/task Check if the Indian national election results are officially declared."
|
||||||
}}
|
}}
|
||||||
|
|
||||||
# Chat History:
|
# Chat History:
|
||||||
|
|||||||
@@ -379,13 +379,14 @@ async def websocket_endpoint(
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
meta_log = conversation.conversation_log
|
meta_log = conversation.conversation_log
|
||||||
|
is_task = conversation_commands == [ConversationCommand.Task]
|
||||||
|
|
||||||
if conversation_commands == [ConversationCommand.Default]:
|
if conversation_commands == [ConversationCommand.Default] or is_task:
|
||||||
conversation_commands = await aget_relevant_information_sources(q, meta_log)
|
conversation_commands = await aget_relevant_information_sources(q, meta_log)
|
||||||
conversation_commands_str = ", ".join([cmd.value for cmd in conversation_commands])
|
conversation_commands_str = ", ".join([cmd.value for cmd in conversation_commands])
|
||||||
await send_status_update(f"**🗃️ Chose Data Sources to Search:** {conversation_commands_str}")
|
await send_status_update(f"**🗃️ Chose Data Sources to Search:** {conversation_commands_str}")
|
||||||
|
|
||||||
mode = await aget_relevant_output_modes(q, meta_log)
|
mode = await aget_relevant_output_modes(q, meta_log, is_task)
|
||||||
await send_status_update(f"**🧑🏾💻 Decided Response Mode:** {mode.value}")
|
await send_status_update(f"**🧑🏾💻 Decided Response Mode:** {mode.value}")
|
||||||
if mode not in conversation_commands:
|
if mode not in conversation_commands:
|
||||||
conversation_commands.append(mode)
|
conversation_commands.append(mode)
|
||||||
@@ -638,9 +639,11 @@ async def chat(
|
|||||||
else:
|
else:
|
||||||
meta_log = conversation.conversation_log
|
meta_log = conversation.conversation_log
|
||||||
|
|
||||||
if conversation_commands == [ConversationCommand.Default]:
|
is_task = conversation_commands == [ConversationCommand.Task]
|
||||||
|
|
||||||
|
if conversation_commands == [ConversationCommand.Default] or is_task:
|
||||||
conversation_commands = await aget_relevant_information_sources(q, meta_log)
|
conversation_commands = await aget_relevant_information_sources(q, meta_log)
|
||||||
mode = await aget_relevant_output_modes(q, meta_log)
|
mode = await aget_relevant_output_modes(q, meta_log, is_task)
|
||||||
if mode not in conversation_commands:
|
if mode not in conversation_commands:
|
||||||
conversation_commands.append(mode)
|
conversation_commands.append(mode)
|
||||||
|
|
||||||
|
|||||||
@@ -163,6 +163,8 @@ def get_conversation_command(query: str, any_references: bool = False) -> Conver
|
|||||||
return ConversationCommand.Online
|
return ConversationCommand.Online
|
||||||
elif query.startswith("/image"):
|
elif query.startswith("/image"):
|
||||||
return ConversationCommand.Image
|
return ConversationCommand.Image
|
||||||
|
elif query.startswith("/task"):
|
||||||
|
return ConversationCommand.Task
|
||||||
# If no relevant notes found for the given query
|
# If no relevant notes found for the given query
|
||||||
elif not any_references:
|
elif not any_references:
|
||||||
return ConversationCommand.General
|
return ConversationCommand.General
|
||||||
@@ -220,7 +222,7 @@ async def aget_relevant_information_sources(query: str, conversation_history: di
|
|||||||
return [ConversationCommand.Default]
|
return [ConversationCommand.Default]
|
||||||
|
|
||||||
|
|
||||||
async def aget_relevant_output_modes(query: str, conversation_history: dict):
|
async def aget_relevant_output_modes(query: str, conversation_history: dict, is_task: bool = False):
|
||||||
"""
|
"""
|
||||||
Given a query, determine which of the available tools the agent should use in order to answer appropriately.
|
Given a query, determine which of the available tools the agent should use in order to answer appropriately.
|
||||||
"""
|
"""
|
||||||
@@ -229,6 +231,9 @@ async def aget_relevant_output_modes(query: str, conversation_history: dict):
|
|||||||
mode_options_str = ""
|
mode_options_str = ""
|
||||||
|
|
||||||
for mode, description in mode_descriptions_for_llm.items():
|
for mode, description in mode_descriptions_for_llm.items():
|
||||||
|
# Do not allow tasks to schedule another task
|
||||||
|
if is_task and mode == ConversationCommand.Reminder:
|
||||||
|
continue
|
||||||
mode_options[mode.value] = description
|
mode_options[mode.value] = description
|
||||||
mode_options_str += f'- "{mode.value}": "{description}"\n'
|
mode_options_str += f'- "{mode.value}": "{description}"\n'
|
||||||
|
|
||||||
|
|||||||
@@ -305,6 +305,7 @@ class ConversationCommand(str, Enum):
|
|||||||
Webpage = "webpage"
|
Webpage = "webpage"
|
||||||
Image = "image"
|
Image = "image"
|
||||||
Reminder = "reminder"
|
Reminder = "reminder"
|
||||||
|
Task = "task"
|
||||||
|
|
||||||
|
|
||||||
command_descriptions = {
|
command_descriptions = {
|
||||||
@@ -315,6 +316,7 @@ command_descriptions = {
|
|||||||
ConversationCommand.Webpage: "Get information from webpage links provided by you.",
|
ConversationCommand.Webpage: "Get information from webpage links provided by you.",
|
||||||
ConversationCommand.Image: "Generate images by describing your imagination in words.",
|
ConversationCommand.Image: "Generate images by describing your imagination in words.",
|
||||||
ConversationCommand.Reminder: "Schedule your query to run at a specified time or interval.",
|
ConversationCommand.Reminder: "Schedule your query to run at a specified time or interval.",
|
||||||
|
ConversationCommand.Task: "Scheduled task running at previously specified schedule.",
|
||||||
ConversationCommand.Help: "Display a help message with all available commands and other metadata.",
|
ConversationCommand.Help: "Display a help message with all available commands and other metadata.",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user