Skip to content

Commit

Permalink
feat(contact-details): test for hallucinations
Browse files Browse the repository at this point in the history
  • Loading branch information
foxt451 committed Jan 13, 2024
1 parent 3849860 commit f558630
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/contact-scraper/test/contacts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,19 @@ type DetailsSpec = {
[key in keyof typeof JSON_SCHEMA['properties']]?: string[];
}

const testWholeWebsiteDetails = (jsonAnswer: any, expectedWebsiteDetails: DetailsSpec) => {
const testWholeWebsiteDetails = (jsonAnswer: any, expectedWebsiteDetails: DetailsSpec, pageContent: string) => {
for (const [key, urls] of Object.entries(expectedWebsiteDetails)) {
testURLInclusion(key as keyof typeof JSON_SCHEMA['properties'], urls as string[], jsonAnswer);
}
for (const [, items] of Object.entries(jsonAnswer) as [
string,
{ item: string, description: string }[],
][]) {
for (const item of items) {
// avoid hallucinations by ensuring that every returned item is in the page content
expect(pageContent).toContain(item.item);
}
}
};

const testWebsite = async (url: string, spec: DetailsSpec) => {
Expand All @@ -75,7 +84,7 @@ const testWebsite = async (url: string, spec: DetailsSpec) => {
});
const { jsonAnswer } = answerResult;
expect(jsonAnswer).not.toBeNull();
testWholeWebsiteDetails(jsonAnswer, spec);
testWholeWebsiteDetails(jsonAnswer, spec, pageContent);
};

test('Scrapes contacts from https://unbounce.com/contact-us/', async () => testWebsite('https://unbounce.com/contact-us/', {
Expand Down

0 comments on commit f558630

Please sign in to comment.