Skip to content

Commit

Permalink
feature(inference): Improve ollama tagging (#162)
Browse files Browse the repository at this point in the history
* Inference Failed with Ollama #20
Changed the prompt to be split in 2, so ollama does not forget them

* Update apps/workers/openaiWorker.ts

Co-authored-by: Mohamed Bassem <me@mbassem.com>

---------

Co-authored-by: kamtschatka <simon.schatka@gmx.at>
Co-authored-by: Mohamed Bassem <me@mbassem.com>
  • Loading branch information
3 people authored May 18, 2024
1 parent eb218ce commit fdc27d3
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions apps/workers/openaiWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,17 @@ with the key "tags" and the value is list of tags. Don't wrap the response in a

const TEXT_PROMPT_BASE = `
I'm building a read-it-later app and I need your help with automatic tagging.
Please analyze the text after the sentence "CONTENT START HERE:" and suggest relevant tags that describe its key themes, topics, and main ideas.
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.
Aim for a variety of tags, including broad categories, specific keywords, and potential sub-genres. The tags language must be ${serverConfig.inference.inferredTagLang}. 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. Aim for 3-5 tags. If there are no good tags, don't emit any.
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.
You must respond in JSON with the key "tags" and the value is list of tags.
CONTENT START HERE:
CONTENT START HERE
`;

const TEXT_PROMPT_INSTRUCTIONS = `
CONTENT END HERE
You must respond in JSON with the key "tags" and the value is an array of string tags.
Aim for 3-5 tags. If there are no good tags, leave the array empty.
`;

function buildPrompt(
Expand All @@ -125,7 +130,7 @@ URL: ${bookmark.link.url}
Title: ${bookmark.link.title ?? ""}
Description: ${bookmark.link.description ?? ""}
Content: ${content ?? ""}
`;
${TEXT_PROMPT_INSTRUCTIONS}`;
}

if (bookmark.text) {
Expand All @@ -134,6 +139,7 @@ Content: ${content ?? ""}
return `
${TEXT_PROMPT_BASE}
${content}
${TEXT_PROMPT_INSTRUCTIONS}
`;
}

Expand Down Expand Up @@ -205,6 +211,7 @@ async function inferTagsFromPDF(

const prompt = `${TEXT_PROMPT_BASE}
Content: ${truncateContent(pdfParse.text)}
${TEXT_PROMPT_INSTRUCTIONS}
`;
return inferenceClient.inferFromText(prompt);
}
Expand Down

0 comments on commit fdc27d3

Please sign in to comment.