diff --git a/Endpoints/ChatEndpoint.cs b/Endpoints/ChatEndpoint.cs index 9afced9..014b968 100644 --- a/Endpoints/ChatEndpoint.cs +++ b/Endpoints/ChatEndpoint.cs @@ -75,6 +75,15 @@ public static class ChatEndpoint res.Headers["Cache-Control"] = "no-cache"; res.Headers["Connection"] = "keep-alive"; + var promptParts = new List(); + promptParts.Add($"Du bist {agent.Name}."); + if (!string.IsNullOrWhiteSpace(agent.Persona)) + promptParts.Add($"## Persona\n{agent.Persona}"); + if (!string.IsNullOrWhiteSpace(agent.Instructions)) + promptParts.Add($"## Instructions\n{agent.Instructions}"); + + var systemPromptText = string.Join("\n\n", promptParts); + var chainId = Guid.NewGuid().ToString("N"); await db.CreateChain(new ChainRecord @@ -83,7 +92,7 @@ public static class ChatEndpoint SessionId = sessionId, AgentId = agent.AgentId, Model = modelId, - SystemPrompt = body.SystemPrompt + SystemPrompt = systemPromptText }); // Session-Timestamp aktualisieren @@ -107,23 +116,10 @@ public static class ChatEndpoint }); } - var systemPrompt = new List(); - - // Agent Persona - if (!string.IsNullOrWhiteSpace(agent.Persona)) - systemPrompt.Add(new { type = "text", text = agent.Persona }); - - // Agent Instructions - if (!string.IsNullOrWhiteSpace(agent.Instructions)) - systemPrompt.Add(new { type = "text", text = agent.Instructions }); - - // Zusätzlicher System Prompt aus dem UI - if (!string.IsNullOrWhiteSpace(body.SystemPrompt)) - systemPrompt.Add(new { type = "text", text = body.SystemPrompt }); - - // Fallback wenn gar nix gesetzt - if (systemPrompt.Count == 0) - systemPrompt.Add(new { type = "text", text = "Du bist ein hilfreicher Assistent." }); + var systemPrompt = new List + { + new { type = "text", text = systemPromptText } + }; var anthropic = new AnthropicService(httpFactory, token, toolService, db); await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId); diff --git a/Models/ChatModels.cs b/Models/ChatModels.cs index b67ebb3..6b55854 100644 --- a/Models/ChatModels.cs +++ b/Models/ChatModels.cs @@ -17,9 +17,6 @@ public class ChatRequest [JsonPropertyName("messages")] public List Messages { get; set; } = new(); - [JsonPropertyName("systemPrompt")] - public string SystemPrompt { get; set; } = ""; - [JsonPropertyName("sessionId")] public string SessionId { get; set; } = ""; } diff --git a/wwwroot/index.html b/wwwroot/index.html index d7d8031..bddef28 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -81,12 +81,7 @@

Session

-
- - -
-
diff --git a/wwwroot/js/api.js b/wwwroot/js/api.js index 217efc8..092bf10 100644 --- a/wwwroot/js/api.js +++ b/wwwroot/js/api.js @@ -1,10 +1,10 @@ // ── API Calls ── -async function apiChat(messages, systemPrompt, sessionId) { +async function apiChat(messages, sessionId) { return fetch('/api/chat', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ messages, systemPrompt, sessionId }) + body: JSON.stringify({ messages, sessionId }) }); } diff --git a/wwwroot/js/chat.js b/wwwroot/js/chat.js index cfa9b4d..d7b090c 100644 --- a/wwwroot/js/chat.js +++ b/wwwroot/js/chat.js @@ -21,7 +21,6 @@ async function clearChat() { async function sendMessage() { const input = $('#input'); const btn = $('#send'); - const systemPrompt = $('#systemPrompt').value.trim(); const text = input.value.trim(); if (!text) return; @@ -38,7 +37,7 @@ async function sendMessage() { let currentToolBox = null; try { - const resp = await apiChat(messages, systemPrompt, getCurrentSessionId()); + const resp = await apiChat(messages, getCurrentSessionId()); const reader = resp.body.getReader(); const decoder = new TextDecoder(); let buffer = ''; diff --git a/wwwroot/js/pages/chat-page.js b/wwwroot/js/pages/chat-page.js index 016fc93..16bcebd 100644 --- a/wwwroot/js/pages/chat-page.js +++ b/wwwroot/js/pages/chat-page.js @@ -27,15 +27,6 @@ registerPage('chat', { backBtn.addEventListener('click', () => navigateTo('session', { id: sessionId })); } - // System Prompt Toggle - const showSystem = document.getElementById('showSystem'); - const systemPrompt = document.getElementById('systemPrompt'); - if (showSystem && systemPrompt) { - showSystem.addEventListener('change', () => { - systemPrompt.classList.toggle('visible', showSystem.checked); - }); - } - // Send const sendBtn = document.getElementById('send'); if (sendBtn) sendBtn.addEventListener('click', sendMessage);