feat(llm 對話): 新增 prompt builder 與 few-shot 範例組裝,強化 Claude 對話品質
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user