Files
NotionNext/lib/plugins/aiSummary.js

33 lines
776 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 null
}
}