mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feat(原生支持AI摘要功能): 使用一层API作为缓存而非直接请求AI,可以实现缓存/后端保密和预渲染
(cherry picked from commit 611a7d1d5dc7bc200d4390e29217ab8c8f76b0f0)
This commit is contained in:
31
lib/plugins/aiSummary.js
Normal file
31
lib/plugins/aiSummary.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* get Ai summary
|
||||
* @returns {Promise<string>}
|
||||
* @param aiSummaryAPI
|
||||
* @param aiSummaryKey
|
||||
* @param truncatedText
|
||||
*/
|
||||
export async function getAiSummary(aiSummaryAPI, aiSummaryKey, truncatedText) {
|
||||
try {
|
||||
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 '获取文章摘要失败,请稍后再试。'
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user