mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 05:29:12 +00:00
Switch to let Khoj infer chat query based on user automation query
This tries to decouple the automation query from the chat query. So the chat model doesn't have to know it is running in an automation context or figure how to notify user or send automation response. It just has to respond to the AI generated `query_to_run' corresponding to the `scheduling_request` automation by the user. For example, a `scheduling_request' of `notify me when X happens' results in the automation calling the chat api with a `query_to_run` like `tell me about X` and deciding if to notify based on information gathered about X from the scheduled run. If these two are not decoupled, the chat model may respond with how it can notify about X instead of just asking about it. Swap query_to_run with scheduling_request on the automation web page
This commit is contained in:
@@ -167,68 +167,68 @@ const timestamp = Date.now();
|
||||
const suggestedAutomationsMetadata: AutomationsData[] = [
|
||||
{
|
||||
subject: "Weekly Newsletter",
|
||||
query_to_run:
|
||||
scheduling_request:
|
||||
"/research Compile a message including: 1. A recap of news from last week 2. An at-home workout I can do before work 3. A quote to inspire me for the week ahead",
|
||||
schedule: "9AM every Monday",
|
||||
next: "Next run at 9AM on Monday",
|
||||
crontime: "0 9 * * 1",
|
||||
id: timestamp,
|
||||
scheduling_request: "",
|
||||
},
|
||||
{
|
||||
subject: "Daily Bedtime Story",
|
||||
query_to_run:
|
||||
"Compose a bedtime story that a five-year-old might enjoy. It should not exceed five paragraphs. Appeal to the imagination, but weave in learnings.",
|
||||
schedule: "9PM every night",
|
||||
next: "Next run at 9PM today",
|
||||
crontime: "0 21 * * *",
|
||||
id: timestamp + 1,
|
||||
scheduling_request: "",
|
||||
query_to_run: "",
|
||||
},
|
||||
{
|
||||
subject: "Front Page of Hacker News",
|
||||
query_to_run:
|
||||
scheduling_request:
|
||||
"/research Summarize the top 5 posts from https://news.ycombinator.com/best and share them with me, including links",
|
||||
schedule: "9PM on every Wednesday",
|
||||
next: "Next run at 9PM on Wednesday",
|
||||
crontime: "0 21 * * 3",
|
||||
id: timestamp + 2,
|
||||
scheduling_request: "",
|
||||
query_to_run: "",
|
||||
},
|
||||
{
|
||||
subject: "Market Summary",
|
||||
query_to_run:
|
||||
scheduling_request:
|
||||
"/research Get the market summary for today and share it with me. Focus on tech stocks and the S&P 500.",
|
||||
schedule: "9AM on every weekday",
|
||||
next: "Next run at 9AM on Monday",
|
||||
crontime: "0 9 * * *",
|
||||
id: timestamp + 3,
|
||||
scheduling_request: "",
|
||||
query_to_run: "",
|
||||
},
|
||||
{
|
||||
subject: "Market Crash Notification",
|
||||
query_to_run: "Notify me if the stock market fell by more than 5% today.",
|
||||
scheduling_request: "Notify me if the stock market fell by more than 5% today.",
|
||||
schedule: "5PM every evening",
|
||||
next: "Next run at 5PM today",
|
||||
crontime: "0 17 * * *",
|
||||
id: timestamp + 5,
|
||||
scheduling_request: "",
|
||||
query_to_run: "",
|
||||
},
|
||||
{
|
||||
subject: "Round-up of research papers about AI in healthcare",
|
||||
query_to_run:
|
||||
scheduling_request:
|
||||
"/research Summarize the top 3 research papers about AI in healthcare that were published in the last week. Include links to the full papers.",
|
||||
schedule: "9AM every Friday",
|
||||
next: "Next run at 9AM on Friday",
|
||||
crontime: "0 9 * * 5",
|
||||
id: timestamp + 4,
|
||||
scheduling_request: "",
|
||||
query_to_run: "",
|
||||
},
|
||||
{
|
||||
subject: "Daily Bedtime Story",
|
||||
scheduling_request:
|
||||
"Compose a bedtime story that a five-year-old might enjoy. It should not exceed five paragraphs. Appeal to the imagination, but weave in learnings.",
|
||||
schedule: "9PM every night",
|
||||
next: "Next run at 9PM today",
|
||||
crontime: "0 21 * * *",
|
||||
id: timestamp + 1,
|
||||
query_to_run: "",
|
||||
},
|
||||
];
|
||||
|
||||
function createShareLink(automation: AutomationsData) {
|
||||
const encodedSubject = encodeURIComponent(automation.subject);
|
||||
const encodedQuery = encodeURIComponent(automation.query_to_run);
|
||||
const encodedQuery = encodeURIComponent(automation.scheduling_request);
|
||||
const encodedCrontime = encodeURIComponent(automation.crontime);
|
||||
|
||||
const shareLink = `${window.location.origin}/automations?subject=${encodedSubject}&query=${encodedQuery}&crontime=${encodedCrontime}`;
|
||||
@@ -391,7 +391,7 @@ function AutomationsCard(props: AutomationsCardProps) {
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="text-secondary-foreground break-all">
|
||||
{updatedAutomationData?.query_to_run || automation.query_to_run}
|
||||
{updatedAutomationData?.scheduling_request || automation.scheduling_request}
|
||||
</CardContent>
|
||||
<CardFooter className="flex flex-col items-start md:flex-row md:justify-between md:items-center gap-2">
|
||||
<div className="flex gap-2">
|
||||
@@ -451,8 +451,8 @@ function SharedAutomationCard(props: SharedAutomationCardProps) {
|
||||
const automation: AutomationsData = {
|
||||
id: 0,
|
||||
subject: decodeURIComponent(subject),
|
||||
query_to_run: decodeURIComponent(query),
|
||||
scheduling_request: "",
|
||||
scheduling_request: decodeURIComponent(query),
|
||||
query_to_run: "",
|
||||
schedule: cronToHumanReadableString(decodeURIComponent(crontime)),
|
||||
crontime: decodeURIComponent(crontime),
|
||||
next: "",
|
||||
@@ -480,7 +480,7 @@ const EditAutomationSchema = z.object({
|
||||
dayOfWeek: z.optional(z.number()),
|
||||
dayOfMonth: z.optional(z.string()),
|
||||
timeRecurrence: z.string({ required_error: "Time Recurrence is required" }),
|
||||
queryToRun: z.string({ required_error: "Query to Run is required" }),
|
||||
schedulingRequest: z.string({ required_error: "Query to Run is required" }),
|
||||
});
|
||||
|
||||
interface EditCardProps {
|
||||
@@ -507,7 +507,7 @@ function EditCard(props: EditCardProps) {
|
||||
? getTimeRecurrenceFromCron(automation.crontime)
|
||||
: "12:00 PM",
|
||||
dayOfMonth: automation?.crontime ? getDayOfMonthFromCron(automation.crontime) : "1",
|
||||
queryToRun: automation?.query_to_run,
|
||||
schedulingRequest: automation?.scheduling_request,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -520,7 +520,7 @@ function EditCard(props: EditCardProps) {
|
||||
);
|
||||
|
||||
let updateQueryUrl = `/api/automation?`;
|
||||
updateQueryUrl += `q=${encodeURIComponent(values.queryToRun)}`;
|
||||
updateQueryUrl += `q=${encodeURIComponent(values.schedulingRequest)}`;
|
||||
if (automation?.id && !props.createNew) {
|
||||
updateQueryUrl += `&automation_id=${encodeURIComponent(automation.id)}`;
|
||||
}
|
||||
@@ -829,7 +829,7 @@ function AutomationModificationForm(props: AutomationModificationFormProps) {
|
||||
)}
|
||||
<FormField
|
||||
control={props.form.control}
|
||||
name="queryToRun"
|
||||
name="schedulingRequest"
|
||||
render={({ field }) => (
|
||||
<FormItem className="space-y-1">
|
||||
<FormLabel>Instructions</FormLabel>
|
||||
@@ -850,7 +850,7 @@ function AutomationModificationForm(props: AutomationModificationFormProps) {
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
{errors.subject && (
|
||||
<FormMessage>{errors.queryToRun?.message}</FormMessage>
|
||||
<FormMessage>{errors.schedulingRequest?.message}</FormMessage>
|
||||
)}
|
||||
</FormItem>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user