{"id":6,"date":"2025-09-02T13:44:53","date_gmt":"2025-09-02T13:44:53","guid":{"rendered":"https:\/\/tiimiss.ba\/?page_id=6"},"modified":"2025-09-02T14:21:04","modified_gmt":"2025-09-02T14:21:04","slug":"ai-assistant-2","status":"publish","type":"page","link":"https:\/\/tiimiss.ba\/?page_id=6","title":{"rendered":"AI Assistant"},"content":{"rendered":"<p><script>\ndocument.addEventListener('DOMContentLoaded', function() {\n    const chatInput = document.getElementById('chat-input');\n    const sendButton = document.getElementById('send-button');\n    const chatMessages = document.getElementById('chat-messages');\n    const modeButtons = document.querySelectorAll('.ai-mode-btn');<\/p>\n<p>    let currentMode = 'general';\n    let conversationHistory = [];<\/p>\n<p>    \/\/ Mode selection\n    modeButtons.forEach(btn => {\n        btn.addEventListener('click', function() {\n            modeButtons.forEach(b => b.classList.remove('active'));\n            this.classList.add('active');\n            currentMode = this.dataset.mode;\n            addMessage(`Switched to ${this.textContent} mode. How can I help?`, 'ai');\n        });\n    });<\/p>\n<p>    \/\/ Send message to AI backend\n    async function sendMessage() {\n        const message = chatInput.value.trim();\n        if (!message) return;<\/p>\n<p>        \/\/ Add user message\n        addMessage(message, 'user');\n        chatInput.value = '';<\/p>\n<p>        try {\n            \/\/ Send to your Hetzner AI backend\n            const response = await fetch('https:\/\/pm.tiimiss.ba\/api\/ai\/chat', {\n                method: 'POST',\n                headers: {\n                    'Content-Type': 'application\/json',\n                },\n                body: JSON.stringify({\n                    message: message,\n                    mode: currentMode,\n                    history: conversationHistory\n                })\n            });<\/p>\n<p>            const data = await response.json();\n            addMessage(data.response, 'ai');\n            conversationHistory.push({role: 'user', content: message});\n            conversationHistory.push({role: 'assistant', content: data.response});<\/p>\n<p>        } catch (error) {\n            addMessage(\"Sorry, I'm having trouble connecting to the AI service. Please try again later.\", 'ai');\n            console.error('AI API error:', error);\n        }\n    }<\/p>\n<p>    \/\/ Add message to chat\n    function addMessage(text, sender) {\n        const messageDiv = document.createElement('div');\n        messageDiv.className = `message ${sender}-message`;\n        messageDiv.textContent = text;\n        chatMessages.appendChild(messageDiv);\n        chatMessages.scrollTop = chatMessages.scrollHeight;\n    }<\/p>\n<p>    \/\/ Event listeners\n    sendButton.addEventListener('click', sendMessage);\n    chatInput.addEventListener('keypress', function(e) {\n        if (e.key === 'Enter') sendMessage();\n    });<\/p>\n<p>    \/\/ Welcome message\n    addMessage(\"Hello! I'm your AI assistant. I can help with general questions, project management, or HR topics. Choose a mode above to get started!\", 'ai');\n});\n<\/script><\/p>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-6","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/pages\/6","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tiimiss.ba\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6"}],"version-history":[{"count":2,"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/pages\/6\/revisions"}],"predecessor-version":[{"id":16,"href":"https:\/\/tiimiss.ba\/index.php?rest_route=\/wp\/v2\/pages\/6\/revisions\/16"}],"wp:attachment":[{"href":"https:\/\/tiimiss.ba\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}