获取预设
提示
请务必先阅读如何正确使用酒馆助手
点击查看对应类型定义文件 (可发给 AI 或 IDE 使用, 酒馆助手界面中提供了打包下载)
getPresetNames
获取预设名称列表
ts
function getPresetNames(): string[];
返回值
- 预设名称列表:
string[]
getLoadedPresetName
获取酒馆正在使用的预设 ('in_use'
) 是从哪个预设加载来的
注意
请务必注意这个说法, 'in_use'
预设虽然是从 getLoadedPresetName()
预设加载而来, 但它的预设内容可能与 getLoadedPresetName()
预设不同.
请回忆一下:
- 在酒馆中编辑预设后, 编辑结果会立即在聊天中生效 (
'in_use'
预设被更改); - 但我们没有点击保存按钮 (将
'in_use'
预设内容保存回getLoadedPresetName()
预设), 一旦切换预设, 编辑结果就会丢失.
ts
function getLoadedPresetName(): string;
返回值
- 预设名称:
string
getPreset
获取 preset_name
预设的内容
ts
function getPreset(preset_name: LiteralUnion<'in_use', string>): Preset | null;
ts
type Preset = {
settings: {
/** 最大上下文 token 数 */
max_context: number;
/** 最大回复 token 数 */
max_completion_tokens: number;
/** 每次生成几个回复 */
reply_count: number;
/** 是否流式传输 */
should_stream: boolean;
/** 温度 */
temperature: number;
/** 频率惩罚 */
frequency_penalty: number;
/** 存在惩罚 */
presence_penalty: number;
top_p: number;
/** 重复惩罚 */
repetition_penalty: number;
min_p: number;
top_k: number;
top_a: number;
/** 种子, -1 表示随机 */
seed: number;
/** 压缩系统消息: 将连续的系统消息合并为一条消息 */
squash_system_messages: boolean;
/** 推理强度, 即内置思维链的投入程度. 例如, 如果酒馆直连 gemini-2.5-flash, 则 `min` 将会不使用内置思维链 */
reasoning_effort: 'auto' | 'min' | 'low' | 'medium' | 'high' | 'max';
/** 请求思维链: 允许模型返回内置思维链的思考过程; 注意这只影响内置思维链显不显示, 不决定模型是否使用内置思维链 */
request_thoughts: boolean;
/** 请求图片: 允许模型在回复中返回图片 */
request_images: boolean;
/** 启用函数调用: 允许模型使用函数调用功能; 比如 cursor 借此在回复中读写文件、运行命令 */
enable_function_calling: boolean;
/** 启用网络搜索: 允许模型使用网络搜索功能 */
enable_web_search: boolean;
/** 是否允许发送图片作为提示词 */
allow_images: 'disabled' | 'auto' | 'low' | 'high';
/** 是否允许发送视频作为提示词 */
allow_videos: boolean;
/**
* 角色名称前缀: 是否要为消息添加角色名称前缀, 以及怎么添加
* - `none`: 不添加
* - `default`: 为与角色卡不同名的消息添加角色名称前缀, 添加到 `content` 字段开头 (即发送的消息内容是 `角色名: 消息内容`)
* - `content`: 为所有消息添加角色名称前缀, 添加到 `content` 字段开头 (即发送的消息内容是 `角色名: 消息内容`)
* - `completion`: 在发送给模型时, 将角色名称写入到 `name` 字段; 仅支持字母数字和下划线, 不适用于 Claude、Google 等模型
*/
character_name_prefix: 'none' | 'default' | 'content' | 'completion';
/** 用引号包裹用户消息: 在发送给模型之前, 将所有用户消息用引号包裹 */
wrap_user_messages_in_quotes: boolean;
};
/** 提示词列表里已经添加的提示词 */
prompts: PresetPrompt[];
/** 下拉框里没添加进来的提示词 */
prompts_unused: PresetPrompt[];
/** 额外字段, 用于为预设绑定额外数据 */
extensions: Record<string, any>;
}
ts
type PresetPrompt = {
/**
* 根据 id, 预设提示词分为以下三类:
* - 普通提示词 (`isPresetNormalPrompt`): 预设界面上可以手动添加的提示词
* - 系统提示词 (`isPresetSystemPrompt`): 酒馆所设置的系统提示词, 但其实相比于手动添加的提示词没有任何优势, 分为 `main`、`nsfw`、`jailbreak`、`enhance_definitions`
* - 占位符提示词 (`isPresetPlaceholderPrompt`): 用于表示世界书条目、角色卡、玩家角色、聊天记录等提示词的插入位置, 分为 `world_info_before`、`persona_description`、`char_description`、`char_personality`、`scenario`、`world_info_after`、`dialogue_examples`、`chat_history`
*/
id: LiteralUnion<
| 'main'
| 'nsfw'
| 'jailbreak'
| 'enhanceDefinitions'
| 'worldInfoBefore'
| 'personaDescription'
| 'charDescription'
| 'charPersonality'
| 'scenario'
| 'worldInfoAfter'
| 'dialogueExamples'
| 'chatHistory',
string
>;
name: string;
enabled: boolean;
/**
* 插入位置, 仅用于普通和占位符提示词
* - `'relative'`: 按提示词相对位置插入
* - `'in_chat'`: 插入到聊天记录的对应深度, 需要设置对应的深度 `depth` 和顺序 `order`
*/
position:
| {
type: 'relative';
depth?: never;
order?: never;
}
| { type: 'in_chat'; depth: number; order: number };
role: 'system' | 'user' | 'assistant';
/** 仅用于普通和系统提示词 */
content?: string;
/** 额外字段, 用于为预设提示词绑定额外数据 */
extra?: Record<string, any>;
};
type PresetNormalPrompt = SetRequired<{ id: string } & Omit<PresetPrompt, 'id'>, 'position' | 'content'>;
type PresetSystemPrompt = SetRequired<
{ id: 'main' | 'nsfw' | 'jailbreak' | 'enhanceDefinitions' } & Omit<PresetPrompt, 'id'>,
'content'
>;
type PresetPlaceholderPrompt = SetRequired<
{
id:
| 'worldInfoBefore'
| 'personaDescription'
| 'charDescription'
| 'charPersonality'
| 'scenario'
| 'worldInfoAfter'
| 'dialogueExamples'
| 'chatHistory';
} & Omit<PresetPrompt, 'id'>,
'position'
>;
declare function isPresetNormalPrompt(prompt: PresetPrompt): prompt is PresetNormalPrompt;
declare function isPresetSystemPrompt(prompt: PresetPrompt): prompt is PresetSystemPrompt;
declare function isPresetPlaceholderPrompt(prompt: PresetPrompt): prompt is PresetPlaceholderPrompt;
ts
const default_preset: Preset = {
settings: {
max_context: 2000000,
max_completion_tokens: 300,
reply_count: 1,
should_stream: false,
temperature: 1,
frequency_penalty: 0,
presence_penalty: 0,
repetition_penalty: 1,
top_p: 1,
min_p: 0,
top_k: 0,
top_a: 0,
seed: -1,
squash_system_messages: false,
reasoning_effort: "auto",
request_thoughts: false,
request_images: false,
enable_function_calling: false,
enable_web_search: false,
allow_sending_images: "disabled",
allow_sending_videos: false,
character_name_prefix: "none",
wrap_user_messages_in_quotes: false,
},
prompts: [
{
id: "worldInfoBefore",
enabled: true,
position: "relative",
role: "system",
},
{
id: "personaDescription",
enabled: true,
position: "relative",
role: "system",
},
{
id: "charDescription",
enabled: true,
position: "relative",
role: "system",
},
{
id: "charPersonality",
enabled: true,
position: "relative",
role: "system",
},
{ id: "scenario", enabled: true, position: "relative", role: "system" },
{
id: "worldInfoAfter",
enabled: true,
position: "relative",
role: "system",
},
{
id: "dialogueExamples",
enabled: true,
position: "relative",
role: "system",
},
{ id: "chatHistory", enabled: true, position: "relative", role: "system" },
],
prompts_unused: [],
extensions: {},
} as const;
参数
preset_name
- 类型:
string
- 描述: 预设名称
返回值
- 预设内容:
Preset
|null
isPresetNormalPrompt
判断 prompt
是否为普通提示词 (预设界面上可以手动添加的提示词)
ts
function isPresetNormalPrompt(prompt: PresetPrompt): prompt is PresetNormalPrompt;
参数
prompt
- 类型:
PresetPrompt
返回值
- 是否为普通提示词:
boolean
isPresetSystemPrompt
判断 prompt
是否为系统提示词 (酒馆所设置的系统提示词, 但其实相比于手动添加的提示词没有任何优势, 分为 main
、nsfw
、jailbreak
、enhance_definitions
)
ts
function isPresetSystemPrompt(prompt: PresetPrompt): prompt is PresetSystemPrompt;
参数
prompt
- 类型:
PresetPrompt
返回值
- 是否为系统提示词:
boolean
isPresetPlaceholderPrompt
判断 prompt
是否为占位符提示词 (用于表示世界书条目、角色卡、玩家角色、聊天记录等提示词的插入位置, 分为 world_info_before
、persona_description
、char_description
、char_personality
、scenario
、world_info_after
、dialogue_examples
、chat_history
)
ts
function isPresetPlaceholderPrompt(prompt: PresetPrompt): prompt is PresetPlaceholderPrompt;
参数
prompt
- 类型:
PresetPrompt
返回值
- 是否为占位符提示词:
boolean