在 Hexo 中使用 AI(Gemini Pro)生成文章摘要,支持自定义模板。hexo-ai-summaries 插件文档(默认适配主题 Butterfly)
前言
部署 Gemini 服务
获取 Gemini Pro API KEY
部署 API Proxy
Netlify
注册繁琐?
- 使用阿里云的
serverless
(云函数) 反向代理AI
服务(理论大部分AI
服务都可使用) - nginx serverless
部署 Gemini OpenAI Proxy
修改:
var BASE_URL
=>Netlify
提供的域名 或者 你自己的gemini
服务var BASE_URL = "https://<your url>.netlify.app";
- 找到
getToken
函数,修改内部的apikey
为你的Gemini
API KEY
if (!rawApikey.includes("#")) { return { // apikey: rawApikey, apikey: 'your api key here', useBeta: false }; } const apikey = 'your api key here';
- 【可选】搜索
access-control-allow-origin
修改为你的域名
测试服务
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-ai-summaries:
enable: true
aiSummaryApi: https://<cloudflare workers url>.workers.dev/v1/chat/completions
在你的文章中也可主动关闭
title: xxx
date: xxx
categories: xxx
cover: xxx
# add this line to disable ai-summaries
ai-summaries: false
进阶
hexo-ai-summaries:
enable: true
aiSummaryApi: https://<cloudflare workers url>.workers.dev/v1/chat/completions
# 只在该日期后的文章上生成 摘要 按钮
generateAfterDate: 2024/05
# 文字数量限制 => 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.
geminiConfig:
model: gpt-4o
temperature: 0.7
headers: false
tagConfig:
title: .post-title
content: .post-content
toc: .toc-content
进进阶
hexo-ai-summaries:
enable: true
generateAfterDate: 2024/05
customHtml:
htmlFile: Gemini/gemini.html
jsFile: Gemini/gemini.js
styleFile: Gemini/gemini.css
prompt 进阶
缓存
结语
https://immmmm.com/gemini-pro-ai/
https://github.com/tardis-ksh/hexo-ai-summaries
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来源 kshao-blog-前端知识记录!
评论