{"id":8,"date":"2025-12-04T14:11:15","date_gmt":"2025-12-04T06:11:15","guid":{"rendered":"http:\/\/hfylrc.qilue.com\/?page_id=8"},"modified":"2026-01-29T21:12:19","modified_gmt":"2026-01-29T13:12:19","slug":"8-2","status":"publish","type":"page","link":"https:\/\/hfylrc.qilue.com\/","title":{"rendered":"\u5408\u80a5\u6613\u8054\u878d\u521b"},"content":{"rendered":"\n<div id=\"chatbox\" style=\"max-width:600px;margin:auto;padding:10px;border:1px solid #ccc;border-radius:10px;\">\n  <div id=\"messages\" style=\"height:300px;overflow-y:auto;margin-bottom:10px;padding:10px;background:#f9f9f9;border-radius:5px;\"><\/div>\n  <input id=\"userInput\" type=\"text\" placeholder=\"\u8f93\u5165\u60a8\u60f3\u54a8\u8be2\u7684\u4fe1\u606f\" style=\"width:80%;padding:8px;border:1px solid #ddd;border-radius:4px;\">\n  <button onclick=\"sendMessage()\" style=\"padding:8px 16px;background:#007cba;color:white;border:none;border-radius:4px;cursor:pointer;\">\u53d1\u9001<\/button>\n<\/div>\n\n<script>\nasync function sendMessage() {\n    const userInput = document.getElementById(\"userInput\");\n    const messages = document.getElementById(\"messages\");\n    const sendBtn = document.querySelector('button[onclick=\"sendMessage()\"]');\n\n    const text = userInput.value.trim();\n    if (!text) return;\n    \n    \/\/ \u7981\u7528\u8f93\u5165\u548c\u6309\u94ae\uff0c\u9632\u6b62\u91cd\u590d\u53d1\u9001\n    userInput.disabled = true;\n    sendBtn.disabled = true;\n    sendBtn.textContent = \"\u601d\u8003\u4e2d...\";\n\n    \/\/ \u6dfb\u52a0\u7528\u6237\u6d88\u606f\u5230\u804a\u5929\u6846\uff08\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\uff0c\u9632\u6b62XSS\uff09\n    const safeText = text.replace(\/<\/g, \"&lt;\").replace(\/>\/g, \"&gt;\");\n    messages.innerHTML += `<div style=\"margin:5px 0;\"><b>\u60a8\uff1a<\/b> ${safeText}<\/div>`;\n    userInput.value = \"\";\n    messages.scrollTop = messages.scrollHeight;\n\n    try {\n        const response = await fetch(\"\/wp-content\/deepseek-proxy.php\", { \/\/ \u4fee\u6b63PHP\u6587\u4ef6\u8def\u5f84\n            method: \"POST\",\n            headers: { \"Content-Type\": \"application\/json\" },\n            body: JSON.stringify({\n                model: \"qwen2.5:0.5b\",\n                prompt: text,\n                stream: false, \/\/ \u660e\u786e\u5173\u95ed\u6d41\u5f0f\u8f93\u51fa\n                temperature: 0.7\n            })\n        });\n\n        if (!response.ok) {\n            const errorData = await response.json().catch(() => ({ error: \"\u672a\u77e5\u9519\u8bef\" }));\n            messages.innerHTML += `<div style=\"margin:5px 0;color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${errorData.error || `Server error (${response.status})`}<\/div>`;\n            return;\n        }\n\n        const data = await response.json();\n\n        \/\/ \u9002\u914dOllama\u7684\u54cd\u5e94\u683c\u5f0f\n        if (data.response) {\n            \/\/ \u8f6c\u4e49\u6a21\u578b\u56de\u7b54\u4e2d\u7684\u7279\u6b8a\u5b57\u7b26\n            const safeResponse = data.response.replace(\/<\/g, \"&lt;\").replace(\/>\/g, \"&gt;\");\n            messages.innerHTML += `<div style=\"margin:5px 0;\"><b>\u7cfb\u7edf\uff1a<\/b> ${safeResponse}<\/div>`;\n        } else if (data.error) {\n            messages.innerHTML += `<div style=\"margin:5px 0;color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${data.error}<\/div>`;\n        } else if (data.message) {\n            messages.innerHTML += `<div style=\"margin:5px 0;color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${data.message}<\/div>`;\n        } else {\n            messages.innerHTML += `<div style=\"margin:5px 0;color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> \u672a\u4eceOllama\u83b7\u53d6\u5230\u6709\u6548\u54cd\u5e94<\/div>`;\n        }\n        messages.scrollTop = messages.scrollHeight;\n    } catch (e) {\n        messages.innerHTML += `<div style=\"margin:5px 0;color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${e.message || \"\u7f51\u7edc\u8bf7\u6c42\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u670d\u52a1\u5668\u8fde\u63a5\"}<\/div>`;\n    } finally {\n        \/\/ \u6062\u590d\u8f93\u5165\u548c\u6309\u94ae\n        userInput.disabled = false;\n        sendBtn.disabled = false;\n        sendBtn.textContent = \"\u53d1\u9001\";\n        userInput.focus(); \/\/ \u805a\u7126\u8f93\u5165\u6846\uff0c\u63d0\u5347\u4f53\u9a8c\n    }\n}\n\n\/\/ \u652f\u6301\u56de\u8f66\u53d1\u9001\u6d88\u606f\uff08\u4f18\u5316\u4f53\u9a8c\uff09\ndocument.getElementById(\"userInput\").addEventListener(\"keypress\", function(e) {\n    if (e.key === \"Enter\") {\n        sendMessage();\n    }\n});\n<\/script>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u53d1\u9001<\/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-8","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":14,"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8\/revisions"}],"predecessor-version":[{"id":34,"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8\/revisions\/34"}],"wp:attachment":[{"href":"https:\/\/hfylrc.qilue.com\/index.php\/wp-json\/wp\/v2\/media?parent=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}