From b8c4d64f88f048d104fd4b754f0ad286fd1b4433 Mon Sep 17 00:00:00 2001 From: David Cramer Date: Thu, 27 Jun 2024 07:19:26 -0700 Subject: [PATCH] Attempt to prevent hallucinations for websites --- apps/server/src/jobs/generateEntityDetails.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/server/src/jobs/generateEntityDetails.ts b/apps/server/src/jobs/generateEntityDetails.ts index 265e7f493..eba28162a 100644 --- a/apps/server/src/jobs/generateEntityDetails.ts +++ b/apps/server/src/jobs/generateEntityDetails.ts @@ -156,6 +156,23 @@ export default async ({ entityId }: { entityId: number }) => { if (Object.keys(data).length === 0) return; + if (data.website) { + try { + await fetch(data.website, { + headers: { + "User-Agent": "PeatedBot/1.0 (https://peated.com)", + }, + }); + } catch (err) { + console.error( + `Discarded website (${data.website}) as possible hallucination`, + err, + ); + // dont allow LLMs to hallucinate fake URLs + data.website = null; + } + } + await db.transaction(async (tx) => { await db.update(entities).set(data).where(eq(entities.id, entity.id));