From 080865615c25a6d143fc5ca0e8af29e527d8c9d0 Mon Sep 17 00:00:00 2001 From: dimitrievgs Date: Wed, 17 Sep 2025 01:04:21 +0300 Subject: [PATCH] add system prompt --- main.ts | 18 +++++++++++++++++- src/components/ChatPanel.ts | 16 ++++------------ src/views/ChatView.ts | 5 +++-- src/views/GraphView.ts | 2 +- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/main.ts b/main.ts index 3eaf37d..e621462 100644 --- a/main.ts +++ b/main.ts @@ -9,10 +9,12 @@ import 'src/css/styles.css'; // Путь к твоему новому CSS фай interface LLMAgentSettings { apiBaseUrl: string; + systemPrompt: string; } const DEFAULT_SETTINGS: LLMAgentSettings = { - apiBaseUrl: 'http://localhost:5000/api' + apiBaseUrl: 'http://localhost:5000/api', + systemPrompt: 'Ты полезный ИИ ассистент.', }; // ----------------------------------------------- Main Plugin Class --------------------------------------------------------------- @@ -138,5 +140,19 @@ class SampleSettingTab extends PluginSettingTab { await this.plugin.saveSettings(); }) ); + + // Новое поле для системного промпта + new Setting(containerEl) + .setName('Системный промпт') + .setDesc('Этот промпт будет отправляться LLM перед каждым диалогом.') + .addTextArea((text) => + text + .setPlaceholder('Ты полезный ИИ ассистент.') + .setValue(this.plugin.settings.systemPrompt) + .onChange(async (value) => { + this.plugin.settings.systemPrompt = value; + await this.plugin.saveSettings(); + }) + ); } } diff --git a/src/components/ChatPanel.ts b/src/components/ChatPanel.ts index 8978fec..ea80a10 100644 --- a/src/components/ChatPanel.ts +++ b/src/components/ChatPanel.ts @@ -131,7 +131,7 @@ export class ChatPanel {
${ msg.role === 'user' - ? `` + ? `` : `` }
@@ -144,20 +144,12 @@ export class ChatPanel { ) .join(''); - const chatPanelContainer = this.container.querySelector('.llm-agent-chat-panel') as HTMLElement; - // Прокручиваем к последнему сообщению - // Обычный `historyContainer.scrollTop = historyContainer.scrollHeight;` не работает if (this.chatHistory.length > 0) { setTimeout(() => { - if (chatPanelContainer.scrollHeight > chatPanelContainer.clientHeight) { - // Используем scrollTop для более точного контроля - // Прокручиваем на всю высоту скролла - chatPanelContainer.scrollTop = chatPanelContainer.scrollHeight; - // Затем отнимаем немного, чтобы создать отступ снизу - // 20px - это пример, можно настроить это значение - const offset = 20; // Величина отступа от низа - chatPanelContainer.scrollTop -= offset; + const lastMessage = historyContainer.lastElementChild as HTMLElement; + if (lastMessage) { + lastMessage.scrollIntoView({ behavior: 'smooth', block: 'end' }); } }, 0); } diff --git a/src/views/ChatView.ts b/src/views/ChatView.ts index e961f32..6e94607 100644 --- a/src/views/ChatView.ts +++ b/src/views/ChatView.ts @@ -87,7 +87,7 @@ export class ChatView extends ItemView { return; } - const url = nodeId + const url = nodeId ? `${this.plugin.settings.apiBaseUrl}/messages/${this.selectedGraphId}/${nodeId}` : `${this.plugin.settings.apiBaseUrl}/messages/${this.selectedGraphId}/last`; const response = await fetch(url); @@ -125,7 +125,8 @@ export class ChatView extends ItemView { body: JSON.stringify({ message: message, graph_id: this.selectedGraphId, - parent_node_id: this.currentNode + parent_node_id: this.currentNode, + system_prompt: this.plugin.settings.systemPrompt }) }); diff --git a/src/views/GraphView.ts b/src/views/GraphView.ts index 8bfeef2..29ce88f 100644 --- a/src/views/GraphView.ts +++ b/src/views/GraphView.ts @@ -27,7 +27,7 @@ export class GraphView extends ItemView { historyPanel: HistoryPanel | null; historyContainer: HTMLDivElement; graphContainer: HTMLDivElement; - reactRoot: ReactDOM.Root | null; // <-- ИСПРАВЛЕНО: Указываем тип для reactRoot + reactRoot: ReactDOM.Root | null; constructor(leaf: WorkspaceLeaf, plugin: LLMAgentPlugin) { super(leaf);