Compare commits
27 Commits
3c7c4d4233
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a649a9475 | ||
|
|
11f0f8fbee | ||
|
|
a93f8def81 | ||
|
|
2afa812eea | ||
|
|
a94af25367 | ||
|
|
c551925e86 | ||
|
|
843bf78727 | ||
|
|
5805f1e81c | ||
|
|
19acb7ef15 | ||
|
|
ca941dcc6f | ||
|
|
7e7439d5c2 | ||
|
|
2b6a0c866f | ||
|
|
7b9947da7e | ||
|
|
267e155ad1 | ||
|
|
d6fdb7372d | ||
|
|
8ab0ae4a4d | ||
|
|
2cd98bb5db | ||
|
|
a6c9534d09 | ||
|
|
839fb7e57a | ||
|
|
a054898b34 | ||
|
|
cea5d50fa6 | ||
|
|
c81958d000 | ||
|
|
2e3f811f25 | ||
|
|
5d6ccd0087 | ||
|
|
13a0209e05 | ||
|
|
4d5467753b | ||
|
|
db0811e8a7 |
@@ -1 +1 @@
|
||||
model: /models/Qwen/Qwen2.5-Coder-32B-Instruct-GGUF/qwen2.5-coder-32b-instruct-q4_k_m.gguf
|
||||
model: /models/qwen2.5-coder-32b-instruct-q4_k_m.gguf
|
||||
@@ -1,4 +1,4 @@
|
||||
- name: /models/Qwen/Qwen2.5-Coder-32B-Instruct-GGUF/qwen2.5-coder-32b-instruct-q4_k_m.gguf
|
||||
- name: /models/qwen2.5-coder-32b-instruct-q4_k_m.gguf
|
||||
extra_params:
|
||||
num_ctx: 16384
|
||||
num_threads: 8
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,3 +1,5 @@
|
||||
.idea/
|
||||
.env
|
||||
.aider*
|
||||
node_modules/
|
||||
dist/
|
||||
16
Dockerfile
16
Dockerfile
@@ -1,5 +1,15 @@
|
||||
FROM node:20-alpine AS builder
|
||||
WORKDIR /app
|
||||
COPY package*.json ./
|
||||
RUN npm ci
|
||||
COPY www/ www/
|
||||
COPY webpack.config.js ./
|
||||
COPY robots.txt ./
|
||||
COPY site.webmanifest ./
|
||||
RUN mkdir -p /usr/share/nginx/html
|
||||
RUN npm run build
|
||||
FROM nginx:alpine
|
||||
COPY index.html /usr/share/nginx/html/
|
||||
COPY 404.html /usr/share/nginx/html/
|
||||
COPY favicon.ico /usr/share/nginx/html/
|
||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
CMD ["nginx", "-g", "daemon off;"]
|
||||
|
||||
63
index.html
63
index.html
@@ -1,63 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chat</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="chatContainer">
|
||||
<div id="header">
|
||||
<div>Chat with Streaming</div>
|
||||
<div style="font-size: 0.9em; opacity: 0.9; display: flex; align-items: center; gap: 15px; flex-wrap: wrap;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span>Backend:</span>
|
||||
<select id="backendSelector" style="padding: 4px 8px; border-radius: 4px; border: 1px solid #444; background: #2a2a2a; color: #e0e0e0;">
|
||||
<option value="ollama">Ollama (192.168.1.159:8081)</option>
|
||||
<option value="plato">Plato (192.168.1.74)</option>
|
||||
<option value="stoic">Stoic (192.168.1.159)</option>
|
||||
</select>
|
||||
</div>
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span>Model:</span>
|
||||
<select id="modelSelector" style="padding: 4px 8px; border-radius: 4px; border: 1px solid #444; background: #2a2a2a; color: #e0e0e0; min-width: 200px;">
|
||||
<option value="">Loading models...</option>
|
||||
</select>
|
||||
</div>
|
||||
<code id="backendDisplay" style="font-size: 0.85em;"></code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="chatLog"></div>
|
||||
|
||||
<div id="inputArea">
|
||||
<textarea
|
||||
id="userInput"
|
||||
placeholder="Type your message here... (Shift+Enter for new line, Enter to send)"
|
||||
rows="1"
|
||||
oninput="autoResize(this)"
|
||||
></textarea>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<div class="controls">
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" id="streamToggle" checked> Streaming
|
||||
</label>
|
||||
<label style="margin-left: 15px;">
|
||||
<input type="checkbox" id="markdownToggle" checked> Markdown
|
||||
</label>
|
||||
</div>
|
||||
<div id="modelInfo">Model: <span id="modelName">unknown</span></div>
|
||||
</div>
|
||||
<button id="sendBtn">Send</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="chatv2.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
34
nginx.conf
34
nginx.conf
@@ -1,9 +1,14 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name localhost;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
|
||||
# Disable caching for all responses during debugging
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate" always;
|
||||
add_header Pragma "no-cache" always;
|
||||
add_header Expires "0" always;
|
||||
|
||||
# Favicon
|
||||
location = /favicon.ico {
|
||||
try_files /favicon.ico =204;
|
||||
@@ -11,6 +16,14 @@ server {
|
||||
log_not_found off;
|
||||
}
|
||||
|
||||
# Serve shared JS and CSS directories at root
|
||||
location /js/ {
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location /css/ {
|
||||
try_files $uri =404;
|
||||
}
|
||||
# Custom 404 page
|
||||
error_page 404 /404.html;
|
||||
location = /404.html {
|
||||
@@ -27,9 +40,11 @@ server {
|
||||
try_files /index.html =404;
|
||||
}
|
||||
|
||||
|
||||
|
||||
# Proxy API requests to plato.lan (192.168.1.74)
|
||||
location /api/plato/ {
|
||||
proxy_pass http://192.168.1.74:1234/v1/;
|
||||
proxy_pass http://192.168.1.74:8080/v1/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
@@ -38,7 +53,7 @@ server {
|
||||
|
||||
# Proxy API requests to stoic.lan (192.168.1.159)
|
||||
location /api/stoic/ {
|
||||
proxy_pass http://192.168.1.159:1234/v1/;
|
||||
proxy_pass http://192.168.1.159:8081/v1/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
@@ -56,15 +71,26 @@ server {
|
||||
|
||||
# Default /api/ points to plato for backwards compatibility
|
||||
location /api/ {
|
||||
proxy_pass http://192.168.1.74:1234/v1/;
|
||||
proxy_pass http://192.168.1.74:8080/v1/;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
# Cache static assets with content hash - minimal caching
|
||||
location ~* \.(js|css)$ {
|
||||
expires 1s; # 1 second for rapid iteration
|
||||
add_header Cache-Control "public, max-age=1, must-revalidate" always;
|
||||
}
|
||||
# Cache images and icons - short caching
|
||||
location ~* \.(ico|png|svg|jpg|jpeg|gif|webp)$ {
|
||||
expires 5s; # 5 seconds, adjust as needed
|
||||
add_header Cache-Control "public, max-age=5, must-revalidate" always;
|
||||
}
|
||||
|
||||
# Gzip compression for better performance
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json;
|
||||
}
|
||||
|
||||
5141
package-lock.json
generated
Normal file
5141
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
32
package.json
Normal file
32
package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "jarvis-lan",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"keywords": [
|
||||
""
|
||||
],
|
||||
"license": "",
|
||||
"author": "",
|
||||
"scripts": {
|
||||
"build": "webpack --mode production",
|
||||
"build:dev": "webpack --mode development",
|
||||
"watch": "webpack --mode development --watch",
|
||||
"dev": "webpack serve --mode development",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"clean-webpack-plugin": "^4.0.0",
|
||||
"copy-webpack-plugin": "^13.0.1",
|
||||
"css-loader": "^7.1.2",
|
||||
"html-webpack-plugin": "^5.6.5",
|
||||
"mini-css-extract-plugin": "^2.9.4",
|
||||
"webpack": "^5.104.0",
|
||||
"webpack-cli": "^6.0.1",
|
||||
"webpack-dev-server": "^5.2.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"jsdom": "^27.3.0"
|
||||
}
|
||||
}
|
||||
5
robots.txt
Normal file
5
robots.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
# www.robotstxt.org/
|
||||
|
||||
# Allow crawling of all content
|
||||
User-agent: *
|
||||
Disallow:
|
||||
12
site.webmanifest
Normal file
12
site.webmanifest
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"short_name": "",
|
||||
"name": "",
|
||||
"icons": [{
|
||||
"src": "icon.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
}],
|
||||
"start_url": "/?utm_source=homescreen",
|
||||
"background_color": "#fafafa",
|
||||
"theme_color": "#fafafa"
|
||||
}
|
||||
91
webpack.config.js
Normal file
91
webpack.config.js
Normal file
@@ -0,0 +1,91 @@
|
||||
import path from 'path'
|
||||
import { fileURLToPath } from 'url'
|
||||
import HtmlWebpackPlugin from 'html-webpack-plugin'
|
||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
||||
import CopyWebpackPlugin from 'copy-webpack-plugin'
|
||||
import { CleanWebpackPlugin } from 'clean-webpack-plugin'
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url)
|
||||
const __dirname = path.dirname(__filename)
|
||||
|
||||
export default (env, argv) => {
|
||||
const isProduction = argv.mode === 'production'
|
||||
|
||||
return {
|
||||
mode: isProduction ? 'production' : 'development',
|
||||
|
||||
entry: {
|
||||
www: ['./www/chatv3.js', './www/style2.css']
|
||||
},
|
||||
|
||||
output: {
|
||||
path : path.resolve(__dirname, 'dist'),
|
||||
filename : isProduction ? 'js/[name].[contenthash:8].js' : 'js/[name].js',
|
||||
publicPath: isProduction ? '../' : '/'
|
||||
},
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.css$/,
|
||||
use : [
|
||||
MiniCssExtractPlugin.loader,
|
||||
'css-loader'
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new CleanWebpackPlugin(),
|
||||
|
||||
new MiniCssExtractPlugin({
|
||||
filename: isProduction ? 'css/[name].[contenthash:8].css' : 'css/[name].css'
|
||||
}),
|
||||
|
||||
new HtmlWebpackPlugin({
|
||||
template: './www/index.html',
|
||||
filename: 'index.html',
|
||||
chunks : ['www'],
|
||||
inject : 'body',
|
||||
minify : isProduction
|
||||
}),
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
{ from: 'www/404.html', to: '404.html' },
|
||||
{ from: 'www/favicon.ico', to: 'favicon.ico' },
|
||||
{ from: 'www/icon.svg', to: 'icon.svg' },
|
||||
{ from: 'robots.txt', to: 'robots.txt', noErrorOnMissing: true },
|
||||
{ from: 'site.webmanifest', to: 'site.webmanifest', noErrorOnMissing: true }
|
||||
]
|
||||
})
|
||||
],
|
||||
|
||||
optimization: {
|
||||
moduleIds : 'deterministic',
|
||||
runtimeChunk: 'single',
|
||||
splitChunks : {
|
||||
cacheGroups: {
|
||||
vendor: {
|
||||
test : /[\\/]node_modules[\\/]/,
|
||||
name : 'vendors',
|
||||
chunks: 'all'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
devtool: isProduction ? 'source-map' : 'eval-source-map',
|
||||
|
||||
devServer: {
|
||||
host : '0.0.0.0',
|
||||
port : 8082,
|
||||
allowedHosts : 'all',
|
||||
hot : true,
|
||||
devMiddleware: { publicPath: '/' },
|
||||
static : [
|
||||
{ directory: path.resolve(__dirname, 'dist') }
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,130 +1,200 @@
|
||||
// Configuration
|
||||
import './style2.css'
|
||||
|
||||
const BACKENDS = {
|
||||
plato : {
|
||||
prod: '/api/plato',
|
||||
dev : 'http://192.168.1.74:1234/v1', // Removed trailing space
|
||||
dev : 'http://192.168.1.74:8080/v1',
|
||||
name: 'Plato (192.168.1.74)'
|
||||
},
|
||||
stoic : {
|
||||
prod: '/api/stoic',
|
||||
dev : 'http://192.168.1.159:1234/v1', // Removed trailing space
|
||||
dev : 'http://192.168.1.159:1234/v1',
|
||||
name: 'Stoic (192.168.1.159)'
|
||||
},
|
||||
ollama: {
|
||||
prod: '/api/ollama',
|
||||
dev : 'http://192.168.1.159:8081/v1', // Removed trailing space
|
||||
dev : 'http://192.168.1.159:8081/v1',
|
||||
name: 'Ollama (192.168.1.159:8081)'
|
||||
}
|
||||
}
|
||||
|
||||
const IS_PRODUCTION = window.location.hostname === 'jarvis-lan.appmodel.nl'
|
||||
const API_KEY = 'not-needed'
|
||||
const MAX_CHAT_HISTORY = 50 // Maximum messages to keep in history
|
||||
const MAX_CHAT_HISTORY = 50
|
||||
|
||||
// Global state
|
||||
let currentBackend = 'plato'
|
||||
let currentModel = null
|
||||
let availableModels = []
|
||||
let currentBackendModel = null
|
||||
let availableBackendModels = []
|
||||
let currentStreamController = null
|
||||
let isStreaming = false
|
||||
let chatHistory = [] // Stores conversation history
|
||||
let chatHistory = JSON.parse(localStorage.getItem('chatHistory')) || []
|
||||
|
||||
// ✅ FIX: Generate unique IDs and validate message structure
|
||||
chatHistory = chatHistory.map((message, index) => ({
|
||||
role : message.role || 'user',
|
||||
content : message.content || '',
|
||||
markdown : message.markdown || false,
|
||||
messageId: message.messageId || `msg-${ Date.now() }-${ index }`
|
||||
})).filter(msg => msg.content && typeof msg.content === 'string')
|
||||
|
||||
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.*`
|
||||
|
||||
// ✅ NEW: Robust parser for backend:model format
|
||||
function splitBackendModel(value) {
|
||||
if (!value || value === ':') {
|
||||
return { backendKey: '', model: '' }
|
||||
}
|
||||
|
||||
const colonIndex = value.indexOf(':')
|
||||
if (colonIndex === -1) {
|
||||
return { backendKey: value, model: '' }
|
||||
}
|
||||
|
||||
return {
|
||||
backendKey: value.substring(0, colonIndex),
|
||||
model : value.substring(colonIndex + 1)
|
||||
}
|
||||
}
|
||||
|
||||
// Get current API URL based on selected backend
|
||||
function getApiUrl() {
|
||||
const backend = BACKENDS[currentBackend]
|
||||
const { backendKey, model } = splitBackendModel(currentBackendModel)
|
||||
const effectiveBackendKey = backendKey || 'plato'
|
||||
const backend = BACKENDS[effectiveBackendKey]
|
||||
|
||||
if (!backend) {
|
||||
throw new Error(`Invalid backend: '${ effectiveBackendKey }'`)
|
||||
}
|
||||
|
||||
return IS_PRODUCTION ? backend.prod : backend.dev
|
||||
}
|
||||
|
||||
// Update backend display
|
||||
function updateBackendDisplay() {
|
||||
const backend = BACKENDS[currentBackend]
|
||||
function updateBackendModelDisplay() {
|
||||
const { backendKey, model } = splitBackendModel(currentBackendModel)
|
||||
const backend = BACKENDS[backendKey]
|
||||
if (!backend) return
|
||||
|
||||
const displayText = IS_PRODUCTION
|
||||
? `${ backend.prod } ? ${ backend.name }`
|
||||
? `${ backend.prod } - ${ backend.name }`
|
||||
: backend.dev
|
||||
document.getElementById('backendDisplay').textContent = displayText
|
||||
const displayElement = document.getElementById('backendDisplay')
|
||||
if (displayElement) {
|
||||
displayElement.textContent = `${ displayText } - Model: ${ model || 'None' }`
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch available models from backend
|
||||
async function fetchModels() {
|
||||
async function fetchBackendModels() {
|
||||
const selector = document.getElementById('backendModelSelector')
|
||||
let allModels = []
|
||||
|
||||
for (const [backendKey, backendConfig] of Object.entries(BACKENDS)) {
|
||||
try {
|
||||
const response = await fetch(`${ getApiUrl() }/models`)
|
||||
const apiUrl = IS_PRODUCTION ? backendConfig.prod : backendConfig.dev
|
||||
console.log(`Fetching models from ${ backendKey }: ${ apiUrl }`)
|
||||
|
||||
const response = await fetch(`${ apiUrl }/models`, {
|
||||
signal: AbortSignal.timeout(5000) // 5 second timeout
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
availableModels = data.data || []
|
||||
populateModelSelector()
|
||||
|
||||
// Auto-select first model if none selected
|
||||
if (!currentModel && availableModels.length > 0) {
|
||||
currentModel = availableModels[0].id
|
||||
document.getElementById('modelSelector').value = currentModel
|
||||
if (data.data && Array.isArray(data.data)) {
|
||||
const models = data.data.map(model => ({
|
||||
backend: backendKey,
|
||||
model : model.id
|
||||
}))
|
||||
allModels = [...allModels, ...models]
|
||||
}
|
||||
} else {
|
||||
console.error('Failed to fetch models:', response.statusText)
|
||||
document.getElementById('modelSelector').innerHTML = '<option value="">Error loading models</option>'
|
||||
console.error(`Failed to fetch models from ${ backendKey }: ${ response.status } ${ response.statusText }`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching models:', error)
|
||||
document.getElementById('modelSelector').innerHTML = '<option value="">Error loading models</option>'
|
||||
console.error(`Error fetching models from ${ backendKey }:`, error)
|
||||
}
|
||||
}
|
||||
|
||||
// Populate model selector dropdown
|
||||
function populateModelSelector() {
|
||||
const selector = document.getElementById('modelSelector')
|
||||
if (availableModels.length === 0) {
|
||||
availableBackendModels = allModels
|
||||
|
||||
if (selector) {
|
||||
if (availableBackendModels.length === 0) {
|
||||
selector.innerHTML = '<option value="">No models available (check backends)</option>'
|
||||
} else {
|
||||
populateBackendModelSelector()
|
||||
|
||||
// Auto-select if no valid model is set
|
||||
const hasModel = currentBackendModel && currentBackendModel.includes(':') && currentBackendModel.split(':')[1]
|
||||
if (!hasModel && availableBackendModels.length > 0) {
|
||||
currentBackendModel = `${ availableBackendModels[0].backend }:${ availableBackendModels[0].model }`
|
||||
selector.value = currentBackendModel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
updateBackendModelDisplay()
|
||||
}
|
||||
|
||||
function populateBackendModelSelector() {
|
||||
const selector = document.getElementById('backendModelSelector')
|
||||
if (!selector) return
|
||||
|
||||
if (availableBackendModels.length === 0) {
|
||||
selector.innerHTML = '<option value="">No models available</option>'
|
||||
return
|
||||
}
|
||||
|
||||
selector.innerHTML = availableModels.map(model =>
|
||||
`<option value="${ model.id }">${ model.id }</option>`
|
||||
selector.innerHTML = availableBackendModels.map(backendModel =>
|
||||
`<option value="${ backendModel.backend }:${ backendModel.model }">${ BACKENDS[backendModel.backend].name } - ${ backendModel.model }</option>`
|
||||
).join('')
|
||||
|
||||
if (currentModel) {
|
||||
selector.value = currentModel
|
||||
if (currentBackendModel && selector.querySelector(`option[value="${ currentBackendModel }"]`)) {
|
||||
selector.value = currentBackendModel
|
||||
} else if (availableBackendModels.length > 0) {
|
||||
// If current selection is invalid, reset to first available
|
||||
currentBackendModel = `${ availableBackendModels[0].backend }:${ availableBackendModels[0].model }`
|
||||
selector.value = currentBackendModel
|
||||
}
|
||||
}
|
||||
|
||||
// Get formatted messages for API (excludes UI-specific properties)
|
||||
function getApiMessages() {
|
||||
// Get last N messages and format for API
|
||||
return chatHistory.slice(-MAX_CHAT_HISTORY).map(({ role, content }) => ({
|
||||
role,
|
||||
content
|
||||
}))
|
||||
}
|
||||
|
||||
// Trim chat history if it exceeds maximum
|
||||
function trimChatHistory() {
|
||||
if (chatHistory.length > MAX_CHAT_HISTORY) {
|
||||
chatHistory = chatHistory.slice(-MAX_CHAT_HISTORY)
|
||||
console.log(`Chat history trimmed to ${ MAX_CHAT_HISTORY } messages`)
|
||||
localStorage.setItem('chatHistory', JSON.stringify(chatHistory))
|
||||
}
|
||||
}
|
||||
|
||||
// Handle backend and model selection changes
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const backendSelector = document.getElementById('backendSelector')
|
||||
const modelSelector = document.getElementById('modelSelector')
|
||||
const backendModelSelector = document.getElementById('backendModelSelector')
|
||||
|
||||
backendSelector.value = currentBackend
|
||||
updateBackendDisplay()
|
||||
fetchModels()
|
||||
|
||||
backendSelector.addEventListener('change', (e) => {
|
||||
currentBackend = e.target.value
|
||||
updateBackendDisplay()
|
||||
console.log('Backend switched to:', currentBackend, '?', getApiUrl())
|
||||
fetchModels() // Reload models for new backend
|
||||
if (backendModelSelector) {
|
||||
backendModelSelector.addEventListener('change', (e) => {
|
||||
currentBackendModel = e.target.value
|
||||
updateBackendModelDisplay()
|
||||
fetchBackendModels()
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
modelSelector.addEventListener('change', (e) => {
|
||||
currentModel = e.target.value
|
||||
console.log('Model selected:', currentModel)
|
||||
})
|
||||
})
|
||||
|
||||
// DOM Elements
|
||||
const chatLog = document.getElementById('chatLog')
|
||||
const userInput = document.getElementById('userInput')
|
||||
const sendBtn = document.getElementById('sendBtn')
|
||||
@@ -132,7 +202,6 @@ const streamToggle = document.getElementById('streamToggle')
|
||||
const markdownToggle = document.getElementById('markdownToggle')
|
||||
const modelNameSpan = document.getElementById('modelName')
|
||||
|
||||
// Initialize marked with options
|
||||
marked.setOptions({
|
||||
gfm : true,
|
||||
breaks : true,
|
||||
@@ -145,14 +214,12 @@ marked.setOptions({
|
||||
}
|
||||
})
|
||||
|
||||
// Auto-resize textarea
|
||||
function autoResize(textarea) {
|
||||
window.autoResize = function autoResize(textarea) {
|
||||
textarea.style.height = 'auto'
|
||||
textarea.style.height = Math.min(textarea.scrollHeight, 300) + 'px'
|
||||
}
|
||||
|
||||
// Add message to chat
|
||||
function addMessage(role, content, markdown = false, messageId = null) {
|
||||
function addMessage(role, content, markdown = false, messageId = null, saveToHistory = true) {
|
||||
const messageDiv = document.createElement('div')
|
||||
messageDiv.className = `message message-${ role }`
|
||||
if (messageId) {
|
||||
@@ -164,7 +231,7 @@ function addMessage(role, content, markdown = false, messageId = null) {
|
||||
|
||||
const avatar = document.createElement('div')
|
||||
avatar.className = `avatar ${ role }-avatar`
|
||||
avatar.textContent = role === 'user' ? '?' : '?'
|
||||
avatar.textContent = role === 'user' ? '👤' : '🤖'
|
||||
|
||||
const name = document.createElement('span')
|
||||
name.textContent = role === 'user' ? 'You' : 'Assistant'
|
||||
@@ -176,10 +243,8 @@ function addMessage(role, content, markdown = false, messageId = null) {
|
||||
|
||||
if (markdown && role === 'assistant' && markdownToggle.checked) {
|
||||
contentDiv.className = 'markdown-content'
|
||||
// Parse thinking tags before markdown
|
||||
const processedContent = parseThinkingTags(content)
|
||||
contentDiv.innerHTML = marked.parse(processedContent)
|
||||
// Apply syntax highlighting if hljs is available
|
||||
if (window.hljs) {
|
||||
setTimeout(() => {
|
||||
contentDiv.querySelectorAll('pre code').forEach((block) => {
|
||||
@@ -188,34 +253,33 @@ function addMessage(role, content, markdown = false, messageId = null) {
|
||||
}, 0)
|
||||
}
|
||||
} else {
|
||||
// Parse thinking tags for non-markdown too
|
||||
const processedContent = parseThinkingTags(content)
|
||||
contentDiv.innerHTML = processedContent
|
||||
contentDiv.style.whiteSpace = 'pre-wrap'
|
||||
contentDiv.style.padding = '8px 0'
|
||||
contentDiv.style.color = '#2d3339'
|
||||
contentDiv.style.color = '#e0e0e0'
|
||||
}
|
||||
|
||||
messageDiv.appendChild(headerDiv)
|
||||
messageDiv.appendChild(contentDiv)
|
||||
if (chatLog) {
|
||||
chatLog.appendChild(messageDiv)
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
}
|
||||
|
||||
// Store message in history (excluding UI-specific properties)
|
||||
if (saveToHistory) {
|
||||
chatHistory.push({ role, content, markdown, messageId })
|
||||
|
||||
// Trim history if it gets too long
|
||||
trimChatHistory()
|
||||
localStorage.setItem('chatHistory', JSON.stringify(chatHistory))
|
||||
}
|
||||
|
||||
return contentDiv
|
||||
}
|
||||
|
||||
// Parse [THINK] tags and create collapsible sections
|
||||
function parseThinkingTags(content) {
|
||||
let result = content
|
||||
let thinkingCounter = 0
|
||||
|
||||
// Handle complete [THINK]...[/THINK] blocks
|
||||
const completeThinkRegex = /\[THINK\]([\s\S]*?)\[\/THINK\]/gi
|
||||
result = result.replace(completeThinkRegex, (match, thinkContent) => {
|
||||
thinkingCounter++
|
||||
@@ -229,7 +293,6 @@ function parseThinkingTags(content) {
|
||||
</div>`
|
||||
})
|
||||
|
||||
// Handle incomplete [THINK] blocks (still streaming)
|
||||
const incompleteThinkRegex = /\[THINK\]([\s\S]*?)$/gi
|
||||
result = result.replace(incompleteThinkRegex, (match, thinkContent) => {
|
||||
thinkingCounter++
|
||||
@@ -246,7 +309,6 @@ function parseThinkingTags(content) {
|
||||
return result
|
||||
}
|
||||
|
||||
// Toggle thinking section visibility
|
||||
window.toggleThinking = function(id) {
|
||||
const content = document.getElementById(id)
|
||||
const toggle = document.getElementById(id + '-toggle')
|
||||
@@ -257,14 +319,11 @@ window.toggleThinking = function(id) {
|
||||
}
|
||||
}
|
||||
|
||||
// Update message content (for streaming)
|
||||
function updateMessageContent(contentDiv, newContent, markdown = false, role) {
|
||||
// Parse thinking tags first
|
||||
const processedContent = parseThinkingTags(newContent)
|
||||
|
||||
if (markdown && role === 'assistant' && markdownToggle.checked) {
|
||||
if (markdown && role === 'assistant' && markdownToggle && markdownToggle.checked) {
|
||||
contentDiv.innerHTML = marked.parse(processedContent)
|
||||
// Apply syntax highlighting if hljs is available
|
||||
if (window.hljs) {
|
||||
setTimeout(() => {
|
||||
contentDiv.querySelectorAll('pre code').forEach((block) => {
|
||||
@@ -273,11 +332,16 @@ function updateMessageContent(contentDiv, newContent, markdown = false, role) {
|
||||
}, 0)
|
||||
}
|
||||
} else {
|
||||
contentDiv.textContent = newContent
|
||||
contentDiv.innerHTML = processedContent
|
||||
contentDiv.style.whiteSpace = 'pre-wrap'
|
||||
contentDiv.style.padding = '8px 0'
|
||||
contentDiv.style.color = '#e0e0e0'
|
||||
}
|
||||
if (chatLog) {
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
}
|
||||
}
|
||||
|
||||
// Show typing indicator
|
||||
function showTypingIndicator() {
|
||||
const typingDiv = document.createElement('div')
|
||||
typingDiv.id = 'typingIndicator'
|
||||
@@ -288,7 +352,7 @@ function showTypingIndicator() {
|
||||
|
||||
const avatar = document.createElement('div')
|
||||
avatar.className = 'avatar assistant-avatar'
|
||||
avatar.textContent = '?'
|
||||
avatar.textContent = '🤖'
|
||||
|
||||
const name = document.createElement('span')
|
||||
name.textContent = 'Assistant'
|
||||
@@ -307,26 +371,25 @@ function showTypingIndicator() {
|
||||
|
||||
typingDiv.appendChild(headerDiv)
|
||||
typingDiv.appendChild(dotsDiv)
|
||||
if (chatLog) {
|
||||
chatLog.appendChild(typingDiv)
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
}
|
||||
|
||||
return typingDiv
|
||||
}
|
||||
|
||||
// Remove typing indicator
|
||||
function removeTypingIndicator(typingDiv) {
|
||||
if (typingDiv && typingDiv.parentNode) {
|
||||
typingDiv.parentNode.removeChild(typingDiv)
|
||||
}
|
||||
}
|
||||
|
||||
// Handle streaming response
|
||||
async function handleStreamingResponse(userMessage) {
|
||||
const messageId = 'msg-' + Date.now()
|
||||
let accumulatedContent = ''
|
||||
let contentDiv = null
|
||||
|
||||
// Create initial empty message
|
||||
const messageDiv = document.createElement('div')
|
||||
messageDiv.className = 'message message-assistant'
|
||||
messageDiv.id = messageId
|
||||
@@ -336,7 +399,7 @@ async function handleStreamingResponse(userMessage) {
|
||||
|
||||
const avatar = document.createElement('div')
|
||||
avatar.className = 'avatar assistant-avatar'
|
||||
avatar.textContent = '?'
|
||||
avatar.textContent = '🤖'
|
||||
|
||||
const name = document.createElement('span')
|
||||
name.textContent = 'Assistant'
|
||||
@@ -349,25 +412,28 @@ async function handleStreamingResponse(userMessage) {
|
||||
|
||||
messageDiv.appendChild(headerDiv)
|
||||
messageDiv.appendChild(contentDiv)
|
||||
if (chatLog) {
|
||||
chatLog.appendChild(messageDiv)
|
||||
}
|
||||
|
||||
// Add streaming cursor
|
||||
const cursorSpan = document.createElement('span')
|
||||
cursorSpan.className = 'streaming-cursor'
|
||||
contentDiv.appendChild(cursorSpan)
|
||||
|
||||
// ✅ FIX: Create AbortController BEFORE fetch
|
||||
currentStreamController = new AbortController()
|
||||
isStreaming = true
|
||||
|
||||
try {
|
||||
// Auto-select first model if none selected
|
||||
if (!currentModel && availableModels.length > 0) {
|
||||
currentModel = availableModels[0].id
|
||||
document.getElementById('modelSelector').value = currentModel
|
||||
}
|
||||
const { backendKey, model } = splitBackendModel(currentBackendModel)
|
||||
const selectedModel = model || availableBackendModels[0]?.model || 'local-model'
|
||||
|
||||
const requestBody = {
|
||||
model : currentModel || 'local-model',
|
||||
messages : getApiMessages(), // Send full chat history
|
||||
model : selectedModel,
|
||||
messages : getApiMessages(),
|
||||
stream : true,
|
||||
temperature : 0.7,
|
||||
repeat_penalty: 1.1,
|
||||
max_tokens : 2000
|
||||
}
|
||||
|
||||
@@ -377,7 +443,8 @@ async function handleStreamingResponse(userMessage) {
|
||||
'Content-Type' : 'application/json',
|
||||
'Authorization': `Bearer ${ API_KEY }`
|
||||
},
|
||||
body : JSON.stringify(requestBody)
|
||||
body : JSON.stringify(requestBody),
|
||||
signal : currentStreamController.signal // ✅ Now works correctly
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
@@ -387,13 +454,9 @@ async function handleStreamingResponse(userMessage) {
|
||||
const reader = response.body.getReader()
|
||||
const decoder = new TextDecoder()
|
||||
|
||||
isStreaming = true
|
||||
currentStreamController = new AbortController()
|
||||
|
||||
// Debounce DOM updates to reduce stutter
|
||||
let updateScheduled = false
|
||||
let lastUpdate = Date.now()
|
||||
const MIN_UPDATE_INTERVAL = 100 // ms, update at most every 100ms
|
||||
const MIN_UPDATE_INTERVAL = 100
|
||||
|
||||
function scheduleUpdate() {
|
||||
if (updateScheduled) return
|
||||
@@ -402,27 +465,29 @@ async function handleStreamingResponse(userMessage) {
|
||||
const timeSinceLastUpdate = now - lastUpdate
|
||||
|
||||
if (timeSinceLastUpdate >= MIN_UPDATE_INTERVAL) {
|
||||
// Update immediately if enough time has passed
|
||||
updateScheduled = true
|
||||
requestAnimationFrame(() => {
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle.checked, 'assistant')
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle && markdownToggle.checked, 'assistant')
|
||||
if (cursorSpan.parentNode) {
|
||||
contentDiv.appendChild(cursorSpan)
|
||||
}
|
||||
if (chatLog) {
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
}
|
||||
lastUpdate = Date.now()
|
||||
updateScheduled = false
|
||||
})
|
||||
} else {
|
||||
// Schedule update after remaining time
|
||||
updateScheduled = true
|
||||
setTimeout(() => {
|
||||
requestAnimationFrame(() => {
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle.checked, 'assistant')
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle && markdownToggle.checked, 'assistant')
|
||||
if (cursorSpan.parentNode) {
|
||||
contentDiv.appendChild(cursorSpan)
|
||||
}
|
||||
if (chatLog) {
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
}
|
||||
lastUpdate = Date.now()
|
||||
updateScheduled = false
|
||||
})
|
||||
@@ -444,7 +509,6 @@ async function handleStreamingResponse(userMessage) {
|
||||
if (data === '[DONE]') {
|
||||
isStreaming = false
|
||||
currentStreamController = null
|
||||
// Final update and remove cursor
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle.checked, 'assistant')
|
||||
if (cursorSpan.parentNode) {
|
||||
cursorSpan.parentNode.removeChild(cursorSpan)
|
||||
@@ -466,7 +530,6 @@ async function handleStreamingResponse(userMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// Final update
|
||||
updateMessageContent(contentDiv, accumulatedContent, markdownToggle.checked, 'assistant')
|
||||
chatLog.scrollTop = chatLog.scrollHeight
|
||||
|
||||
@@ -480,29 +543,26 @@ async function handleStreamingResponse(userMessage) {
|
||||
currentStreamController = null
|
||||
sendBtn.disabled = false
|
||||
|
||||
// Remove cursor if still exists
|
||||
if (cursorSpan.parentNode) {
|
||||
if (cursorSpan && cursorSpan.parentNode) {
|
||||
cursorSpan.parentNode.removeChild(cursorSpan)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle non-streaming response
|
||||
async function handleNonStreamingResponse(userMessage) {
|
||||
const typingIndicator = showTypingIndicator()
|
||||
|
||||
let typingIndicator = null
|
||||
try {
|
||||
// Auto-select first model if none selected
|
||||
if (!currentModel && availableModels.length > 0) {
|
||||
currentModel = availableModels[0].id
|
||||
document.getElementById('modelSelector').value = currentModel
|
||||
}
|
||||
typingIndicator = showTypingIndicator()
|
||||
|
||||
const { backendKey, model } = splitBackendModel(currentBackendModel)
|
||||
const selectedModel = model || availableBackendModels[0]?.model || 'local-model'
|
||||
|
||||
const requestBody = {
|
||||
model : currentModel || 'local-model',
|
||||
messages : getApiMessages(), // Send full chat history
|
||||
model : selectedModel,
|
||||
messages : getApiMessages(),
|
||||
stream : false,
|
||||
temperature : 0.7,
|
||||
repeat_penalty: 1.1,
|
||||
max_tokens : 2000
|
||||
}
|
||||
|
||||
@@ -531,7 +591,9 @@ async function handleNonStreamingResponse(userMessage) {
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error:', error)
|
||||
if (typingIndicator) {
|
||||
removeTypingIndicator(typingIndicator)
|
||||
}
|
||||
addMessage('assistant', `Error: ${ error.message }`, false)
|
||||
} finally {
|
||||
sendBtn.disabled = false
|
||||
@@ -539,7 +601,6 @@ async function handleNonStreamingResponse(userMessage) {
|
||||
}
|
||||
}
|
||||
|
||||
// Stop current stream
|
||||
function stopStream() {
|
||||
if (currentStreamController) {
|
||||
currentStreamController.abort()
|
||||
@@ -550,20 +611,22 @@ function stopStream() {
|
||||
}
|
||||
}
|
||||
|
||||
// Send message
|
||||
async function sendMessage() {
|
||||
const userMessage = userInput.value.trim()
|
||||
if (!userMessage || isStreaming) return
|
||||
|
||||
// Add user message to UI and history
|
||||
addMessage('user', userMessage)
|
||||
// ✅ FIX: Validate backend selection
|
||||
if (!currentBackendModel) {
|
||||
addMessage('assistant', 'Please select a backend model first.', false)
|
||||
return
|
||||
}
|
||||
|
||||
addMessage('user', userMessage, false)
|
||||
|
||||
// Clear input field
|
||||
userInput.value = ''
|
||||
userInput.style.height = 'auto'
|
||||
sendBtn.disabled = true
|
||||
|
||||
// Update button text based on streaming state
|
||||
if (streamToggle.checked) {
|
||||
sendBtn.textContent = 'Stop'
|
||||
await handleStreamingResponse(userMessage)
|
||||
@@ -571,11 +634,9 @@ async function sendMessage() {
|
||||
await handleNonStreamingResponse(userMessage)
|
||||
}
|
||||
|
||||
// Reset button text
|
||||
sendBtn.textContent = 'Send'
|
||||
}
|
||||
|
||||
// Event Listeners
|
||||
sendBtn.addEventListener('click', () => {
|
||||
if (isStreaming) {
|
||||
stopStream()
|
||||
@@ -593,30 +654,39 @@ userInput.addEventListener('keydown', (e) => {
|
||||
}
|
||||
})
|
||||
|
||||
// Initialize on load
|
||||
// ✅ Updated window.onload with better initialization
|
||||
window.onload = () => {
|
||||
userInput.focus()
|
||||
fetchModels()
|
||||
if (userInput) userInput.focus()
|
||||
|
||||
// Add welcome message (this will be the first entry in chatHistory)
|
||||
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.*`
|
||||
|
||||
addMessage('assistant', welcomeMessage, true)
|
||||
// Set default backend BEFORE fetching
|
||||
if (!currentBackendModel) {
|
||||
currentBackendModel = 'plato'
|
||||
}
|
||||
|
||||
fetchBackendModels().then(() => {
|
||||
// Load chat history after models are fetched
|
||||
if (chatLog) {
|
||||
if (chatHistory.length === 0) {
|
||||
//addMessage('assistant', welcomeMessage, true, null, false);
|
||||
} else {
|
||||
chatHistory.forEach(msg => {
|
||||
if (typeof msg.content === 'string' && msg.content.trim()) {
|
||||
addMessage(msg.role, msg.content, msg.markdown, msg.messageId, false)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
document.getElementById('resetBtn')?.addEventListener('click', resetChat)
|
||||
}
|
||||
|
||||
function resetChat() {
|
||||
chatHistory = []
|
||||
localStorage.setItem('chatHistory', JSON.stringify(chatHistory))
|
||||
|
||||
if (chatLog) {
|
||||
chatLog.innerHTML = ''
|
||||
addMessage('assistant', welcomeMessage, true, null, false)
|
||||
}
|
||||
}
|
||||
|
Before Width: | Height: | Size: 174 KiB After Width: | Height: | Size: 174 KiB |
|
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
81
www/index.html
Normal file
81
www/index.html
Normal file
@@ -0,0 +1,81 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Chat</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/styles/github-dark.min.css">
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.8.0/highlight.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="chatContainer">
|
||||
<div id="header">
|
||||
<div>Chat with Streaming</div>
|
||||
<div style="font-size: 0.9em; opacity: 0.9; display: flex; align-items: center; gap: 15px; flex-wrap: wrap;">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span>Backend & Model:</span>
|
||||
<select id="backendModelSelector" style="padding: 4px 8px; border-radius: 4px; border: 1px solid #444; background: #2a2a2a; color: #e0e0e0; min-width: 200px;">
|
||||
<option value="">Loading backends and models...</option>
|
||||
</select>
|
||||
</div>
|
||||
<code id="backendDisplay" style="font-size: 0.85em;"></code>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="chatLog">
|
||||
<div class="message message-assistant">
|
||||
<div class="message-header assistant">
|
||||
<div class="avatar assistant-avatar">?</div>
|
||||
<span>Assistant</span></div>
|
||||
<div class="markdown-content"><h1>Welcome to LM Studio Chat!</h1>
|
||||
<p>I now support <strong>full conversation history</strong>, <strong>real-time streaming responses</strong> and <strong>dark, readable text formatting</strong>.</p>
|
||||
<h2>Features:</h2>
|
||||
<ol>
|
||||
<li><strong>Full Chat History</strong> - Complete conversation context is now sent to the AI</li>
|
||||
<li><strong>Smart History Management</strong> - Automatically keeps the last 50 messages</li>
|
||||
<li><strong>Streaming Mode</strong> (enabled by default) - Watch responses appear word-by-word</li>
|
||||
<li><strong>Markdown Rendering</strong> - Proper formatting for code, lists, tables, and more</li>
|
||||
<li><strong>Readable Dark Text</strong> - No more eye strain from light gray text</li>
|
||||
</ol>
|
||||
<h2>Try it out:</h2>
|
||||
<ul>
|
||||
<li>Ask follow-up questions that reference earlier messages</li>
|
||||
<li>Have a multi-turn conversation with full context</li>
|
||||
<li>Ask "what did I just ask?" to test history retention</li>
|
||||
<li>Watch the streaming response in real-time!</li>
|
||||
</ul>
|
||||
<blockquote>
|
||||
<p><em>Tip: You can toggle streaming and markdown using the checkboxes below.</em></p>
|
||||
</blockquote>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="inputArea">
|
||||
<textarea
|
||||
id="userInput"
|
||||
placeholder="Type your message here... (Shift+Enter for new line, Enter to send)"
|
||||
rows="1"
|
||||
oninput="autoResize(this)"
|
||||
></textarea>
|
||||
<div style="display: flex; justify-content: space-between; align-items: center;">
|
||||
<div class="controls">
|
||||
<div>
|
||||
<label>
|
||||
<input type="checkbox" id="streamToggle" checked> Streaming
|
||||
</label>
|
||||
<label style="margin-left: 15px;">
|
||||
<input type="checkbox" id="markdownToggle" checked> Markdown
|
||||
</label>
|
||||
</div>
|
||||
<div id="modelInfo">Model: <span id="modelName">unknown</span></div>
|
||||
</div>
|
||||
<button id="sendBtn">Send</button>
|
||||
<button id="resetBtn">Reset Chat</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -9,7 +9,6 @@ body {
|
||||
#chatContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 95vh;
|
||||
background: white;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||
@@ -279,7 +278,6 @@ body {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
/* Darker markdown styling */
|
||||
.markdown-content {
|
||||
color: #24292f;
|
||||
font-size: 15px;
|
||||
Reference in New Issue
Block a user