Files
Kokorone/apps/api/src/llm/few-shot-examples.ts
T

31 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { EmotionTag } from "@kokorone/shared";
import { pickTemplates } from "./template-library.js";
export interface FewShotExample {
emotionTag: EmotionTag;
tier: "low" | "high";
userInput: string;
response: string;
}
const SAMPLE_USER_INPUT: Record<"low" | "high", string> = {
low: "今天天氣真好呢。",
high: "謝謝你,我今天好開心!",
};
const SAMPLE_EMOTIONS: EmotionTag[] = ["CALM", "JOY", "SAD", "ALERT", "SHY", "GRUMPY"];
// R-3:F-7 的 Mock 模板庫在真實 Provider 這邊轉為 few-shot 範例——同一份模板資料,
// 從「隨機挑一句直接當回應」變成「示範這個性格原型在各種情緒下該有的語氣」。
export function buildFewShotExamples(personalityArchetype: string): FewShotExample[] {
const examples: FewShotExample[] = [];
for (const tier of ["low", "high"] as const) {
for (const emotionTag of SAMPLE_EMOTIONS) {
const candidates = pickTemplates(personalityArchetype, emotionTag, tier);
if (candidates.length === 0) continue;
examples.push({ emotionTag, tier, userInput: SAMPLE_USER_INPUT[tier], response: candidates[0] });
}
}
return examples;
}