{"id":148,"date":"2026-04-09T20:38:56","date_gmt":"2026-04-09T12:38:56","guid":{"rendered":"https:\/\/yuantian.xin\/?page_id=148"},"modified":"2026-04-10T23:38:58","modified_gmt":"2026-04-10T15:38:58","slug":"ai%e6%90%9c%e7%b4%a2","status":"publish","type":"page","link":"https:\/\/yuantian.xin\/index.php\/ai%e6%90%9c%e7%b4%a2\/","title":{"rendered":"AI\u641c\u7d22"},"content":{"rendered":"\n<div class=\"wp-block-group is-nowrap is-layout-flex wp-container-core-group-is-layout-6c531013 wp-block-group-is-layout-flex\">\n<div id=\"ai-assistant-container\" style=\"width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 15px; box-sizing: border-box; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;\">\n    <h3 style=\"text-align: center; color: #333; margin-bottom: 20px; font-weight: 600;\">AI \u667a\u80fd\u52a9\u624b<\/h3>\n    \n    <!-- \u5bf9\u8bdd\u5c55\u793a\u6846\uff08\u6269\u5bbd+\u65e0\u80cc\u666f\uff09 -->\n    <div id=\"chat-box\" style=\"border: 1px solid #e0e0e0; height: 450px; overflow-y: auto; padding: 20px; margin-bottom: 20px; border-radius: 8px; background: transparent; line-height: 1.6;\"><\/div>\n    \n    <!-- \u63a7\u5236\u533a\u57df -->\n    <div style=\"display: flex; flex-direction: column; gap: 15px;\">\n        <!-- \u8054\u7f51\u641c\u7d22\u52fe\u9009 -->\n        <div style=\"display: flex; align-items: center; gap: 8px; color: #555; font-size: 15px;\">\n            <input type=\"checkbox\" id=\"search-toggle\" style=\"width: 18px; height: 18px; cursor: pointer;\">\n            <label for=\"search-toggle\" style=\"cursor: pointer; margin: 0;\">\u542f\u7528\u8054\u7f51\u641c\u7d22<\/label>\n        <\/div>\n        \n        <!-- \u9a8c\u8bc1\u7801\u8f93\u5165 -->\n        <div style=\"display: flex; gap: 10px; align-items: center;\">\n            <input type=\"text\" id=\"captcha\" placeholder=\"\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801\" style=\"flex: 1; padding: 12px 15px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; outline: none; transition: border-color 0.2s;\">\n        <\/div>\n        \n        <!-- \u95ee\u9898\u8f93\u5165+\u6309\u94ae -->\n        <div style=\"display: flex; gap: 10px; flex-wrap: wrap;\">\n            <input type=\"text\" id=\"user-input\" placeholder=\"\u8bf7\u8f93\u5165\u4f60\u7684\u95ee\u9898...\" style=\"flex: 1; min-width: 200px; padding: 12px 15px; border: 1px solid #ddd; border-radius: 6px; font-size: 16px; outline: none; transition: border-color 0.2s;\">\n            <button id=\"send-btn\" style=\"padding: 12px 25px; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; font-weight: 600; background-color: #007bff; color: white; transition: background 0.2s; white-space: nowrap;\">\u5f00\u59cb\u6267\u884c<\/button>\n            <button id=\"clear-btn\" style=\"padding: 12px 25px; border: none; border-radius: 6px; cursor: pointer; font-size: 16px; font-weight: 600; background-color: #6c757d; color: white; transition: background 0.2s; white-space: nowrap;\">\u6e05\u9664\u5bf9\u8bdd<\/button>\n        <\/div>\n    <\/div>\n<\/div>\n\n<script>\n    let conversationHistory = [];\n    const chatBox = document.getElementById('chat-box');\n    const userInput = document.getElementById('user-input');\n    const sendBtn = document.getElementById('send-btn');\n    const clearBtn = document.getElementById('clear-btn');\n    const searchToggle = document.getElementById('search-toggle');\n    const captchaInput = document.getElementById('captcha');\n\n    \/\/ \u8f93\u5165\u6846\u805a\u7126\u6548\u679c\n    [userInput, captchaInput].forEach(input => {\n        input.addEventListener('focus', () => input.style.borderColor = '#007bff');\n        input.addEventListener('blur', () => input.style.borderColor = '#ddd');\n    });\n\n    \/\/ \u6309\u94ae\u60ac\u505c\u6548\u679c\n    sendBtn.addEventListener('mouseover', () => sendBtn.style.backgroundColor = '#0056b3');\n    sendBtn.addEventListener('mouseout', () => sendBtn.style.backgroundColor = '#007bff');\n    clearBtn.addEventListener('mouseover', () => clearBtn.style.backgroundColor = '#545b62');\n    clearBtn.addEventListener('mouseout', () => clearBtn.style.backgroundColor = '#6c757d');\n\n    function appendMessage(content, isUser) {\n        const div = document.createElement('div');\n        div.style.marginBottom = '15px';\n        div.style.padding = '10px 15px';\n        div.style.borderRadius = '18px';\n        div.style.maxWidth = '85%';\n        div.style.lineHeight = '1.6';\n        div.style.wordWrap = 'break-word';\n        if (isUser) {\n            div.style.backgroundColor = '#007bff';\n            div.style.color = 'white';\n            div.style.marginLeft = 'auto';\n        } else {\n            div.style.backgroundColor = '#f1f3f4';\n            div.style.color = '#333';\n        }\n        div.textContent = content;\n        chatBox.appendChild(div);\n        chatBox.scrollTop = chatBox.scrollHeight;\n    }\n\n    async function sendMessage() {\n        const question = userInput.value.trim();\n        const captcha = captchaInput.value.trim();\n\n        if (!question) return alert('\u8bf7\u8f93\u5165\u95ee\u9898');\n        if (!captcha) return alert('\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801');\n\n        sendBtn.disabled = true;\n        sendBtn.textContent = '\u601d\u8003\u4e2d...';\n        appendMessage(question, true);\n        userInput.value = '';\n\n        try {\n            \/\/ ================== \u5173\u952e\u4fee\u590d\uff1a\u5f3a\u5236\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84 ==================\n            const response = await fetch('https:\/\/www.yuantian.xin\/ai.php', {\n                method: 'POST',\n                headers: { 'Content-Type': 'application\/json' },\n                body: JSON.stringify({\n                    question: question,\n                    history: conversationHistory,\n                    use_search: searchToggle.checked,\n                    captcha: captcha\n                })\n            });\n\n            const data = await response.json();\n            \n            if (data.error) {\n                appendMessage('\u9519\u8bef: ' + data.error, false);\n            } else {\n                appendMessage(data.reply, false);\n                conversationHistory.push({ role: 'user', content: question });\n                conversationHistory.push({ role: 'assistant', content: data.reply });\n            }\n        } catch (error) {\n            appendMessage('\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u7f51\u7edc\u6216\u540e\u7aef\u914d\u7f6e\u3002', false);\n            console.error('\u8be6\u7ec6\u9519\u8bef:', error); \/\/ \u5728\u6d4f\u89c8\u5668\u63a7\u5236\u53f0\u6309F12\u53ef\u67e5\u770b\u8be6\u7ec6\u9519\u8bef\n        } finally {\n            sendBtn.disabled = false;\n            sendBtn.textContent = '\u5f00\u59cb\u6267\u884c';\n        }\n    }\n\n    sendBtn.addEventListener('click', sendMessage);\n    userInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') sendMessage(); });\n    \n    clearBtn.addEventListener('click', () => {\n        chatBox.innerHTML = '';\n        conversationHistory = [];\n    });\n<\/script>\n<\/div>\n\n\n\n<p class=\"has-text-align-center\">\u00a9 2026 \u6e90\u751c\u7684\u4e2a\u4eba\u7f51\u7ad9 | <img loading=\"lazy\" decoding=\"async\" width=\"18\" height=\"20\" class=\"wp-image-119\" style=\"width: 18px;\" src=\"https:\/\/yuantian.xin\/wp-content\/uploads\/2026\/04\/head-logo2.4d29d9b1.png\" alt=\"\"> <a href=\"https:\/\/beian.mps.gov.cn\/\">\u8c6b\u516c\u7f51\u5b89\u590741170202411829\u53f7<\/a> | <a href=\"https:\/\/beian.miit.gov.cn\">\u8c6bICP\u59072026011029\u53f7<\/a> <\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>AI \u667a\u80fd\u52a9\u624b \u542f\u7528\u8054\u7f51\u641c\u7d22 \u5f00\u59cb\u6267\u884c \u6e05\u9664\u5bf9\u8bdd<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-148","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/pages\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":13,"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/pages\/148\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/pages\/148\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/yuantian.xin\/index.php\/wp-json\/wp\/v2\/media?parent=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}