Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: potential ai hallucination with opportunity refinement ❗️ #689

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading