System prompt: build from agent persona/instructions, store in chain, remove UI textarea
This commit is contained in:
1 parent
a90b9427a5
commit
002ef293f0
6 files changed
+17
-39
No files matched your search
+14
-18
@@ -75,6 +75,15 @@ public static class ChatEndpoint
|
||||
res.Headers["Cache-Control"] = "no-cache";
|
||||
res.Headers["Connection"] = "keep-alive";
|
||||
|
||||
var promptParts = new List<string>();
|
||||
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<object>();
|
||||
|
||||
// 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<object>
|
||||
{
|
||||
new { type = "text", text = systemPromptText }
|
||||
};
|
||||
|
||||
var anthropic = new AnthropicService(httpFactory, token, toolService, db);
|
||||
await anthropic.StreamChat(res, modelId, systemPrompt, messages, chainId);
|
||||
|
||||
@@ -17,9 +17,6 @@ public class ChatRequest
|
||||
[JsonPropertyName("messages")]
|
||||
public List<ChatMessage> Messages { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("systemPrompt")]
|
||||
public string SystemPrompt { get; set; } = "";
|
||||
|
||||
[JsonPropertyName("sessionId")]
|
||||
public string SessionId { get; set; } = "";
|
||||
}
|
||||
@@ -81,12 +81,7 @@
|
||||
<button class="back-btn" id="chatBackBtn">←</button>
|
||||
<h1 id="sessionTitle">Session</h1>
|
||||
<button class="header-btn" id="archiveBtn">Archivieren</button>
|
||||
<div class="toggle">
|
||||
<input type="checkbox" id="showSystem">
|
||||
<label for="showSystem">System Prompt</label>
|
||||
</div>
|
||||
</header>
|
||||
<textarea id="systemPrompt" placeholder="System Prompt (SOUL.md Inhalt etc.)"></textarea>
|
||||
<div class="meta-bar" id="meta"></div>
|
||||
<div id="chat"></div>
|
||||
<div class="input-area">
|
||||
|
||||
+2
-2
@@ -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 })
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -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 = '';
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user