<divclass="post-ai"onclick="geminiAI()"> <imgalt="Static Badge"src="https://api-shields.edui.fun/badge/Gemini-文章摘要-blue.svg?logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxZW0iIGhlaWdodD0iMWVtIiB2aWV3Qm94PSIwIDAgMjQgMjQiPjxwYXRoIGZpbGw9Im5vbmUiIHN0cm9rZT0iI2ZmZmZmZiIgc3Ryb2tlLWxpbmVjYXA9InJvdW5kIiBzdHJva2UtbGluZWpvaW49InJvdW5kIiBzdHJva2Utd2lkdGg9IjIiIGQ9Im0yMS42NCAzLjY0bC0xLjI4LTEuMjhhMS4yMSAxLjIxIDAgMCAwLTEuNzIgMEwyLjM2IDE4LjY0YTEuMjEgMS4yMSAwIDAgMCAwIDEuNzJsMS4yOCAxLjI4YTEuMiAxLjIgMCAwIDAgMS43MiAwTDIxLjY0IDUuMzZhMS4yIDEuMiAwIDAgMCAwLTEuNzJNMTQgN2wzIDNNNSA2djRtMTQgNHY0TTEwIDJ2Mk03IDhIM20xOCA4aC00TTExIDNIOSIvPjwvc3ZnPg=="> </div> <style> @keyframes spin { from {transform: rotate(0deg);}to {transform: rotate(360deg);} } .post-ai-result svg{animation: spin 1s infinite linear;} </style> <script> let postAI = document.querySelector(".post-ai") let postTile = document.querySelector(".post-title a").textContent asyncfunctiongeminiAI() { postAI.insertAdjacentHTML('afterend', '<div class="post-ai-result"><svg xmlns="http://www.w3.org/2000/svg" width="1.5rem" height="1.5rem" viewBox="0 0 24 24"><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 1 1-6.219-8.56"/></svg></div>'); postAI.classList.add("noclick") letGeminiFetch = "{{ geminiAPI }}" try { let postAIResult = document.querySelector(".post-ai-result") let input = document.querySelector(".post-content").textContent let inputHanzi = input.replace(/\n/g, '').replace(/[ ]+/g, ' ').replace(/<pre>[\s\S]*?<\/pre>/g, '').substring(0, 30000) let toAI = `文章标题:${postTile},具体内容:${inputHanzi}` const res = awaitfetch(GeminiFetch, { headers: { 'Content-Type': 'application/json' }, method: 'POST', body: JSON.stringify({ model: 'gemini-pro', messages: [ { role: 'system', content: `{% raw %}You are a highly skilled AI trained in language comprehension and summarization. I would like you to read the text delimited by triple quotes and summarize it into a concise abstract paragraph. Aim to retain the most important points, providing a coherent and readable summary that could help a person understand the main points of the discussion without needing to read the entire text. Please avoid unnecessary details or tangential points. Only give me the output and nothing else. Do not wrap responses in quotes. Respond in the Chinese language.{% endraw %}` }, { role: 'user', content: toAI } ], temperature: 0.7, stream: true }) }) const reader = res.body.getReader() while(true) { const {value, done} = await reader.read() if (done) { break } const text = newTextDecoder().decode(value) const match = text.match(/DONE/) if(!match){ const textJson = JSON.parse(text.substring(5)) const resData = textJson.choices[0].delta.content if(resData.length > 0){ //console.log(textJson) postAIResult.textContent += resData } } } } catch (error) { document.querySelector(".post-ai-result").remove(); console.log(error); } }; </script>