Skip to content

Commit

Permalink
Feed GTP existing knowledge to improve outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Dec 18, 2023
1 parent 57ba5e4 commit 7c570b0
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
24 changes: 20 additions & 4 deletions apps/worker/src/jobs/generateBottleDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,28 @@ if (!config.OPENAI_API_KEY) {
console.warn("OPENAI_API_KEY is not configured.");
}

function generatePrompt(bottleName: string) {
function generatePrompt(bottle: Bottle) {
const infoLines = [];
if (bottle.category) {
infoLines.push(`Category: ${bottle.category}`);
}
if (bottle.statedAge) {
infoLines.push(`Stated Age: ${bottle.statedAge}`);
}

return `
Pretend to be an expert in whiskey distillation. Tell me about the following whiskey:
You are an expert in whiskey. Your job is to accurately describe information about the whiskey industry.
${bottleName}
Tell me about the following bottle of whiskey:
${bottle.fullName}
${
infoLines.length
? `\nOther information we already know about this bottle:\n- ${infoLines.join(
"\n- ",
)}\n`
: ""
}
If the whiskey is made in Scotland, it is always spelled "whisky".
'description' should focus on what is unique about this whiskey. It should not include the tasting notes. It should be less than 200 words, and structured as paragraphs with prose.
Expand Down Expand Up @@ -79,7 +95,7 @@ async function generateBottleDetails(bottle: Bottle): Promise<Response | null> {
if (!config.OPENAI_API_KEY) return null;

const result = await getStructuredResponse(
generatePrompt(bottle.fullName),
generatePrompt(bottle),
OpenAIBottleDetailsSchema,
OpenAIBottleDetailsValidationSchema,
undefined,
Expand Down
34 changes: 29 additions & 5 deletions apps/worker/src/jobs/generateEntityDetails.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,37 @@ if (!config.OPENAI_API_KEY) {
console.warn("OPENAI_API_KEY is not configured.");
}

function generatePrompt(entityName: string) {
function generatePrompt(entity: Entity) {
const infoLines = [];
if (entity.country && entity.region) {
infoLines.push(`Origin: ${entity.region}, ${entity.country}`);
} else if (entity.country) {
infoLines.push(`Origin: ${entity.country}`);
}
if (entity.yearEstablished) {
infoLines.push(`Year Established: ${entity.yearEstablished}`);
}
if (entity.website) {
infoLines.push(`Website: ${entity.website}`);
}
if (entity.type) {
infoLines.push(`Entity Types: ${entity.type.join(", ")}`);
}

return `
Pretend to be an expert in whiskey distillation. Tell me about the following entity:
You are an expert in whiskey. Your job is to accurately describe information about the whiskey industry.
${entityName}
Tell me about the following whiskey brand:
If the entity is located in Scotland, spell wihskey as "whisky".
${entity.name}
${
infoLines.length
? `\nOther information we already know about this entity:\n- ${infoLines.join(
"\n- ",
)}\n`
: ""
}
If the entity is located in Scotland, spell whiskey as "whisky".
Describe the entity as a distiller, bottler, or brand, whichever one it primarily is. Do not describe it as a "entity".
Expand Down Expand Up @@ -70,7 +94,7 @@ async function generateEntityDetails(entity: Entity): Promise<Response | null> {
if (!config.OPENAI_API_KEY) return null;

const result = await getStructuredResponse(
generatePrompt(entity.name),
generatePrompt(entity),
OpenAIBottleDetailsSchema,
OpenAIBottleDetailsValidationSchema,
undefined,
Expand Down

0 comments on commit 7c570b0

Please sign in to comment.