| | <!DOCTYPE html> |
| | <html lang="en"> |
| | <head> |
| | <meta charset="UTF-8"> |
| | <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| | <title>DeepSeek Chat Interface</title> |
| | <style> |
| | body { |
| | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; |
| | line-height: 1.6; |
| | margin: 0; |
| | padding: 20px; |
| | background-color: #f0f2f5; |
| | color: #1c1e21; |
| | display: flex; |
| | justify-content: center; |
| | } |
| | .container { |
| | max-width: 800px; |
| | width: 100%; |
| | background: #fff; |
| | padding: 25px; |
| | border-radius: 8px; |
| | box-shadow: 0 2px 10px rgba(0,0,0,0.1); |
| | } |
| | h1 { |
| | text-align: center; |
| | color: #333; |
| | margin-bottom: 25px; |
| | } |
| | .auth-section { |
| | text-align: right; |
| | margin-bottom: 15px; |
| | font-size: 0.9em; |
| | } |
| | .auth-section button { |
| | padding: 5px 10px; |
| | font-size: 0.9em; |
| | cursor: pointer; |
| | border: 1px solid #ddd; |
| | border-radius: 4px; |
| | background-color: #f5f5f5; |
| | margin-left: 5px; |
| | } |
| | .auth-section button:hover { |
| | background-color: #e9e9e9; |
| | } |
| | .auth-section span { |
| | color: #606770; |
| | } |
| | label { |
| | display: block; |
| | margin-bottom: 8px; |
| | font-weight: 600; |
| | color: #4b4f56; |
| | } |
| | textarea { |
| | width: calc(100% - 22px); |
| | padding: 10px; |
| | margin-bottom: 15px; |
| | border: 1px solid #ccd0d5; |
| | border-radius: 6px; |
| | font-size: 1rem; |
| | min-height: 80px; |
| | resize: vertical; |
| | } |
| | button#send-button { |
| | display: block; |
| | width: 100%; |
| | padding: 12px; |
| | background-color: #1877f2; |
| | color: white; |
| | border: none; |
| | border-radius: 6px; |
| | cursor: pointer; |
| | font-size: 1rem; |
| | font-weight: 600; |
| | transition: background-color 0.2s ease; |
| | } |
| | button#send-button:hover:not(:disabled) { |
| | background-color: #166fe5; |
| | } |
| | button#send-button:disabled { |
| | background-color: #a0c3f0; |
| | cursor: not-allowed; |
| | } |
| | #status { |
| | margin-top: 15px; |
| | padding: 10px; |
| | border-radius: 4px; |
| | font-size: 0.95em; |
| | display: none; |
| | text-align: center; |
| | } |
| | #status.info { |
| | background-color: #e7f3ff; |
| | border: 1px solid #b8d7f7; |
| | color: #1877f2; |
| | display: block; |
| | } |
| | #status.error { |
| | background-color: #fdecea; |
| | border: 1px solid #f8bbc1; |
| | color: #a94442; |
| | display: block; |
| | } |
| | #response-area { |
| | margin-top: 20px; |
| | border: 1px solid #e0e0e0; |
| | border-radius: 6px; |
| | padding: 15px; |
| | min-height: 150px; |
| | background-color: #f9f9f9; |
| | overflow-y: auto; |
| | max-height: 400px; |
| | white-space: pre-wrap; |
| | word-wrap: break-word; |
| | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; |
| | font-size: 0.9em; |
| | line-height: 1.5; |
| | } |
| | #response-area:empty::before { |
| | content: "Model's response will appear here..."; |
| | color: #999; |
| | font-style: italic; |
| | } |
| | </style> |
| | </head> |
| | <body> |
| | <div class="container"> |
| | <h1>DeepSeek Chat</h1> |
| |
|
| | <div class="auth-section"> |
| | <span id="user-info">Checking login status...</span> |
| | <button id="auth-button">Login</button> |
| | </div> |
| |
|
| | <label for="user-prompt">Your Prompt:</label> |
| | <textarea id="user-prompt" placeholder="Enter your message or instructions for the AI..."></textarea> |
| |
|
| | |
| | |
| | |
| | |
| | |
| |
|
| | <button id="send-button">Send Prompt</button> |
| |
|
| | <div id="status"></div> |
| |
|
| | <label for="response-area" style="margin-top: 20px;">AI Response:</label> |
| | <div id="response-area"></div> |
| | |
| |
|
| | </div> |
| |
|
| | <script> |
| | const userInfoSpan = document.getElementById('user-info'); |
| | const authButton = document.getElementById('auth-button'); |
| | const promptInput = document.getElementById('user-prompt'); |
| | const sendButton = document.getElementById('send-button'); |
| | const statusDiv = document.getElementById('status'); |
| | const responseArea = document.getElementById('response-area'); |
| | |
| | |
| | |
| | let isLoggedIn = false; |
| | let currentUsername = 'Guest'; |
| | |
| | |
| | async function checkLoginStatus() { |
| | try { |
| | const response = await fetch('/api/@me'); |
| | if (response.ok) { |
| | const user = await response.json(); |
| | currentUsername = user.preferred_username || user.name || 'Logged In User'; |
| | userInfoSpan.textContent = `Logged in as: ${currentUsername}`; |
| | authButton.textContent = 'Logout'; |
| | authButton.onclick = () => window.location.href = '/auth/logout'; |
| | isLoggedIn = true; |
| | } else { |
| | throw new Error('Not logged in'); |
| | } |
| | } catch (error) { |
| | userInfoSpan.textContent = 'Not logged in.'; |
| | authButton.textContent = 'Login with Hugging Face'; |
| | authButton.onclick = () => window.location.href = '/api/login'; |
| | isLoggedIn = false; |
| | } |
| | } |
| | |
| | |
| | function showStatus(message, type = 'info') { |
| | statusDiv.textContent = message; |
| | statusDiv.className = type; |
| | } |
| | |
| | function clearStatus() { |
| | statusDiv.textContent = ''; |
| | statusDiv.className = ''; |
| | statusDiv.style.display = 'none'; |
| | } |
| | |
| | |
| | sendButton.addEventListener('click', async () => { |
| | const prompt = promptInput.value.trim(); |
| | |
| | |
| | |
| | if (!prompt) { |
| | showStatus('Please enter a prompt.', 'error'); |
| | return; |
| | } |
| | |
| | |
| | responseArea.textContent = ''; |
| | clearStatus(); |
| | showStatus('Sending request and waiting for response...', 'info'); |
| | sendButton.disabled = true; |
| | |
| | const requestBody = { |
| | prompt: prompt, |
| | |
| | |
| | |
| | }; |
| | |
| | try { |
| | const response = await fetch('/api/ask-ai', { |
| | method: 'POST', |
| | headers: { |
| | 'Content-Type': 'application/json', |
| | 'Accept': 'text/plain', |
| | }, |
| | body: JSON.stringify(requestBody), |
| | }); |
| | |
| | |
| | if (!response.ok) { |
| | let errorMsg = `Error: ${response.status} ${response.statusText}`; |
| | try { |
| | |
| | const errorData = await response.json(); |
| | errorMsg = errorData.message || errorMsg; |
| | |
| | if (errorData.openLogin) { |
| | errorMsg += " Please log in."; |
| | |
| | } |
| | if (errorData.openProModal) { |
| | errorMsg += " (Credit limit likely reached)"; |
| | } |
| | } catch (e) { |
| | |
| | console.warn("Could not parse error response as JSON"); |
| | } |
| | throw new Error(errorMsg); |
| | } |
| | |
| | |
| | const reader = response.body.getReader(); |
| | const decoder = new TextDecoder(); |
| | |
| | responseArea.textContent = ''; |
| | showStatus('Receiving response...', 'info'); |
| | |
| | while (true) { |
| | const { value, done } = await reader.read(); |
| | if (done) { |
| | console.log('Stream finished.'); |
| | break; |
| | } |
| | const chunk = decoder.decode(value, { stream: true }); |
| | responseArea.textContent += chunk; |
| | |
| | responseArea.scrollTop = responseArea.scrollHeight; |
| | } |
| | clearStatus(); |
| | |
| | } catch (error) { |
| | console.error('Error fetching or streaming response:', error); |
| | showStatus(`Failed: ${error.message}`, 'error'); |
| | } finally { |
| | sendButton.disabled = false; |
| | } |
| | }); |
| | |
| | |
| | checkLoginStatus(); |
| | |
| | </script> |
| | </body> |
| | </html> |