You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: apps/web/utils/ai/choose-rule/ai-choose-rule.ts
+7-10
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ import { Braintrust } from "@/utils/braintrust";
8
8
9
9
constlogger=createScopedLogger("ai-choose-rule");
10
10
11
-
constbraintrust=newBraintrust("choose-rule-1");
11
+
constbraintrust=newBraintrust("choose-rule-2");
12
12
13
13
typeGetAiResponseOptions={
14
14
email: EmailForLLM;
@@ -29,14 +29,13 @@ async function getAiResponse(options: GetAiResponseOptions) {
29
29
<priority>
30
30
1. Match the email to a SPECIFIC user-defined rule that addresses the email's exact content or purpose.
31
31
2. If the email doesn't match any specific rule but the user has a catch-all rule (like "emails that don't match other criteria"), use that catch-all rule.
32
-
3. Only use rule system fallback if no user-defined rule can reasonably apply.
32
+
3. Only set "noMatchFound" to true if no user-defined rule can reasonably apply.
33
33
</priority>
34
34
35
35
<guidelines>
36
36
- If a rule says to exclude certain types of emails, DO NOT select that rule for those excluded emails.
37
37
- When multiple rules match, choose the more specific one that best matches the email's content.
38
38
- Rules about requiring replies should be prioritized when the email clearly needs a response.
39
-
- The system fallback rule should ONLY be selected when there is absolutely no user-defined rule that could apply.
40
39
</guidelines>
41
40
</instructions>
42
41
@@ -51,13 +50,6 @@ ${rules
51
50
.join("\n")}
52
51
</user_rules>
53
52
54
-
<system_fallback>
55
-
<name>System fallback</name>
56
-
<instructions>
57
-
The system fallback rule should ONLY be selected when there is absolutely no user-defined rule that could apply.
58
-
</instructions>
59
-
</system_fallback>
60
-
61
53
${
62
54
user.about
63
55
? `<user_info>
@@ -73,6 +65,7 @@ ${
73
65
Respond with a JSON object with the following fields:
74
66
"reason" - the reason you chose that rule. Keep it concise.
75
67
"ruleName" - the exact name of the rule you want to apply
68
+
"noMatchFound" - true if no match was found, false otherwise
76
69
</outputFormat>`;
77
70
78
71
constprompt=`Select a rule to apply to this email that was sent to me:
@@ -106,6 +99,7 @@ ${emailSection}
106
99
schema: z.object({
107
100
reason: z.string(),
108
101
ruleName: z.string(),
102
+
noMatchFound: z.boolean().optional(),
109
103
}),
110
104
userEmail: user.email||"",
111
105
usageLabel: "Choose rule",
@@ -144,6 +138,9 @@ export async function aiChooseRule<
0 commit comments