Skip to content

Commit

Permalink
fix: fix spelling mistake
Browse files Browse the repository at this point in the history
chore: optimize md2node handling
  • Loading branch information
adolphnov committed Aug 20, 2024
1 parent 561ba79 commit 4ff4922
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 55 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sha":"5ea58d5","timestamp":1723898343}
{"sha":"561ba79","timestamp":1724170465}
20 changes: 11 additions & 9 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,9 @@ var Environment = class {
// -- 版本数据 --
//
// 当前版本
BUILD_TIMESTAMP = 1723898343;
BUILD_TIMESTAMP = 1724170465;
// 当前版本 commit id
BUILD_VERSION = "5ea58d5";
BUILD_VERSION = "561ba79";
// -- 基础配置 --
/**
* @type {I18n | null}
Expand Down Expand Up @@ -1909,13 +1909,13 @@ ERROR: ${e2.message}`;
var tools_default2 = {
search: {
prompt: "\u4F5C\u4E3A\u667A\u80FD\u52A9\u624B\uFF0C\u8BF7\u6309\u7167\u4EE5\u4E0B\u6B65\u9AA4\u6709\u6548\u5206\u6790\u5E76\u63D0\u53D6\u6211\u63D0\u4F9B\u7684\u641C\u7D22\u7ED3\u679C\uFF0C\u4EE5\u7B80\u6D01\u660E\u4E86\u7684\u65B9\u5F0F\u56DE\u7B54\u6211\u7684\u95EE\u9898\uFF1A\n\n1. \u9605\u8BFB\u548C\u8BC4\u4F30\uFF1A\u4ED4\u7EC6\u9605\u8BFB\u6240\u6709\u641C\u7D22\u7ED3\u679C\uFF0C\u8BC6\u522B\u5E76\u4F18\u5148\u83B7\u53D6\u6765\u81EA\u53EF\u9760\u548C\u6700\u65B0\u6765\u6E90\u7684\u4FE1\u606F\u3002\u8003\u8651\u56E0\u7D20\u5305\u62EC\u5B98\u65B9\u6765\u6E90\u3001\u77E5\u540D\u673A\u6784\u4EE5\u53CA\u4FE1\u606F\u7684\u66F4\u65B0\u65F6\u95F4\u3002\n\n2. \u63D0\u53D6\u5173\u952E\u4FE1\u606F\uFF1A\n \u2022 *\u6C47\u7387\u67E5\u8BE2*\uFF1A\u63D0\u4F9B\u6700\u65B0\u6C47\u7387\u5E76\u8FDB\u884C\u5FC5\u8981\u7684\u6362\u7B97\u3002\n \u2022 *\u5929\u6C14\u67E5\u8BE2*\uFF1A\u63D0\u4F9B\u5177\u4F53\u5730\u70B9\u548C\u65F6\u95F4\u7684\u5929\u6C14\u9884\u62A5\u3002\n \u2022 *\u4E8B\u5B9E\u6027\u95EE\u9898*\uFF1A\u627E\u51FA\u6743\u5A01\u56DE\u7B54\u3002\n\n3. \u7B80\u6D01\u56DE\u7B54\uFF1A\u5BF9\u63D0\u53D6\u7684\u4FE1\u606F\u8FDB\u884C\u7EFC\u5408\u5206\u6790\uFF0C\u7ED9\u51FA\u7B80\u660E\u627C\u8981\u7684\u56DE\u7B54\u3002\n\n4. \u8BC6\u522B\u4E0D\u786E\u5B9A\u6027\uFF1A\u5982\u679C\u4FE1\u606F\u5B58\u5728\u77DB\u76FE\u6216\u4E0D\u786E\u5B9A\u6027\uFF0C\u8BF7\u89E3\u91CA\u53EF\u80FD\u539F\u56E0\u3002\n\n5. \u8BF4\u660E\u4FE1\u606F\u4E0D\u8DB3\uFF1A\u5982\u679C\u641C\u7D22\u7ED3\u679C\u65E0\u6CD5\u5B8C\u5168\u56DE\u7B54\u95EE\u9898\uFF0C\u6307\u51FA\u9700\u8981\u7684\u989D\u5916\u4FE1\u606F\u3002\n\n6. \u7528\u6237\u53CB\u597D\uFF1A\u4F7F\u7528\u7B80\u5355\u6613\u61C2\u7684\u8BED\u8A00\uFF0C\u5FC5\u8981\u65F6\u63D0\u4F9B\u7B80\u77ED\u89E3\u91CA\uFF0C\u786E\u4FDD\u56DE\u7B54\u6613\u4E8E\u7406\u89E3\u3002\n\n7. \u9644\u52A0\u4FE1\u606F\uFF1A\u6839\u636E\u9700\u8981\u63D0\u4F9B\u989D\u5916\u76F8\u5173\u4FE1\u606F\u6216\u5EFA\u8BAE\uFF0C\u4EE5\u589E\u5F3A\u56DE\u7B54\u7684\u4EF7\u503C\u3002\n\n8. \u6765\u6E90\u6807\u6CE8\uFF1A\u5728\u56DE\u7B54\u4E2D\u6E05\u6670\u6807\u6CE8\u4FE1\u606F\u6765\u6E90\uFF0C\u5305\u62EC\u6765\u6E90\u7F51\u7AD9\u6216\u673A\u6784\u540D\u79F0\u53CA\u6570\u636E\u7684\u53D1\u5E03\u6216\u66F4\u65B0\u65F6\u95F4\u3002\n\n9. \u53C2\u8003\u5217\u8868\uFF1A\u5982\u679C\u5F15\u7528\u4E86\u591A\u4E2A\u6765\u6E90\uFF0C\u5728\u56DE\u7B54\u6700\u540E\u63D0\u4F9B\u7B80\u77ED\u7684\u53C2\u8003\u5217\u8868\uFF0C\u5217\u51FA\u4E3B\u8981\u4FE1\u606F\u6765\u6E90\u3002\n\n\u8BF7\u786E\u4FDD\u76EE\u6807\u662F\u63D0\u4F9B\u6700\u65B0\u3001\u6700\u76F8\u5173\u548C\u6700\u6709\u7528\u7684\u4FE1\u606F\uFF0C\u76F4\u63A5\u56DE\u5E94\u6211\u7684\u95EE\u9898\u3002\u907F\u514D\u5197\u957F\u7684\u7EC6\u8282\uFF0C\u805A\u7126\u4E8E\u6211\u6700\u5173\u5FC3\u7684\u6838\u5FC3\u7B54\u6848\uFF0C\u5E76\u901A\u8FC7\u53EF\u9760\u7684\u6765\u6E90\u589E\u5F3A\u56DE\u7B54\u7684\u53EF\u4FE1\u5EA6\u3002Tip: \u4E0D\u8981\u4EE5\u4F60\u7684\u77E5\u8BC6\u5E93\u65F6\u95F4\u4F5C\u4E3A\u8BC4\u5224\u6807\u51C6",
extra_params: { tempurature: 0.7, "top_p": 0.4 },
extra_params: { temperature: 0.7, "top_p": 0.4 },
render: (result) => `\u641C\u7D22\u7ED3\u679C:
${result}`
},
web_crawler: {
prompt: '\u4F5C\u4E3A\u4E00\u4E2A\u9AD8\u6548\u7684\u5185\u5BB9\u5206\u6790\u548C\u603B\u7ED3\u52A9\u624B\uFF0C\u4F60\u7684\u4EFB\u52A1\u662F\u5BF9\u7528\u6237\u63D0\u4F9B\u7684\u7F51\u9875\u6216PDF\u5185\u5BB9\u8FDB\u884C\u5168\u9762\u800C\u7B80\u6D01\u7684\u603B\u7ED3\u3002\u8BF7\u9075\u5FAA\u4EE5\u4E0B\u6307\u5357\uFF1A\n 1. \u4ED4\u7EC6\u9605\u8BFB\u7528\u6237\u63D0\u4F9B\u7684\u5168\u90E8\u5185\u5BB9\uFF0C\u786E\u4FDD\u7406\u89E3\u4E3B\u8981\u89C2\u70B9\u548C\u5173\u952E\u4FE1\u606F\u3002\n 2. \u8BC6\u522B\u5E76\u63D0\u70BC\u51FA\u5185\u5BB9\u7684\u6838\u5FC3\u4E3B\u9898\u548C\u4E3B\u8981\u8BBA\u70B9\u3002\n 3. \u603B\u7ED3\u65F6\u5E94\u5305\u62EC\u4EE5\u4E0B\u8981\u7D20\uFF1A\n \u2022 \u5185\u5BB9\u7684\u4E3B\u8981\u76EE\u7684\u6216\u4E3B\u9898\n \u2022 \u5173\u952E\u89C2\u70B9\u6216\u8BBA\u636E\n \u2022 \u91CD\u8981\u7684\u6570\u636E\u6216\u7EDF\u8BA1\u4FE1\u606F\uFF08\u5982\u679C\u6709\uFF09\n \u2022 \u4F5C\u8005\u7684\u7ED3\u8BBA\u6216\u5EFA\u8BAE\uFF08\u5982\u679C\u9002\u7528\uFF09\n 4. \u4FDD\u6301\u5BA2\u89C2\u6027\uFF0C\u51C6\u786E\u53CD\u6620\u539F\u6587\u7684\u89C2\u70B9\uFF0C\u4E0D\u6DFB\u52A0\u4E2A\u4EBA\u89E3\u91CA\u6216\u8BC4\u8BBA\u3002\n 5. \u4F7F\u7528\u6E05\u6670\u3001\u7B80\u6D01\u7684\u8BED\u8A00\uFF0C\u907F\u514D\u4F7F\u7528\u8FC7\u4E8E\u4E13\u4E1A\u6216\u6666\u6DA9\u7684\u672F\u8BED\u3002\n 6. \u603B\u7ED3\u7684\u957F\u5EA6\u5E94\u8BE5\u662F\u539F\u6587\u768410-15%\uFF0C\u9664\u975E\u7528\u6237\u7279\u522B\u6307\u5B9A\u5176\u4ED6\u957F\u5EA6\u8981\u6C42\u3002\n 7. \u5982\u679C\u5185\u5BB9\u5305\u542B\u591A\u4E2A\u90E8\u5206\u6216\u7AE0\u8282\uFF0C\u53EF\u4EE5\u4F7F\u7528\u7B80\u77ED\u7684\u5C0F\u6807\u9898\u6765\u7EC4\u7EC7\u4F60\u7684\u603B\u7ED3\u3002\n 8. \u5982\u679C\u539F\u6587\u5305\u542B\u56FE\u8868\u6216\u56FE\u50CF\u7684\u91CD\u8981\u4FE1\u606F\uFF0C\u8BF7\u5728\u603B\u7ED3\u4E2D\u63D0\u53CA\u8FD9\u4E00\u70B9\u3002\n 9. \u5982\u679C\u5185\u5BB9\u6D89\u53CA\u65F6\u95F4\u654F\u611F\u7684\u4FE1\u606F\uFF0C\u8BF7\u5728\u603B\u7ED3\u4E2D\u6CE8\u660E\u5185\u5BB9\u7684\u53D1\u5E03\u65E5\u671F\u6216\u7248\u672C\u3002\n 10. \u5982\u679C\u539F\u6587\u5B58\u5728\u660E\u663E\u7684\u504F\u89C1\u6216\u4E89\u8BAE\u6027\u89C2\u70B9\uFF0C\u8BF7\u5728\u603B\u7ED3\u4E2D\u5BA2\u89C2\u5730\u6307\u51FA\u8FD9\u4E00\u70B9\u3002\n 11. \u603B\u7ED3\u5B8C\u6210\u540E\uFF0C\u63D0\u4F9B1-3\u4E2A\u5173\u952E\u8BCD\u6216\u77ED\u8BED\uFF0C\u6982\u62EC\u5185\u5BB9\u7684\u6838\u5FC3\u4E3B\u9898\u3002\n 12. \u5982\u679C\u7528\u6237\u8981\u6C42\uFF0C\u53EF\u4EE5\u5728\u603B\u7ED3\u7684\u6700\u540E\u6DFB\u52A0\u4E00\u4E2A\u7B80\u77ED\u7684"\u8FDB\u4E00\u6B65\u9605\u8BFB\u5EFA\u8BAE"\u90E8\u5206, \u4EE5\u53CA\u5FC5\u8981\u7684\u5F15\u7528\u6765\u6E90\u3002\n \u8BF7\u8BB0\u4F4F\uFF0C\u4F60\u7684\u76EE\u6807\u662F\u63D0\u4F9B\u4E00\u4E2A\u5168\u9762\u3001\u51C6\u786E\u3001\u6613\u4E8E\u7406\u89E3\u7684\u603B\u7ED3\uFF0C\u5E2E\u52A9\u7528\u6237\u5FEB\u901F\u628A\u63E1\u5185\u5BB9\u7684\u7CBE\u9AD3\u3002\u5982\u679C\u5185\u5BB9\u7279\u522B\u957F\u6216\u590D\u6742\uFF0C\u4F60\u53EF\u4EE5\u8BE2\u95EE\u7528\u6237\u662F\u5426\u9700\u8981\u66F4\u8BE6\u7EC6\u7684\u603B\u7ED3\u6216\u7279\u5B9A\u90E8\u5206\u7684\u6DF1\u5165\u5206\u6790\u3002\u8BF7\u5728\u6700\u540E\u9762\u6807\u6CE8\u5F15\u7528\u7684\u94FE\u63A5.',
extra_params: { tempurature: 0.7, "top_p": 0.4 },
extra_params: { temperature: 0.7, "top_p": 0.4 },
render: (result) => `\u7F51\u9875\u5185\u5BB9:
${result}`
},
Expand Down Expand Up @@ -3171,20 +3171,21 @@ function markdownToTelegraphNodes(markdown) {
codeBlockContent += line + "\n";
continue;
}
if (!line)
const _line = line.trim();
if (!_line)
continue;
if (line.startsWith("#")) {
if (_line.startsWith("#")) {
let level = line.match(/^#+/)[0].length;
level = level <= 2 ? 3 : 4;
const text2 = line.replace(/^#+\s*/, "");
nodes.push({ tag: `h${level}`, children: processInlineElements(text2) });
} else if (line.startsWith("> ")) {
} else if (_line.startsWith("> ")) {
const text2 = line.slice(2);
nodes.push({ tag: "blockquote", children: processInlineElements(text2) });
} else if (line === "---" || line === "***") {
} else if (_line === "---" || _line === "***") {
nodes.push({ tag: "hr" });
} else {
const matches = line.match(/^(\s*)(-|\*)\s/);
const matches = RegExp(/^(\s*)(-|\*)\s/).exec(line);
if (matches) {
line = matches[1] + "\u2022 " + line.slice(matches[0].length);
}
Expand Down Expand Up @@ -3332,6 +3333,7 @@ async function sendTelegraph(context, title, content, author) {
const c_resp = await createOrEditPage(sendContext, title, content, author);
if (c_resp.ok) {
context.telegraphPath = c_resp.result.path;
console.log("telegraph url: ", c_resp.result.url);
return c_resp;
} else {
console.error(c_resp.error);
Expand Down
2 changes: 1 addition & 1 deletion dist/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1723898343
1724170465
4 changes: 2 additions & 2 deletions src/prompt/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ export default {
search: {
prompt:
'作为智能助手,请按照以下步骤有效分析并提取我提供的搜索结果,以简洁明了的方式回答我的问题:\n\n1. 阅读和评估:仔细阅读所有搜索结果,识别并优先获取来自可靠和最新来源的信息。考虑因素包括官方来源、知名机构以及信息的更新时间。\n\n2. 提取关键信息:\n • *汇率查询*:提供最新汇率并进行必要的换算。\n • *天气查询*:提供具体地点和时间的天气预报。\n • *事实性问题*:找出权威回答。\n\n3. 简洁回答:对提取的信息进行综合分析,给出简明扼要的回答。\n\n4. 识别不确定性:如果信息存在矛盾或不确定性,请解释可能原因。\n\n5. 说明信息不足:如果搜索结果无法完全回答问题,指出需要的额外信息。\n\n6. 用户友好:使用简单易懂的语言,必要时提供简短解释,确保回答易于理解。\n\n7. 附加信息:根据需要提供额外相关信息或建议,以增强回答的价值。\n\n8. 来源标注:在回答中清晰标注信息来源,包括来源网站或机构名称及数据的发布或更新时间。\n\n9. 参考列表:如果引用了多个来源,在回答最后提供简短的参考列表,列出主要信息来源。\n\n请确保目标是提供最新、最相关和最有用的信息,直接回应我的问题。避免冗长的细节,聚焦于我最关心的核心答案,并通过可靠的来源增强回答的可信度。Tip: 不要以你的知识库时间作为评判标准',
extra_params: { tempurature: 0.7, 'top_p': 0.4 },
extra_params: { temperature: 0.7, 'top_p': 0.4 },
render: (result) => `搜索结果:\n${result}`,
},
web_crawler: {
prompt:
'作为一个高效的内容分析和总结助手,你的任务是对用户提供的网页或PDF内容进行全面而简洁的总结。请遵循以下指南:\n 1. 仔细阅读用户提供的全部内容,确保理解主要观点和关键信息。\n 2. 识别并提炼出内容的核心主题和主要论点。\n 3. 总结时应包括以下要素:\n • 内容的主要目的或主题\n • 关键观点或论据\n • 重要的数据或统计信息(如果有)\n • 作者的结论或建议(如果适用)\n 4. 保持客观性,准确反映原文的观点,不添加个人解释或评论。\n 5. 使用清晰、简洁的语言,避免使用过于专业或晦涩的术语。\n 6. 总结的长度应该是原文的10-15%,除非用户特别指定其他长度要求。\n 7. 如果内容包含多个部分或章节,可以使用简短的小标题来组织你的总结。\n 8. 如果原文包含图表或图像的重要信息,请在总结中提及这一点。\n 9. 如果内容涉及时间敏感的信息,请在总结中注明内容的发布日期或版本。\n 10. 如果原文存在明显的偏见或争议性观点,请在总结中客观地指出这一点。\n 11. 总结完成后,提供1-3个关键词或短语,概括内容的核心主题。\n 12. 如果用户要求,可以在总结的最后添加一个简短的"进一步阅读建议"部分, 以及必要的引用来源。\n 请记住,你的目标是提供一个全面、准确、易于理解的总结,帮助用户快速把握内容的精髓。如果内容特别长或复杂,你可以询问用户是否需要更详细的总结或特定部分的深入分析。请在最后面标注引用的链接.',
extra_params: { tempurature: 0.7, 'top_p': 0.4 },
extra_params: { temperature: 0.7, 'top_p': 0.4 },
render: (result) => `网页内容:\n${result}`,
},
default: {
Expand Down
50 changes: 14 additions & 36 deletions src/telegram/telegraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ async function createAccount(author) {
}

async function createOrEditPage(sendContext, title, content, author) {
// const url = 'https://api.telegra.ph/createPage';
const { url, access_token, path } = sendContext;
const {short_name, author_name, author_url} = author;
const body = {
Expand All @@ -34,41 +33,15 @@ async function createOrEditPage(sendContext, title, content, author) {
}).then((r) => r.json());
}

// async function editTelegraph(access_token, path, title, content, author_name) {
// const url = 'https://api.telegra.ph/editPage';
// const headers = { 'Content-Type': 'application/json' };
// // const perfix_nodes = [
// // { tag: 'h3', children: ['Question'] },
// // { tag: 'blockquote', children: [content.question] },
// // { tag: 'hr' },
// // { tag: 'h3', children: ['Answer'] }];

// const body = {
// access_token,
// path,
// title,
// author_name,
// content: md2node(content.answer)
// // 'return_content': true,
// };

// return fetch(url, {
// method: 'post',
// headers,
// body: JSON.stringify(body),
// }).then((r) => r.json());
// }

// function render(title, content) {
// return [
// { tag: 'h3', children: ['Question'] },
// { tag: 'blockquote', children: [title] },
// { tag: 'hr' },
// { tag: 'h3', children: ['Answer'] },
// { tag: 'pre', children: [content] },
// ];
// }

/**
* @description:
* @param {*} context
* @param {*} title
* @param {*} content
* @param {*} author
* @return {*}
*/
async function sendTelegraph(context, title, content, author) {
let endPoint = 'https://api.telegra.ph/editPage';
let access_token = context.telegraphAccessToken;
Expand All @@ -85,12 +58,17 @@ async function sendTelegraph(context, title, content, author) {
const c_resp = await createOrEditPage(sendContext, title, content, author);
if (c_resp.ok) {
context.telegraphPath = c_resp.result.path;
// console.log('telegraph url: ', c_resp.result.url);
console.log('telegraph url: ', c_resp.result.url);
return c_resp;
} else { console.error(c_resp.error); throw new Error(c_resp.error); }
} else return createOrEditPage(sendContext, title, content, author);
}

/**
* @description:
* @param {*} context
* @return {*}
*/
export function sendTelegraphWithContext(context) {
return async (title, content, author) => sendTelegraph(context.SHARE_CONTEXT, title, content, author);
}
12 changes: 6 additions & 6 deletions src/utils/md2node.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ function markdownToTelegraphNodes(markdown) {
continue;
}

// line = line.trim();
if (!line) continue;
const _line = line.trim();
if (!_line) continue;

// 标题
if (line.startsWith('#')) {
if (_line.startsWith('#')) {
let level = line.match(/^#+/)[0].length;
level = level <= 2 ? 3 : 4; // telegram 仅支持h3 h4
const text = line.replace(/^#+\s*/, '');
nodes.push({ tag: `h${level}`, children: processInlineElements(text) });
// nodes.push({ tag: `h${level}`, children: [text] }); // 简化处理
}
// 引用
else if (line.startsWith("> ")) {
else if (_line.startsWith("> ")) {
const text = line.slice(2);
nodes.push({ tag: 'blockquote', children: processInlineElements(text) });
}
Expand All @@ -77,12 +77,12 @@ function markdownToTelegraphNodes(markdown) {
// currentList.children.push({ tag: 'li', children: processInlineElements(text) });
// }
// 分割线
else if (line === '---' || line === '***') {
else if (_line === '---' || _line === '***') {
nodes.push({ tag: "hr" });
}
// 段落
else {
const matches = line.match(/^(\s*)(-|\*)\s/);
const matches = RegExp(/^(\s*)(-|\*)\s/).exec(line);
if (matches) {
line = matches[1] + '• ' + line.slice(matches[0].length);
}
Expand Down

0 comments on commit 4ff4922

Please sign in to comment.