修复bug
This commit is contained in:
1 parent
26a68a8b31
commit
264a403470
121 files changed
+323
-210
No files matched your search
+13
-9
@@ -19,16 +19,20 @@ const ZHIPU_URL = 'https://open.bigmodel.cn/api/paas/v4/chat/completions';
|
||||
const ZHIPU_MODEL = 'glm-4';
|
||||
|
||||
async function generateComment(content) {
|
||||
const prompt = `你是一个热情的博客读者。请阅读以下文章内容,并写一段简短的评论(100字以内)。
|
||||
|
||||
要求:
|
||||
1. 语气自然、轻松,像真人的评论。
|
||||
2. 可以带一点幽默或感慨。
|
||||
3. 不要只是总结文章,要发表看法或共鸣。
|
||||
4. 不要带引号。
|
||||
const prompt = `你是"优世界"博客的常驻读者。你的评论风格:
|
||||
|
||||
文章内容:
|
||||
${content.substring(0, 2000)}...`; // Truncate to avoid token limits
|
||||
声音:
|
||||
- 你是一名资深技术人员,评论冷静、精准、有洞察力
|
||||
- 善于从技术细节中提炼出通用原理,或用简洁的类比让复杂问题变清晰
|
||||
- 偶尔就事论事地指出文章中可以深入探讨的方向,像同行审阅一样,但不过度严肃
|
||||
- 不强行搞笑,但可以有一丝冷幽默
|
||||
|
||||
格式:
|
||||
- 100 字以内
|
||||
- 只输出评论文本,不加引号、不署名、不带 emoji
|
||||
|
||||
文章内容:
|
||||
${content.substring(0, 2000)}`;
|
||||
|
||||
try {
|
||||
if (PROVIDER === 'siliconflow') {
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* Fetch AI greetings from api.usj.cc and write to static JS file.
|
||||
* Usage: node scripts/fetch_greetings.js
|
||||
* Env: RSS_API_TOKEN (same token used for RSS/links)
|
||||
*/
|
||||
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
|
||||
const API_BASE = "https://api.usj.cc/api/ai/greeting";
|
||||
let TOKEN = process.env.RSS_API_TOKEN;
|
||||
|
||||
// Fallback: read from write/.env
|
||||
if (!TOKEN) {
|
||||
try {
|
||||
const envPath = path.join(__dirname, "..", "write", ".env");
|
||||
const envContent = fs.readFileSync(envPath, "utf-8");
|
||||
const match = envContent.match(/^RSS_API_TOKEN=(.+)$/m);
|
||||
if (match) TOKEN = match[1].trim();
|
||||
} catch {}
|
||||
}
|
||||
|
||||
if (!TOKEN) {
|
||||
console.error("RSS_API_TOKEN env var is required (or write/.env with RSS_API_TOKEN=xxx)");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const url = `${API_BASE}?token=${encodeURIComponent(TOKEN)}`;
|
||||
const res = await fetch(url);
|
||||
if (!res.ok) {
|
||||
const body = await res.text();
|
||||
throw new Error(`API returned ${res.status}: ${body}`);
|
||||
}
|
||||
const data = await res.json();
|
||||
const greetings = data.greetings || [];
|
||||
|
||||
const byTime = { morning: [], noon: [], afternoon: [], evening: [], night: [] };
|
||||
const holidays = {};
|
||||
const generic = [];
|
||||
const timeKeys = Object.keys(byTime);
|
||||
|
||||
greetings.forEach((g) => {
|
||||
if (g.holiday) {
|
||||
holidays[g.holiday] = g.text;
|
||||
return;
|
||||
}
|
||||
var t = g.time || "";
|
||||
// Normalize: strip "weekday-"/"weekend-" prefix, lowercase
|
||||
var bucket = t.replace(/^(weekday|weekend)-/, "").toLowerCase();
|
||||
if (byTime[bucket]) {
|
||||
byTime[bucket].push(g.text);
|
||||
} else if (t === "weekend") {
|
||||
// "weekend" without a specific time → add to all slots
|
||||
timeKeys.forEach(function(k) { byTime[k].push(g.text); });
|
||||
} else {
|
||||
generic.push(g.text);
|
||||
}
|
||||
});
|
||||
|
||||
// Pick one random greeting per time slot, fall back to generic pool
|
||||
var timeGreetings = {};
|
||||
timeKeys.forEach(function(key) {
|
||||
var list = byTime[key];
|
||||
if (list.length === 0) list = generic;
|
||||
if (list.length > 0) {
|
||||
timeGreetings[key] = list[Math.floor(Math.random() * list.length)];
|
||||
}
|
||||
});
|
||||
|
||||
const js =
|
||||
"window.searchGreetings=" +
|
||||
JSON.stringify(timeGreetings) +
|
||||
";window.searchHolidays=" +
|
||||
JSON.stringify(holidays) +
|
||||
";";
|
||||
|
||||
const outDir = path.join(__dirname, "..", "static", "js");
|
||||
fs.mkdirSync(outDir, { recursive: true });
|
||||
const outPath = path.join(outDir, "ai_greetings.js");
|
||||
fs.writeFileSync(outPath, js, "utf-8");
|
||||
|
||||
console.log(
|
||||
`Wrote ${Object.keys(timeGreetings).length} time slots, ${Object.keys(holidays).length} holidays → ${outPath}`
|
||||
);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error("Failed to fetch AI greetings:", e.message);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user