Spaces:
Sleeping
Sleeping
File size: 7,165 Bytes
94c8770 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
{% extends "base.html" %}
{% block title %}Chat Interface - Sheikh LLM Studio{% endblock %}
{% block content %}
<div class="container">
<div class="card">
<h1><i class="fas fa-comments"></i> AI Chat Interface</h1>
<p>Chat with multiple AI models and use advanced tools</p>
</div>
<div class="card">
<div class="chat-container" style="display: grid; grid-template-columns: 1fr 300px; gap: 2rem;">
<div class="chat-messages" id="chatMessages" style="height: 500px; overflow-y: auto; border: 1px solid #e1e5e9; border-radius: 10px; padding: 1rem; background: #f8f9fa;">
<div class="welcome-message">
<div style="text-align: center; color: #666; margin-top: 2rem;">
<i class="fas fa-robot fa-3x" style="color: #667eea; margin-bottom: 1rem;"></i>
<h3>Welcome to Sheikh LLM Chat!</h3>
<p>Select a model and start chatting. You can also use tools like web search and code execution.</p>
</div>
</div>
</div>
<div class="controls-panel">
<div style="margin-bottom: 1.5rem;">
<label for="modelSelect"><strong>Select Model:</strong></label>
<select id="modelSelect" class="btn" style="width: 100%; margin-top: 0.5rem;">
<option value="mistral-small">Mistral Small (24B)</option>
<option value="mistral-large">Mistral Large</option>
<option value="mistral-7b">Mistral 7B</option>
<option value="baby-grok">Baby Grok (1.5B)</option>
</select>
</div>
<div style="margin-bottom: 1.5rem;">
<label><strong>Tools:</strong></label>
<div style="display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;">
<button class="btn" onclick="useTool('search')" style="background: #10b981;">
<i class="fas fa-search"></i> Web Search
</button>
<button class="btn" onclick="useTool('code')" style="background: #f59e0b;">
<i class="fas fa-code"></i> Code Execution
</button>
</div>
</div>
<div style="margin-bottom: 1.5rem;">
<label><strong>Parameters:</strong></label>
<div style="margin-top: 0.5rem;">
<label>Max Tokens: <span id="maxTokensValue">500</span></label>
<input type="range" id="maxTokens" min="100" max="2000" value="500" style="width: 100%; margin: 0.5rem 0;">
<label>Temperature: <span id="tempValue">0.7</span></label>
<input type="range" id="temperature" min="0" max="1" step="0.1" value="0.7" style="width: 100%; margin: 0.5rem 0;">
</div>
</div>
</div>
</div>
<div style="display: flex; gap: 1rem; margin-top: 1rem;">
<input type="text" id="messageInput" placeholder="Type your message here..." style="flex: 1; padding: 1rem; border: 1px solid #e1e5e9; border-radius: 8px;" onkeypress="if(event.key === 'Enter') sendMessage()">
<button class="btn" onclick="sendMessage()" style="padding: 1rem 2rem;">
<i class="fas fa-paper-plane"></i> Send
</button>
</div>
</div>
</div>
<script>
let chatHistory = [];
function updateSliderValues() {
document.getElementById('maxTokensValue').textContent = document.getElementById('maxTokens').value;
document.getElementById('tempValue').textContent = document.getElementById('temperature').value;
}
document.getElementById('maxTokens').addEventListener('input', updateSliderValues);
document.getElementById('temperature').addEventListener('input', updateSliderValues);
function addMessage(role, content) {
const messagesDiv = document.getElementById('chatMessages');
const messageDiv = document.createElement('div');
messageDiv.className = `message ${role}`;
messageDiv.innerHTML = `
<div style="margin: 1rem 0; padding: 1rem; border-radius: 10px; ${role === 'user' ? 'background: #667eea; color: white; margin-left: 2rem;' : 'background: white; border: 1px solid #e1e5e9; margin-right: 2rem;'}">
<strong>${role === 'user' ? 'You' : 'AI'}:</strong>
<div>${content}</div>
<small style="opacity: 0.7; font-size: 0.8rem;">${new Date().toLocaleTimeString()}</small>
</div>
`;
messagesDiv.appendChild(messageDiv);
messagesDiv.scrollTop = messagesDiv.scrollHeight;
}
async function sendMessage() {
const input = document.getElementById('messageInput');
const message = input.value.trim();
if (!message) return;
addMessage('user', message);
input.value = '';
const model = document.getElementById('modelSelect').value;
const maxTokens = document.getElementById('maxTokens').value;
const temperature = document.getElementById('temperature').value;
try {
const response = await fetch('/api/chat', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
message: message,
model: model,
max_tokens: parseInt(maxTokens),
temperature: parseFloat(temperature),
stream: false
})
});
const data = await response.json();
if (response.ok && data.status === 'success') {
addMessage('assistant', data.response);
} else {
addMessage('assistant', `Error: ${data.detail || 'Unknown error'}`);
}
} catch (error) {
addMessage('assistant', `Connection error: ${error.message}`);
}
}
async function useTool(tool) {
const message = prompt(`Enter parameters for ${tool}:`);
if (!message) return;
try {
const endpoint = tool === 'search' ? '/api/tools/search' : '/api/tools/code';
const response = await fetch(endpoint, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
tool: tool === 'search' ? 'web_search' : 'execute_python',
parameters: { query: message, code: message }
})
});
const data = await response.json();
addMessage('assistant', `Tool result (${tool}): ${JSON.stringify(data, null, 2)}`);
} catch (error) {
addMessage('assistant', `Tool error: ${error.message}`);
}
}
updateSliderValues();
document.getElementById('messageInput').focus();
</script>
{% endblock %}
|