前言
还在前言???帮 AI 快速总结嘛?哈哈~
本文为 hexo-ai-summaries 插件文档,插件主要功能是帮你插入 AI Html 至文章中,至于 Html 内容可自定,默认内容为适配 Gemini 和主题 ButterFly
获取 Gemini Pro API KEY
部署 API Proxy
Google PaLM API 限制使用区域,你需要部署中转服务
Netlify 注册繁琐?
你可能会因为 Netlify 的身份验证而停止了此教程,再提供个方案,好好看下去~
- 使用阿里云的
serverless(云函数) 反向代理AI服务(理论大部分AI服务都可使用) - nginx serverless - 或你懂的修改代码,也可以直接将 Gemini 提供的 API 和 gemini-openai-proxy 部署至 阿里云等
serverless服务中,注意Gemini的区域限制。
部署 Gemini OpenAI Proxy
这一步为可选,完成上面部署即可使用了。使用 赛博菩萨 cloudflare 部署该服务即可像使用 open ai 样使用 Gemini
修改:
var BASE_URL=>Netlify提供的域名 或者 你自己的gemini服务
var BASE_URL = "https://<your url>.netlify.app";
- 找到
getToken函数,修改内部的apikey为你的GeminiAPI KEY
if (!rawApikey.includes("#")) {
return {
// apikey: rawApikey,
apikey: 'your api key here',
useBeta: false
};
}
const apikey = 'your api key here';
- 【可选】搜索
access-control-allow-origin修改为你的域名
测试服务
你的 header 需要携带 Authorization,任意值即可。你可以在上述 getToken 函数中修改此逻辑。
curl https://cloudflare部署地址/v1/chat/completions \
-H "Authorization: xx \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello"}],
"temperature": 0.7
}'
配置 hexo-ai-summaries 插件
安装
pnpm add hexo-ai-summaries
使用
在 hexo/_config.yml 中配置 hexo-ai-summaries
root/_config.yml
hexo-ai-summaries: enable: true aiSummaryApi: https://<cloudflare workers url>.workers.dev/v1/chat/completions prompt: 'xxx' maxToken: 2000 aiConfig: model: gpt-4o stream: true
在你的文章中也可主动关闭
title: xxx
date: xxx
categories: xxx
cover: xxx
# add this line to disable ai-summaries
ai-summaries: false
进阶
- 为了更好的让
ai理解文章,传入至ai的内容为:文章标题:${tagConfig.title};文章目录:${tagConfig.toc};具体内容:${tagConfig.content},大部分情况下不需要设置该值,如需更改请修改tagConfig接受document.querySelector的值。 geminiConfig中的headers为Boolean,你可以在workers中固定,此处false可以防止options请求
root/_config.yml
hexo-ai-summaries: enable: true aiSummaryApi: https://<cloudflare workers url>.workers.dev/v1/chat/completions # 只在该日期后的文章上生成 摘要 按钮 generateAfterDate: 2024/05 # optional # 文字数量限制 => String.length maxToken: 30000 prompt: You are a highly skilled AI trained in language comprehension and summarization. I would like you to read the text delimited by triple quotes and summarize it into a concise abstract paragraph. Aim to retain the most important points, providing a coherent and readable summary that could help a person understand the main points of the discussion without needing to read the entire text. Please avoid unnecessary details or tangential points. Only give me the output and nothing else. Do not wrap responses in quotes. Respond in the Chinese language. aiConfig: model: gpt-4o temperature: 0.7 # optional default undefined headers: { 'Content-Type': 'application/json' } # optional, default undefined stream: false # optional default undefined # 获取摘要内容的元素标签,一般不需要改 tagConfig: # optional title: .post-title content: .post-content toc: .toc-content
进进阶
如果你有其他的服务和样式,那你也可以使用该插件。hexo-ai-summaries 可将你的 html js css 插入文章中(.post-content 内)。
因为会将内容添加至 文章内容 最前端,若塞入整个 html 将会影响列表页的摘要展示,所以 css 和 js 资源会以引入的方式加载(当然也会更加节省资源,和加快加载速度,有 CDN 的话)。会将你的文件生成在 public/hexo-ai-summaries 中。
hexo-ai-summaries:
enable: true
generateAfterDate: 2024/05
customHtml:
htmlFile: Gemini/gemini.html
jsFile: Gemini/gemini.js
styleFile: Gemini/gemini.css
prompt 进阶
在 prompt 中你可以让 Gemini 将相关词汇使用 "``" 回复,在渲染对话时会将其渲染为 code 标签。(目前仅支持此扩展)
缓存
你可以在 CF 的 workers 中使用 kV 缓存结果,或阿里云函数部署的可以使用 Nas 存储,插件在请求体中携带了 title 和 updateTime,可以由此判断,具体逻辑不赘述。
你可以一次性的返回结果(保持结构体一致即可),插件也会 fake 出流式输出效果
使用 deepseek 等其他 AI 服务
不支持推理的 tokens 输出(未做推理的回复识别)
插件支持 OpenAI 格式的输出,兼容非流式输出的 API,如你的 API 服务不是 openAI 格式的,可以使用三方工具 format,如 LiteLLM
国内可以使用中转的 API 服务,也可以使用大厂提供的如 硅基流动、火山引擎 等
推荐阅读
https://immmmm.com/gemini-pro-ai/
https://github.com/tardis-ksh/hexo-ai-summaries
























