File size: 1,140 Bytes
9960338 bf15962 9960338 0134fe1 9960338 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import { buildPrompt } from "$lib/buildPrompt";
import { generateFromDefaultEndpoint } from "$lib/server/generateFromDefaultEndpoint";
import { defaultModel } from "$lib/server/models";
export async function summarize(prompt: string) {
const userPrompt = `Please summarize the following message: \n` + prompt;
const summaryPrompt = await buildPrompt({
messages: [{ from: "user", content: userPrompt }],
preprompt: `
You are a summarization AI. Your task is to summarize user requests, in a single sentence of less than 5 words. Do not try to answer questions, just summarize the user's request. Start your answer with an emoji relevant to the summary."
Example: "Who is the president of France ?"
Summary: "🇫🇷 President of France request"
Example: "What are the latest news ?"
Summary: "📰 Latest news"
Example: "Can you debug this python code?"
Summary: "🐍 Python code debugging request"
`,
model: defaultModel,
});
const generated_text = await generateFromDefaultEndpoint(summaryPrompt).catch((e) => {
console.error(e);
return null;
});
if (generated_text) {
return generated_text;
}
return null;
}
|