Skip to content

Commit 10696da

Browse files
committed
Better no rule found handling
1 parent 90f75fe commit 10696da

File tree

3 files changed

+27
-26
lines changed

3 files changed

+27
-26
lines changed

apps/web/utils/ai/choose-rule/ai-choose-rule.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { chatCompletionObject } from "@/utils/llms";
44
import { stringifyEmail } from "@/utils/stringify-email";
55
import type { EmailForLLM } from "@/utils/types";
66
import { createScopedLogger } from "@/utils/logger";
7-
import { Braintrust } from "@/utils/braintrust";
7+
// import { Braintrust } from "@/utils/braintrust";
88

99
const logger = createScopedLogger("ai-choose-rule");
1010

11-
const braintrust = new Braintrust("choose-rule-2");
11+
// const braintrust = new Braintrust("choose-rule-2");
1212

1313
type GetAiResponseOptions = {
1414
email: EmailForLLM;
@@ -98,7 +98,7 @@ ${emailSection}
9898
],
9999
schema: z.object({
100100
reason: z.string(),
101-
ruleName: z.string(),
101+
ruleName: z.string().nullish(),
102102
noMatchFound: z.boolean().nullish(),
103103
}),
104104
userEmail: emailAccount.email,
@@ -107,20 +107,20 @@ ${emailSection}
107107

108108
logger.trace("Response", aiResponse.object);
109109

110-
braintrust.insertToDataset({
111-
id: email.id,
112-
input: {
113-
email: emailSection,
114-
rules: rules.map((rule) => ({
115-
name: rule.name,
116-
instructions: rule.instructions,
117-
})),
118-
hasAbout: !!emailAccount.about,
119-
userAbout: emailAccount.about,
120-
userEmail: emailAccount.email,
121-
},
122-
expected: aiResponse.object.ruleName,
123-
});
110+
// braintrust.insertToDataset({
111+
// id: email.id,
112+
// input: {
113+
// email: emailSection,
114+
// rules: rules.map((rule) => ({
115+
// name: rule.name,
116+
// instructions: rule.instructions,
117+
// })),
118+
// hasAbout: !!emailAccount.about,
119+
// userAbout: emailAccount.about,
120+
// userEmail: emailAccount.email,
121+
// },
122+
// expected: aiResponse.object.ruleName,
123+
// });
124124

125125
return aiResponse.object;
126126
}
@@ -149,7 +149,8 @@ export async function aiChooseRule<
149149

150150
const selectedRule = aiResponse.ruleName
151151
? rules.find(
152-
(rule) => rule.name.toLowerCase() === aiResponse.ruleName.toLowerCase(),
152+
(rule) =>
153+
rule.name.toLowerCase() === aiResponse.ruleName?.toLowerCase(),
153154
)
154155
: undefined;
155156

apps/web/utils/ai/clean/ai-clean.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { createScopedLogger } from "@/utils/logger";
55
import type { EmailForLLM } from "@/utils/types";
66
import { stringifyEmailSimple } from "@/utils/stringify-email";
77
import { formatDateForLLM, formatRelativeTimeForLLM } from "@/utils/date";
8-
import { Braintrust } from "@/utils/braintrust";
98
import { preprocessBooleanLike } from "@/utils/zod";
9+
// import { Braintrust } from "@/utils/braintrust";
1010

1111
const logger = createScopedLogger("ai/clean");
1212

@@ -18,7 +18,7 @@ const schema = z.object({
1818
// reasoning: z.string(),
1919
});
2020

21-
const braintrust = new Braintrust("cleaner-1");
21+
// const braintrust = new Braintrust("cleaner-1");
2222

2323
export async function aiClean({
2424
emailAccount,
@@ -103,11 +103,11 @@ The current date is ${currentDate}.
103103

104104
logger.trace("Result", { response: aiResponse.object });
105105

106-
braintrust.insertToDataset({
107-
id: messageId,
108-
input: { message, currentDate },
109-
expected: aiResponse.object,
110-
});
106+
// braintrust.insertToDataset({
107+
// id: messageId,
108+
// input: { message, currentDate },
109+
// expected: aiResponse.object,
110+
// });
111111

112112
return aiResponse.object as { archive: boolean };
113113
}

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v1.3.13
1+
v1.3.14

0 commit comments

Comments
 (0)