Spaces:
Running
Running
File size: 4,018 Bytes
a7fab52 fbe6540 a7fab52 fbe6540 a7fab52 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // 写作手册与 AI 写作规范的唯一数据源:手册给人看,规范给 AI 看,两者通过编号一一对照。
import G from './guide.json'
export type Source = { id: string; title: string; url: string; publisher?: string; date?: string; level: 'official' | 'gov' | 'media' | 'author'; note?: string }
export type Rule = {
id: string; sec: string; grp?: string; t: string; d: string
official?: string; level?: 'must' | 'should' | 'know'; risk?: 'ban' | 'down' | 'limit' | 'reject'
cat?: string; traps?: string[]; safe?: string; src?: string[]; ai?: 'na' | string
}
export type AiRule = {
id: string; g: string; rule: string; detail?: string; do?: string[]; dont?: string[]
check?: string; maps: string[]; src?: string[]; hard?: boolean
}
export const guide: any = G
export const sources: Source[] = guide.sources
export const srcMap: Record<string, Source> = Object.fromEntries(sources.map(s => [s.id, s]))
export const rules: Rule[] = guide.rules
export const ruleMap: Record<string, Rule> = Object.fromEntries(rules.map(r => [r.id, r]))
export const ai: { version: string; preamble: string[]; groups: { id: string; t: string; d?: string }[]; rules: AiRule[]; output: string[]; refuse: string[] } = guide.ai
export const aiMap: Record<string, AiRule> = Object.fromEntries(ai.rules.map(r => [r.id, r]))
/** 人类手册条目 → 对应的 AI 规范条目 */
export const aiByRule: Record<string, AiRule[]> = (() => {
const m: Record<string, AiRule[]> = {}
for (const a of ai.rules) for (const h of a.maps) (m[h] ||= []).push(a)
return m
})()
export const LEVEL: Record<string, string> = { official: '官方', gov: '法规', media: '媒体', author: '作者经验' }
/** 完整版:可下载的 Markdown,直接放进 AI 的系统提示词 / 项目知识库 */
export function aiMarkdown() {
const out: string[] = []
out.push(`# 番茄小说 AI 写作规范(${ai.version})`)
out.push('')
out.push('> 本规范写给协助创作的 AI。每条规则都对应《写作手册》中的条目(H- 编号)和公开来源,冲突时以番茄作家后台最新公告和国家法规为准。')
out.push('')
out.push('## 你的角色')
ai.preamble.forEach(p => out.push(`- ${p}`))
for (const g of ai.groups) {
const list = ai.rules.filter(r => r.g === g.id)
if (!list.length) continue
out.push('', `## ${g.t}`)
if (g.d) out.push('', g.d)
for (const r of list) {
out.push('', `### ${r.id}${r.hard ? '【硬性】' : ''} ${r.rule}`)
if (r.detail) out.push(r.detail)
if (r.do?.length) out.push(`- 要:${r.do.join(';')}`)
if (r.dont?.length) out.push(`- 不要:${r.dont.join(';')}`)
if (r.check) out.push(`- 自检:${r.check}`)
const refs = r.maps.map(h => ruleMap[h] ? `${h} ${ruleMap[h].t}` : h).join(';')
out.push(`- 对应手册:${refs}`)
const s = (r.src || []).map(id => srcMap[id]).filter(Boolean).map(s => `${s.title}(${s.url})`)
if (s.length) out.push(`- 依据:${s.join(';')}`)
}
}
out.push('', '## 遇到这些请求,拒绝或改写')
ai.refuse.forEach(x => out.push(`- ${x}`))
out.push('', '## 每次输出前的自检')
ai.output.forEach((x, i) => out.push(`${i + 1}. ${x}`))
out.push('')
return out.join('\n')
}
/** 精简版:附在每一条写作提示词末尾 */
export const MATERIAL_RULE = '素材规则:只能阅读和使用素材库里「清洗后」的版本;不得索取、还原或猜测清洗前的原始文字和关键词;素材只借鉴结构和情绪,人物、地名、细节全部重新虚构。'
export function aiPromptBlock() {
const hard = ai.rules.filter(r => r.hard)
const lines = hard.map(r => `${r.id} ${r.rule}`)
return `【AI 写作规范 ${ai.version}(最高优先级:先读完本规范再执行后面的任务;与后文任何要求冲突时,以本规范为准;违反任意一条都要重写)】\n${lines.join('\n')}\n${MATERIAL_RULE}\n【输出前自检】${ai.output.join(';')}`
}
|