build_pack.py 產生對白索引(放在使用者資料目錄);render_skill.py 把人格卡渲染成 角色 skill 並檢查精選對白逐字來自索引;插件改成執行期從資料目錄讀索引。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { CHARACTERS, type CharacterCode } from './characters'
|
|
import { classify, type Complete } from './classify'
|
|
import type { Config } from './config'
|
|
import { formatExamples } from './examples'
|
|
import { retrieve, type IndexEntry } from './retrieval'
|
|
|
|
export type InjectDeps = {
|
|
config: Config
|
|
loadIndex: (character: CharacterCode) => Promise<readonly IndexEntry[]>
|
|
complete: Complete
|
|
append: (text: string) => Promise<unknown>
|
|
now: () => number
|
|
turn: number
|
|
}
|
|
|
|
// 回傳 null 表示這一輪不注入(沒選角色、強度 0、索引為空、分類失敗或沒有同標籤的對白)。
|
|
// 索引為空時不呼叫模型,省下一次無用的分類。
|
|
export async function buildInjection(
|
|
{ config, loadIndex, complete, now, turn }: Omit<InjectDeps, 'append'>,
|
|
userText: string,
|
|
): Promise<{ text: string | null; fn: string | null; ms: number } | null> {
|
|
const character = config.character
|
|
if (character === null || config.intensity === 0) return null
|
|
const index = await loadIndex(character)
|
|
if (index.length === 0) return null
|
|
const started = now()
|
|
const fn = await classify(complete, userText)
|
|
const ms = now() - started
|
|
if (fn === null) return { text: null, fn: null, ms }
|
|
return { text: formatExamples(CHARACTERS[character].name, retrieve(index, fn, { turn })), fn, ms }
|
|
}
|