feat(ai): 打通 SEO 闭环与投稿写作辅助

对齐 Zibll 的 AI 生成 SEO 流程:统一 WP AI Client/主题 Provider 双后端、文章/分类 SEO 框与生成回填、投稿摘要/标签建议,并收敛扩展页为连接配置。
This commit is contained in:
kate522 committed 2026-07-12 15:36:04 +08:00
1 parent a4cd5276e2
commit b36186da65
14 files changed
+1243 -330

No files matched your search

+70 -29
View File
@@ -2,8 +2,6 @@
/**
* AKSRT AI Prompt — AI Prompt 模板管理
*
* 管理各种 AI 功能的 prompt 模板。
*
* @package AKSRT
*/
@@ -21,27 +19,71 @@ class AKSRT_AI_Prompt {
}
/**
* 构建 SEO 建议 prompt
*
* 优先读取后台 ai_seo_*_prompt 设置,为空则使用内置默认提示词。
* SEO 标题 system instruction(Zibll 默认长提示词)。
*/
public function build_seo_prompt(string $title, string $content): string {
// 读取后台自定义提示词
$custom_title = '';
$custom_kw = '';
$custom_desc = '';
if (class_exists('AKSRT_Settings')) {
$s = AKSRT_Settings::get_all();
$custom_title = trim((string) ($s['ai_seo_title_prompt'] ?? ''));
$custom_kw = trim((string) ($s['ai_seo_keywords_prompt'] ?? ''));
$custom_desc = trim((string) ($s['ai_seo_description_prompt'] ?? ''));
public function get_seo_title_system_instruction(): string {
$custom = $this->read_custom_prompt('ai_seo_title_prompt');
if ($custom !== '') {
return $custom;
}
// 内置默认提示词(zibll 风格长提示词)
$title_instruction = $custom_title ?: '请为文章生成一个 SEO 友好的标题,要求:包含核心关键词,控制在 60 个字符以内,语言自然流畅,吸引用户点击。';
$kw_instruction = $custom_kw ?: '请为文章提取 5-8 个 SEO 关键词,要求:涵盖核心主题词和长尾词,按搜索热度排序,用英文逗号分隔。';
$desc_instruction = $custom_desc ?: '请为文章生成一段 SEO 描述(meta description),要求:160 个字符以内,准确概括文章内容,包含核心关键词,具有吸引力能促进点击。';
return '你是一名资深的网站 SEO 编辑,擅长撰写既符合搜索习惯又具备点击力的文章标题。
请严格遵循以下规则:
1. 输出 1 条最佳标题,作为该文章的 <title>。
2. 字数控制在 20 至 40 个汉字之间,避免过短或过长。
3. 必须包含文章的主关键词,且把最重要的关键词放在标题前部。
4. 不要堆砌关键词、不要重复同义词、不要使用煽动性或夸张词汇。
5. 不要包含网站名称、品牌后缀,我们会自动追加站点名。
6. 直接输出标题文本本身,不要任何前缀、引号、Markdown、序号或解释。
7. 不要输出"标题:"、"答:"、"以下是" 等任何前导词。';
}
/**
* SEO 关键词 system instruction。
*/
public function get_seo_keywords_system_instruction(): string {
$custom = $this->read_custom_prompt('ai_seo_keywords_prompt');
if ($custom !== '') {
return $custom;
}
return '你是一名资深 SEO 编辑,负责为网站生成文章 meta keywords。
请严格遵循以下规则:
1. 输出 4 到 8 个最具搜索价值的关键词。
2. 全部使用中文(专有英文词可保留原文,例如 WordPress、AI、SEO)。
3. 使用英文逗号"," 分隔,不要使用顿号、句号、换行或编号。
4. 第一个关键词必须是文章的主关键词,紧扣标题与正文核心主题。
5. 不要堆砌、不要重复同义词、不要出现"等"、"以及"等填充语。
6. 直接输出关键词列表,不要任何前缀、解释、Markdown、引号或括号。
7. 关键词总长度建议控制在 50 个汉字以内。';
}
/**
* SEO 描述 system instruction。
*/
public function get_seo_description_system_instruction(): string {
$custom = $this->read_custom_prompt('ai_seo_description_prompt');
if ($custom !== '') {
return $custom;
}
return '你是一名资深的中文 SEO 编辑,擅长撰写吸引点击的搜索结果摘要(meta description)。
请严格遵循以下规则:
1. 输出 1 段描述,作为该文章的 meta description。
2. 字数控制在 80 至 150 个汉字之间,写成1至4句通顺的中文。
3. 必须自然融入文章的主关键词,但不要堆砌。
4. 体现文章的核心价值、目标读者或可获得的收益,要有吸引力但不夸张。
5. 不要分行、不要使用项目符号、不要使用 Markdown,不要包含品牌后缀或网址。
6. 直接输出描述文本本身,不要任何前缀、引号或解释。';
}
/**
* 兼容旧单 prompt 构建(草稿/无 ID 场景)。
*/
public function build_seo_prompt(string $title, string $content): string {
$title_instruction = $this->get_seo_title_system_instruction();
$kw_instruction = $this->get_seo_keywords_system_instruction();
$desc_instruction = $this->get_seo_description_system_instruction();
return <<<PROMPT
请根据以下文章内容,生成 SEO 优化建议。
@@ -60,9 +102,6 @@ class AKSRT_AI_Prompt {
PROMPT;
}
/**
* 构建内容摘要 prompt
*/
public function build_summary_prompt(string $content, int $max_length = 200): string {
$content = mb_substr($content, 0, 3000);
return <<<PROMPT
@@ -75,9 +114,6 @@ PROMPT;
PROMPT;
}
/**
* 构建标签建议 prompt
*/
public function build_tags_prompt(string $title, string $content): string {
$content = mb_substr($content, 0, 2000);
return <<<PROMPT
@@ -93,9 +129,6 @@ PROMPT;
PROMPT;
}
/**
* 构建摘要建议 prompt
*/
public function build_excerpt_prompt(string $title, string $content): string {
$content = mb_substr($content, 0, 2000);
return <<<PROMPT
@@ -114,4 +147,12 @@ PROMPT;
只返回摘要文本,不要其他内容。
PROMPT;
}
private function read_custom_prompt(string $key): string {
if (!class_exists('AKSRT_Settings')) {
return '';
}
$s = AKSRT_Settings::get_all();
return trim((string) ($s[$key] ?? ''));
}
}