File size: 765 Bytes
e67ab0e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { generateFromDefaultEndpoint } from "$lib/server/generateFromDefaultEndpoint";
import { MessageUpdateType } from "$lib/types/MessageUpdate";

export async function generateSummaryOfReasoning(
	reasoning: string,
	modelId: string | undefined,
	locals: App.Locals | undefined
): Promise<string> {
	const prompt = `Summarize concisely the following reasoning for the user. Keep it short (one short paragraph).\n\n${reasoning}`;
	const summary = await (async () => {
		const it = generateFromDefaultEndpoint({
			messages: [{ from: "user", content: prompt }],
			modelId,
			locals,
		});
		let out = "";
		for await (const update of it) {
			if (update.type === MessageUpdateType.Stream) out += update.token;
		}
		return out;
	})();
	return summary.trim();
}