Files
NotionNext/lib/plugins/aiSummary.js
anime 148545cea9 feat(原生AI摘要功能支持缓存): 自定义缓存功能只支持memory,不支持文件缓存
(cherry picked from commit dd56dae44f7f555d9004e7d1f872085bded2cb86)
2024-12-29 00:21:37 +08:00

33 lines
819 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* get Ai summary
* @returns {Promise<string>}
* @param aiSummaryAPI
* @param aiSummaryKey
* @param truncatedText
*/
export async function getAiSummary(aiSummaryAPI, aiSummaryKey, truncatedText) {
try {
console.log('请求文章摘要', truncatedText.slice(0, 100))
const response = await fetch(aiSummaryAPI, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
token: aiSummaryKey,
content: truncatedText
})
})
if (response.ok) {
const data = await response.json()
return data.summary
} else {
throw new Error('Response not ok')
}
} catch (error) {
console.error('ChucklePostAI请求失败', error)
return '获取文章摘要失败,请稍后再试。'
}
}