Skip to content

Commit

Permalink
Simplify ai fix rule
Browse files Browse the repository at this point in the history
  • Loading branch information
elie222 committed Dec 22, 2024
1 parent b63cc36 commit e67f5c4
Show file tree
Hide file tree
Showing 6 changed files with 482 additions and 313 deletions.
26 changes: 13 additions & 13 deletions apps/web/__tests__/ai-rule-fix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

const result = await aiRuleFix({
incorrectRule: rule,
correctRule: null,
actualRule: rule,
expectedRule: null,
email: salesEmail,
user: getUser(),
});

console.log(result);

expect(result).toBeDefined();
expect(result.rule).toBe("matched_rule");
expect(result.rule).toBe("actual_rule");
expect(result.fixedInstructions).toContain("sales");
expect(result.fixedInstructions).not.toBe(rule.instructions);
// The new instructions should be more specific to exclude sales pitches
Expand All @@ -51,10 +51,10 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

test("should fix rules when email matched wrong rule instead of correct rule", async () => {
const incorrectRule = {
const actualRule = {
instructions: "Match emails about technical support and bug reports",
};
const correctRule = {
const expectedRule = {
instructions: "Match emails about product feedback and feature requests",
};

Expand All @@ -72,8 +72,8 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

const result = await aiRuleFix({
incorrectRule,
correctRule,
actualRule,
expectedRule,
email: feedbackEmail,
user: getUser(),
});
Expand All @@ -90,7 +90,7 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

test("should fix rule when email matched but shouldn't match any rules", async () => {
const incorrectRule = {
const actualRule = {
instructions: "Match emails about marketing collaborations",
};

Expand All @@ -108,16 +108,16 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

const result = await aiRuleFix({
incorrectRule,
correctRule: null,
actualRule,
expectedRule: null,
email: newsletterEmail,
user: getUser(),
});

console.log(result);

expect(result).toBeDefined();
expect(result.rule).toBe("matched_rule");
expect(result.rule).toBe("actual_rule");
expect(result.fixedInstructions).toContain("collaboration");
// The fixed rule should exclude newsletters and automated updates
expect(result.fixedInstructions.toLowerCase()).toMatch(
Expand All @@ -144,8 +144,8 @@ describe.skipIf(!isAiTest)("aiRuleFix", () => {
});

const result = await aiRuleFix({
incorrectRule: null,
correctRule,
actualRule: null,
expectedRule: correctRule,
email: priceRequestEmail,
user: getUser(),
});
Expand Down
Loading

0 comments on commit e67f5c4

Please sign in to comment.