Skip to content

Commit

Permalink
feature: Improve the LLM prompts for tag generation
Browse files Browse the repository at this point in the history
This new prompt works well in gpt-4o-mini and llama3.1-8b.
  • Loading branch information
Papierkorb committed Oct 8, 2024
1 parent 09e0659 commit 567e63d
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions packages/shared/prompts.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
export function buildImagePrompt(lang: string, customPrompts: string[]) {
return `
You are a bot in a read-it-later app and your responsibility is to help with automatic tagging.
Please analyze the attached image and suggest relevant tags that describe its key themes, topics, and main ideas. The rules are:
You're an expert image tagger. Given an input you generate an JSON object of the following format: { "tags": ["First tag", "Another tag", ...] }
Only respond in this format! Write only the JSON data and nothing else. Do not write an explanation.
- Suggest relevant tags that describe its key themes, topics, and main ideas.
- Aim for a variety of tags, including broad categories, specific keywords, and potential sub-genres.
- The tags language must be in ${lang}.
- If the tag is not generic enough, don't include it.
- Aim for 10-15 tags.
- If there are no good tags, don't emit any.
${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
You must respond in valid JSON with the key "tags" and the value is list of tags. Don't wrap the response in a markdown code.`;
- If you can't find tags you're satisfied with respond with an empty tags array.
${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}`;
}

export function buildTextPrompt(
Expand All @@ -17,17 +19,14 @@ export function buildTextPrompt(
content: string,
) {
return `
You are a bot in a read-it-later app and your responsibility is to help with automatic tagging.
Please analyze the text between the sentences "CONTENT START HERE" and "CONTENT END HERE" and suggest relevant tags that describe its key themes, topics, and main ideas. The rules are:
- Aim for a variety of tags, including broad categories, specific keywords, and potential sub-genres.
- The tags language must be in ${lang}.
- If it's a famous website you may also include a tag for the website. If the tag is not generic enough, don't include it.
- The content can include text for cookie consent and privacy policy, ignore those while tagging.
- Aim for 3-5 tags.
- If there are no good tags, leave the array empty.
You're an expert document tagger. Given an input you generate an JSON object of the following format: { "tags": ["First tag", "Another tag", ...] }
Only respond in this format! Write only the JSON data and nothing else. Do not write an explanation.
- If you can't find tags you're satisfied with respond with an empty tags array.
- Write at most five tags.
- Write your tags in ${lang}.
${customPrompts && customPrompts.map((p) => `- ${p}`).join("\n")}
CONTENT START HERE
${content}
CONTENT END HERE
You must respond in JSON with the key "tags" and the value is an array of string tags.`;
${content}`;
}

0 comments on commit 567e63d

Please sign in to comment.