Spaces:
Running
Running
File size: 1,952 Bytes
98b1c51 1e5090f ddbe7d2 9960338 98b1c51 d779ad0 bf15962 1e5090f 9db8ced 1e5090f 86bc2ea 9db8ced 1e5090f ddbe7d2 1e5090f 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 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import { env } from "$env/dynamic/private";
import { generateFromDefaultEndpoint } from "$lib/server/generateFromDefaultEndpoint";
import type { Message } from "$lib/types/Message";
import { logger } from "$lib/server/logger";
export async function summarize(prompt: string) {
if (!env.LLM_SUMMERIZATION) {
return prompt.split(/\s+/g).slice(0, 5).join(" ");
}
const messages: Array<Omit<Message, "id">> = [
{ from: "user", content: "Who is the president of Gabon?" },
{ from: "assistant", content: "π¬π¦ President of Gabon" },
{ from: "user", content: "Who is Julien Chaumond?" },
{ from: "assistant", content: "π§ Julien Chaumond" },
{ from: "user", content: "what is 1 + 1?" },
{ from: "assistant", content: "π’ Simple math operation" },
{ from: "user", content: "What are the latest news?" },
{ from: "assistant", content: "π° Latest news" },
{ from: "user", content: "How to make a great cheesecake?" },
{ from: "assistant", content: "π° Cheesecake recipe" },
{ from: "user", content: "what is your favorite movie? do a short answer." },
{ from: "assistant", content: "π₯ Favorite movie" },
{ from: "user", content: "Explain the concept of artificial intelligence in one sentence" },
{ from: "assistant", content: "π€ AI definition" },
{ from: "user", content: prompt },
];
return await generateFromDefaultEndpoint({
messages,
preprompt:
"You are a summarization AI. Summarize the user's request into a single short sentence of four words or less. Do not try to answer it, only summarize the user's query. Always start your answer with an emoji relevant to the summary",
generateSettings: {
max_new_tokens: 15,
},
})
.then((summary) => {
// add an emoji if none is found in the first three characters
if (!/\p{Emoji}/u.test(summary.slice(0, 3))) {
return "π¬ " + summary;
}
return summary;
})
.catch((e) => {
logger.error(e);
return null;
});
}
|