{"id":8,"date":"2025-12-04T14:11:15","date_gmt":"2025-12-04T06:11:15","guid":{"rendered":"http:\/\/yirong.qilue.com\/?page_id=8"},"modified":"2025-12-04T21:13:11","modified_gmt":"2025-12-04T13:13:11","slug":"8-2","status":"publish","type":"page","link":"https:\/\/yirong.qilue.com\/","title":{"rendered":"\u6613\u878d"},"content":{"rendered":"\n<!-- Place in your HTML file -->\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;\"><\/div>\n  <input id=\"userInput\" type=\"text\" placeholder=\"\u8f93\u5165\u60a8\u60f3\u54a8\u8be2\u7684\u4fe1\u606f\" style=\"width:80%;padding:8px;\">\n  <button onclick=\"sendMessage()\" style=\"padding:8px;\">\u53d1\u9001<\/button>\n<\/div>\n\n<script>\nasync function sendMessage() {\n    const userInput = document.getElementById(\"userInput\");\n    const messages = document.getElementById(\"messages\");\n\n    const text = userInput.value.trim();\n    if (!text) return;\n    userInput.value = \"\";\n\n    messages.innerHTML += `<div><b>\u60a8\uff1a<\/b> ${text}<\/div>`;\n\n    try {\n        const response = await fetch(\"\/deepseek-proxy.php\", {\n            method: \"POST\",\n            headers: { \"Content-Type\": \"application\/json\" },\n            body: JSON.stringify({\n                model: \"deepseek-r1:1.5b\",\n                prompt: text,\n                stream: false\n            })\n        });\n\n        if (!response.ok) {\n            messages.innerHTML += `<div style=\"color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> Server error (${response.status})<\/div>`;\n            return;\n        }\n\n        const data = await response.json();\n\n        \/\/ Ollama returns 'response' field with the answer\n        if (data.response) {\n            messages.innerHTML += `<div><b>\u7cfb\u7edf\uff1a<\/b> ${data.response}<\/div>`;\n        } else if (data.error) {\n            messages.innerHTML += `<div style=\"color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${data.error}<\/div>`;\n        } else {\n            messages.innerHTML += `<div style=\"color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> No response from Ollama<\/div>`;\n        }\n        messages.scrollTop = messages.scrollHeight;\n    } catch (e) {\n        messages.innerHTML += `<div style=\"color:red;\"><b>\u51fa\u73b0\u9519\u8bef\uff1a<\/b> ${e.message}<\/div>`;\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:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/comments?post=8"}],"version-history":[{"count":11,"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8\/revisions"}],"predecessor-version":[{"id":30,"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/pages\/8\/revisions\/30"}],"wp:attachment":[{"href":"https:\/\/yirong.qilue.com\/index.php\/wp-json\/wp\/v2\/media?parent=8"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}