Skip to content

获取世界书

提示

请务必先阅读如何正确使用酒馆助手

点击查看对应类型定义文件 (可发给 AI 或 IDE 使用, 酒馆助手界面中提供了打包下载)

getWorldbook

获取 worldbook_name 世界书的内容

ts
function getWorldbook(worldbook_name: string): Promise<WorldbookEntry[]>;
ts
type WorldbookEntry = {
  /** uid 是相对于世界书内部的, 不要跨世界书使用 */
  uid: number;
  name: string;
  enabled: boolean;

  strategy: {
    /**
     * - `'constant'`: 常量🔵, 俗称蓝灯. 只需要满足 "启用"、"激活概率%" 等别的要求即可.
     * - `'selective'`: 可选项🟢, 俗称绿灯. 除了蓝灯条件, 还需要满足 `keys` 扫描条件
     * - `'vectorized'`: 向量化🔗. 一般不使用
     */
    type: 'constant' | 'selective' | 'vectorized';
    /** 主要关键字. 绿灯条目必须在欲扫描文本中扫描到其中任意一个关键字才能激活 */
    keys: (string | RegExp)[];
    /**
     * 次要关键字. 如果数组不为空, 则条目除了在主要关键字中匹配到任意一个关键字外, 还需要满足:
     * - `'and_any'`: 次要关键字中任意一个关键字能在欲扫描文本中匹配到
     * - `'and_all'`: 次要关键字中所有关键字都能在欲扫描文本中匹配到
     * - `'not_all'`: 次要关键字中至少有一个关键字没能在欲扫描文本中匹配到
     * - `'not_any'`: 次要关键字中所有关键字都没能欲扫描文本中匹配到
     */
    keys_secondary: { logic: 'and_any' | 'and_all' | 'not_all' | 'not_any'; keys: (string | RegExp)[] };
    /** 扫描深度: 1 为仅扫描最后一个楼层, 2 为扫描最后两个楼层, 以此类推 */
    scan_depth: 'same_as_global' | number;
  };
  position: {
    /**
     * 位置类型:
     * - `'before_character_definition'`: 角色定义之前
     * - `'after_character_definition'`: 角色定义之后
     * - `'before_example_messages'`: 示例消息之前
     * - `'after_example_messages'`: 示例消息之后
     * - `'before_author_note'`: 作者注释之前
     * - `'after_author_note'`: 作者注释之后
     * - `'at_depth'`: 插入到指定深度
     */
    type:
      | 'before_character_definition'
      | 'after_character_definition'
      | 'before_example_messages'
      | 'after_example_messages'
      | 'before_author_note'
      | 'after_author_note'
      | 'at_depth';
    /** 该条目的消息身份, 仅位置类型为 `'at_depth'` 时有效 */
    role: 'system' | 'assistant' | 'user';
    /** 该条目要插入的深度, 仅位置类型为 `'at_depth'` 时有效 */
    depth: number;
    // TODO: 世界书条目的插入: 文档链接
    order: number;
  };

  content: string;

  probability: number;
  recursion: {
    /** 禁止其他条目递归激活本条目 */
    prevent_incoming: boolean;
    /** 禁止本条目递归激活其他条目 */
    prevent_outgoing: boolean;
    /** 延迟到第 n 级递归检查时才能激活本条目 */
    delay_until: null | number;
  };
  effect: {
    /** 黏性: 条目激活后, 在之后 `n` 条消息内始终激活, 无视激活策略、激活概率% */
    sticky: null | number;
    /** 冷却: 条目激活后, 在之后 `n` 条消息内不能再激活*/
    cooldown: null | number;
    /** 延迟: 聊天中至少有 `1` 楼消息时, 才能激活条目 */
    delay: null | number;
  };

  extra?: Record<string, any>;
};

参数

worldbook_name

  • 类型: string
  • 描述: 世界书名称

返回值

getWorldbookNames

获取世界书名称列表

ts
function getWorldbookNames(): string[];

返回值

  • 世界书名称列表: string[]

getGlobalWorldbookNames

获取当前全局开启的世界书名称列表

ts
function getGlobalWorldbookNames(): string[];

返回值

  • 全局开启的世界书名称列表: string[]

getCharWorldbookNames

获取角色卡绑定的世界书

ts
function getCharWorldbookNames(character_name: LiteralUnion<'current' | string>): CharWorldbooks;
ts
type CharWorldbooks = {
  primary: string | null;
  additional: string[];
}

参数

character_name

  • 类型: 'current' | string
  • 描述: 角色卡名称, 'current' 表示当前打开的角色卡

返回值

getChatWorldbookName

获取聊天文件绑定的世界书

ts
function getChatWorldbookName(chat_name: 'current'): string | null;

参数

chat_name

  • 类型: 'current' | string
  • 描述: 聊天文件名称, 'current' 表示当前打开的聊天文件

返回值

  • 聊天文件绑定的世界书: string | null

getOrCreateChatWorldbook

获取或新建聊天文件世界书

ts
function getOrCreateChatWorldbook(chat_name: 'current', worldbook_name?: string): Promise<string>;

参数

chat_name

  • 类型: 'current' | string
  • 描述: 聊天文件名称, 'current' 表示当前打开的聊天文件

worldbook_name

  • 类型: string
  • 描述: 世界书名称; 不填则根据当前时间创建

返回值

  • 聊天文件绑定的世界书: string

作者:KAKAA, 青空莉想做舞台少女的狗