chore: update 1 file(s)

This commit is contained in:
mike
2025-12-28 04:20:00 +01:00
parent c81958d000
commit cea5d50fa6

110
chatv2.js
View File

@@ -15,11 +15,29 @@ const BACKENDS = {
name: 'Ollama (192.168.1.159:8081)' name: 'Ollama (192.168.1.159:8081)'
} }
} }
const IS_PRODUCTION = window.location.hostname === 'jarvis-lan.appmodel.nl' const IS_PRODUCTION = window.location.hostname === 'jarvis-lan.appmodel.nl'
const API_KEY = 'not-needed' const API_KEY = 'not-needed'
const MAX_CHAT_HISTORY = 50 const MAX_CHAT_HISTORY = 50
const welcomeMessage = `# Welcome to LM Studio Chat!
I now support **full conversation history**, **real-time streaming responses** and **dark, readable text formatting**.
## Features:
1. **Full Chat History** - Complete conversation context is now sent to the AI
2. **Smart History Management** - Automatically keeps the last ${ MAX_CHAT_HISTORY } messages
3. **Streaming Mode** (enabled by default) - Watch responses appear word-by-word
4. **Markdown Rendering** - Proper formatting for code, lists, tables, and more
5. **Readable Dark Text** - No more eye strain from light gray text
## Try it out:
- Ask follow-up questions that reference earlier messages
- Have a multi-turn conversation with full context
- Ask "what did I just ask?" to test history retention
- Watch the streaming response in real-time!
> *Tip: You can toggle streaming and markdown using the checkboxes below.*`
let currentBackend = 'plato' let currentBackend = 'plato'
let currentModel = null let currentModel = null
let availableModels = [] let availableModels = []
@@ -454,51 +472,53 @@ async function handleStreamingResponse(userMessage) {
} }
async function handleNonStreamingResponse(userMessage) { async function handleNonStreamingResponse(userMessage) {
const typingIndicator = showTypingIndicator() try {
const typingIndicator = showTypingIndicator()
if (!currentModel && availableModels.length > 0) { if (!currentModel && availableModels.length > 0) {
currentModel = availableModels[0].id currentModel = availableModels[0].id
document.getElementById('modelSelector').value = currentModel document.getElementById('modelSelector').value = currentModel
}
const requestBody = {
model : currentModel || 'local-model',
messages : getApiMessages(),
stream : false,
temperature: 0.7,
max_tokens : 2000
}
const response = await fetch(`${ getApiUrl() }/chat/completions`, {
method : 'POST',
headers: {
'Content-Type' : 'application/json',
'Authorization': `Bearer ${ API_KEY }`
},
body : JSON.stringify(requestBody)
})
if (!response.ok) {
throw new Error(`API Error: ${ response.status } ${ response.statusText }`)
}
const data = await response.json()
removeTypingIndicator(typingIndicator)
if (data.choices && data.choices.length > 0) {
const assistantReply = data.choices[0].message.content
addMessage('assistant', assistantReply, markdownToggle.checked)
} else {
addMessage('assistant', 'No response generated.', false)
}
} catch (error) {
console.error('Error:', error)
removeTypingIndicator(typingIndicator)
addMessage('assistant', `Error: ${ error.message }`, false)
} finally {
sendBtn.disabled = false
userInput.focus()
} }
const requestBody = {
model : currentModel || 'local-model',
messages : getApiMessages(),
stream : false,
temperature: 0.7,
max_tokens : 2000
}
const response = await fetch(`${ getApiUrl() }/chat/completions`, {
method : 'POST',
headers: {
'Content-Type' : 'application/json',
'Authorization': `Bearer ${ API_KEY }`
},
body : JSON.stringify(requestBody)
})
if (!response.ok) {
throw new Error(`API Error: ${ response.status } ${ response.statusText }`)
}
const data = await response.json()
removeTypingIndicator(typingIndicator)
if (data.choices && data.choices.length > 0) {
const assistantReply = data.choices[0].message.content
addMessage('assistant', assistantReply, markdownToggle.checked)
} else {
addMessage('assistant', 'No response generated.', false)
}
} catch (error) {
console.error('Error:', error)
removeTypingIndicator(typingIndicator)
addMessage('assistant', `Error: ${ error.message }`, false)
} finally {
sendBtn.disabled = false
userInput.focus()
} }
function stopStream() { function stopStream() {
@@ -559,7 +579,7 @@ window.onload = () => {
function resetChat() { function resetChat() {
chatHistory = [] chatHistory = []
chatLog.innerHTML = '' chatLog.innerHTML = welcomeMessage
localStorage.setItem('chatHistory', JSON.stringify(chatHistory)) localStorage.setItem('chatHistory', JSON.stringify(chatHistory))
} }