feat: W7 功能標籤分類、對白檢索與注入 (#8)
用 $.model.complete(Haiku)判斷回應的功能標籤,從角色索引取同標籤對白, 以只增不改的訊息附在使用者訊息之前;失敗一律退回不注入。 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
1c4e0c5d98
commit
d9e50d196b
@@ -0,0 +1,31 @@
|
||||
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
|
||||
indexes: Readonly<Record<CharacterCode, readonly IndexEntry[]>>
|
||||
complete: Complete
|
||||
append: (text: string) => Promise<unknown>
|
||||
now: () => number
|
||||
turn: number
|
||||
}
|
||||
|
||||
// 回傳 null 表示這一輪不注入(沒選角色、強度 0、索引為空、分類失敗或沒有同標籤的對白)。
|
||||
// 索引為空時不呼叫模型,省下一次無用的分類。
|
||||
export async function buildInjection(
|
||||
{ config, indexes, 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 = indexes[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 }
|
||||
}
|
||||
Reference in New Issue
Block a user