73 lines
2.6 KiB
JavaScript
73 lines
2.6 KiB
JavaScript
/*
|
|
async function startDemoChat() {
|
|
try {
|
|
const response = await fetch('/api/v1/chats/new', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
// WICHTIG: Wenn dein Nginx den Token nicht setzt,
|
|
// muss er hier hin: 'Authorization': 'Bearer DEIN_TOKEN'
|
|
},
|
|
body: JSON.stringify({
|
|
"title": "Demo Chat",
|
|
"chat": {
|
|
//"title": "Neuer Chat",
|
|
//"models": ["trinity-test"], // WICHTIG: Es ist ein Array!
|
|
//"history": { "messages": {}, "children": {} }
|
|
"model":
|
|
//"arcee-ai/trinity-large-preview:free"
|
|
"trinity-test"
|
|
}
|
|
})
|
|
});
|
|
|
|
if (!response.ok) {
|
|
const errorData = await response.json();
|
|
console.error('API Fehlerdetails:', errorData);
|
|
throw new Error(`Fehler: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
const sessionId = data.id;
|
|
|
|
// --- DER KORREKTE DYNAMISCHE PFAD ---
|
|
|
|
// 1. Hole den aktuellen Sprachpfad (z.B. "/de/", "/en/")
|
|
// split('/') macht aus "/de/about/" -> ["", "de", "about", ""]
|
|
const pathSegments = window.location.pathname.split('/');
|
|
const lang = pathSegments[1] || 'de'; // Fallback auf "de", falls kein Pfad da ist
|
|
|
|
// 2. Leite auf den Pfad MIT Sprache und Session-ID um
|
|
// Das ergibt dann z.B. /de/chat/?session=...
|
|
window.location.href = `/${lang}/chat/?session=${sessionId}`;
|
|
//window.location.href = `/de/chat/?session=${sessionId}`;
|
|
|
|
} catch (error) {
|
|
console.error('Fehler beim Starten:', error);
|
|
alert('Demo-Chat konnte nicht gestartet werden.');
|
|
}
|
|
}
|
|
*/
|
|
|
|
// Initialisierung
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
// ... dein bestehender Code ...
|
|
const savedTheme = localStorage.getItem('theme') || 'auto';
|
|
applyTheme(savedTheme);
|
|
|
|
// Hamburger Menü schließen bei Klick auf einen Link
|
|
const navLinksContainer = document.getElementById('navLinks');
|
|
const navLinks = navLinksContainer.querySelectorAll('a');
|
|
const hamburger = document.querySelector('.hamburger');
|
|
|
|
navLinks.forEach(link => {
|
|
link.addEventListener('click', () => {
|
|
// Prüfen, ob das Menü gerade offen ist
|
|
if (navLinksContainer.classList.contains('mobile-open')) {
|
|
navLinksContainer.classList.remove('mobile-open');
|
|
hamburger.classList.remove('active');
|
|
}
|
|
});
|
|
});
|
|
});
|