KI-Chat: Kontext-Injection repariert (SQL from-Alias) + Datum im Prompt
gatherChatContext() brach mit SQLITE_ERROR ab, weil "e.from_addr AS from"
das SQL-Schlüsselwort from als Alias nutzte. Der Fehler wurde im Route-Handler
geschluckt (context={}), sodass der Assistent keinen Zugriff auf Bewerbungen/
Termine/E-Mails hatte. Alias entfernt.
Zusätzlich erhält der System-Prompt jetzt das heutige Datum, damit der
Assistent "morgen"/"heute" aus den UTC-Termin-Zeitstempeln ableiten kann.
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -103,6 +103,7 @@ async function streamChat({ system, messages, onToken, temperature = 0.6, signal
|
|||||||
// Each entry is already trimmed to the fields the prompt needs.
|
// Each entry is already trimmed to the fields the prompt needs.
|
||||||
function buildContextPrompt(ctx) {
|
function buildContextPrompt(ctx) {
|
||||||
const name = (ctx && ctx.settings && ctx.settings.name) || 'der Bewerber';
|
const name = (ctx && ctx.settings && ctx.settings.name) || 'der Bewerber';
|
||||||
|
const heute = (ctx && ctx.heute) || '';
|
||||||
const parts = [];
|
const parts = [];
|
||||||
parts.push(
|
parts.push(
|
||||||
'Du bist ein hilfreicher, deutschsprachiger Bewerbungs-Assistent für ' + name + '. ' +
|
'Du bist ein hilfreicher, deutschsprachiger Bewerbungs-Assistent für ' + name + '. ' +
|
||||||
@@ -113,6 +114,13 @@ function buildContextPrompt(ctx) {
|
|||||||
'Wenn eine Angabe nötig ist, die du nicht weißt, setze einen klar erkennbaren ' +
|
'Wenn eine Angabe nötig ist, die du nicht weißt, setze einen klar erkennbaren ' +
|
||||||
'Platzhalter in eckigen Klammern. Verwende nur den einfachen Bindestrich "-".'
|
'Platzhalter in eckigen Klammern. Verwende nur den einfachen Bindestrich "-".'
|
||||||
);
|
);
|
||||||
|
if (heute) {
|
||||||
|
parts.push('# Heute\n' + 'Heutiges Datum: ' + heute + '. ' +
|
||||||
|
'Terminangaben unten sind UTC-Zeitstempel (ISO, endet auf Z). ' +
|
||||||
|
'Rechne in UTC-Zeiten und leite daraus ab, was "heute", "morgen" usw. ist. ' +
|
||||||
|
'Zeige dem Nutzer Terminzeiten in seiner lokalen Zeit (Europe/Berlin = UTC+1, ' +
|
||||||
|
'bzw. UTC+2 während der Sommerzeit).');
|
||||||
|
}
|
||||||
|
|
||||||
const apps = (ctx && ctx.applications) || [];
|
const apps = (ctx && ctx.applications) || [];
|
||||||
if (apps.length) {
|
if (apps.length) {
|
||||||
|
|||||||
@@ -2328,13 +2328,15 @@ initializeDatabase().then(() => {
|
|||||||
dbGet('SELECT name FROM settings WHERE id = 1'),
|
dbGet('SELECT name FROM settings WHERE id = 1'),
|
||||||
dbAll(`SELECT firma, stelle, status, datum, notizen FROM bewerbungen
|
dbAll(`SELECT firma, stelle, status, datum, notizen FROM bewerbungen
|
||||||
ORDER BY datum DESC, created_at DESC LIMIT 25`),
|
ORDER BY datum DESC, created_at DESC LIMIT 25`),
|
||||||
dbAll(`SELECT e.subject, e.from_addr AS from, b.firma AS bewerbung
|
dbAll(`SELECT e.subject, e.from_addr, b.firma AS bewerbung
|
||||||
FROM emails e LEFT JOIN bewerbungen b ON b.id = e.bewerbung_id
|
FROM emails e LEFT JOIN bewerbungen b ON b.id = e.bewerbung_id
|
||||||
WHERE e.direction = 'received'
|
WHERE e.direction = 'received'
|
||||||
ORDER BY e.email_date DESC, e.created_at DESC LIMIT 12`),
|
ORDER BY e.email_date DESC, e.created_at DESC LIMIT 12`),
|
||||||
upcomingTermine(8),
|
upcomingTermine(8),
|
||||||
]);
|
]);
|
||||||
|
const heute = new Date().toLocaleDateString('de-DE', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' });
|
||||||
return {
|
return {
|
||||||
|
heute,
|
||||||
settings: settings || {},
|
settings: settings || {},
|
||||||
applications: applications.map((a) => ({
|
applications: applications.map((a) => ({
|
||||||
firma: a.firma, stelle: a.stelle, status: a.status,
|
firma: a.firma, stelle: a.stelle, status: a.status,
|
||||||
|
|||||||
Reference in New Issue
Block a user