Skip to content

Commit

Permalink
fix: potential ai hallucination with opportunity refinement ❗️ (color…
Browse files Browse the repository at this point in the history
  • Loading branch information
ramiAbdou authored Dec 21, 2024
1 parent 988b84a commit 72ccc8f
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/core/src/modules/opportunities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,10 @@ const REFINE_OPPORTUNITY_PROMPT = dedent`
Follow these guidelines:
- If you cannot confidently infer a field, set it to null.
- If the page is not found, expired, or otherwise not a valid opportunity,
set all fields to null.
- Double check that your output is based on the website content. Don't make
up information that you cannot confidently infer from the website content.
Your output should be a single JSON object containing these fields. Do not
provide any explanation or text outside of the JSON object. Ensure your JSON
Expand All @@ -469,20 +473,20 @@ const REFINE_OPPORTUNITY_PROMPT = dedent`
<output>
{
"company": "string | null",
"description": "string",
"description": "string | null",
"expiresAt": "string | null",
"tags": "string[]",
"title": "string"
"tags": "string[] | null",
"title": "string | null"
}
</output>
`;

const RefineOpportunityResponse = z.object({
company: z.string().trim().min(1).nullable(),
description: z.string().trim().min(1).max(500),
description: z.string().trim().min(1).max(500).nullable(),
expiresAt: z.string().nullable(),
tags: z.array(z.string().trim().min(1)).min(1),
title: z.string().trim().min(1).max(100),
tags: z.array(z.string().trim().min(1)).min(1).nullable(),
title: z.string().trim().min(1).max(100).nullable(),
});

type RefineOpportunityResponse = z.infer<typeof RefineOpportunityResponse>;
Expand Down Expand Up @@ -569,10 +573,10 @@ export async function refineOpportunity(
const opportunity = await trx
.updateTable('opportunities')
.set({
...(data.description && { description: data.description }),
...(data.title && { title: data.title }),
companyId,
description: data.description,
expiresAt,
title: data.title,
})
.where('id', '=', input.opportunityId)
.returning(['id', 'refinedAt', 'slackChannelId', 'slackMessageId'])
Expand All @@ -587,6 +591,10 @@ export async function refineOpportunity(
.where('refinedAt', 'is', null)
.executeTakeFirst();

if (!data.tags) {
return opportunity;
}

const upsertedTags = await trx
.insertInto('opportunityTags')
.values(
Expand Down

0 comments on commit 72ccc8f

Please sign in to comment.