Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
added RAG search to prompts
Michael Peter Christenb36e72a4d70c
diff --git a/htroot/yacychat.html b/htroot/yacychat.htmlindex 0fbf64131..778589d63 100644--- a/htroot/yacychat.html+++ b/htroot/yacychat.html@@ -200,12 +200,23 @@.attachment-row.has-attachment .attachment-button {display: none;}+ .attachment-row.has-attachment .search-button {+ display: none;+ }+ .attachment-row.search-mode .attachment-button,+ .attachment-row.search-mode .search-button {+ display: none;+ }+ .attachment-row.search-mode .attachment-clear {+ display: inline-flex;+ }.attachment-row.loading .attachment-filename {font-style: italic;color: #6b7a90;}.attachment-button,+ .search-button,.copy-button,.user-trim-button {width: 24px;@@ -224,6 +235,7 @@}.attachment-button:hover,+ .search-button:hover,.copy-button:hover,.user-trim-button:hover {background: #c3cbd9;@@ -546,6 +558,9 @@<div class="composer-main" id="composerMain"><textarea class="chat-body" id="userInput" rows="3" placeholder="Ask me anything..." required="required"></textarea><div class="attachment-row" id="attachmentRow">+ <button type="button" class="search-button" id="searchButton" aria-label="Search">+ <span class="glyphicon glyphicon-search" aria-hidden="true"></span>+ </button><button type="button" class="attachment-button" id="addFileButton" aria-label="Attach a file"><span class="glyphicon glyphicon-paperclip" aria-hidden="true"></span></button>@@ -600,6 +615,7 @@},busy: false,attachment: null,+ searchMode: false,assistantSeen: false,showSystem: false};@@ -610,6 +626,7 @@input: document.getElementById('userInput'),sendButton: document.getElementById('sendButton'),fileInput: document.getElementById('fileInput'),+ searchButton: document.getElementById('searchButton'),addFileButton: document.getElementById('addFileButton'),attachmentFilename: document.getElementById('attachmentFilename'),clearFileButton: document.getElementById('clearFileButton'),@@ -905,16 +922,20 @@function clearAttachment() {state.attachment = null;+ state.searchMode = false;dom.fileInput.value = '';dom.attachmentFilename.textContent = 'Attach PNG/JPG or text (.txt/.md/.tex)';dom.attachmentRow.classList.remove('has-attachment');+ dom.attachmentRow.classList.remove('search-mode');closeAttachmentPopover();}function setComposerAttachment(attachment) {+ state.searchMode = false;+ dom.attachmentRow.classList.remove('search-mode');state.attachment = attachment ? cloneAttachment(attachment) : null;if (state.attachment) {- dom.attachmentFilename.textContent = state.attachment.name || 'Attachment';+ dom.attachmentFilename.textContent = `Attach File: ${state.attachment.name || 'Attachment'}`;dom.attachmentRow.classList.add('has-attachment');} else {clearAttachment();@@ -993,7 +1014,7 @@function updateClearChatVisibility() {if (!dom.clearChatRow) return;dom.clearChatRow.style.visibility = state.assistantSeen ? 'visible' : 'hidden';- dom.clearChatRow.style.pointerEvents = state.assistantSeen ? '' : 'none';+ dom.clearChatRow.style.pointerEvents = state.assistantSeen ? 'auto' : 'none';}function ensureComposerVisible(evt) {@@ -1191,15 +1212,18 @@}return {role: 'user',- content: parts+ content: parts,+ search: !!state.searchMode};}- return { role: 'user', content: promptText };+ return { role: 'user', content: promptText, search: !!state.searchMode };}function stripMessageForApi(message) {if (!message) return null;- return { role: message.role, content: message.content };+ const sanitized = { role: message.role, content: message.content };+ if (message.search) sanitized.search = true;+ return sanitized;}function buildRequestPayload() {@@ -1745,7 +1769,8 @@state.messages.push({role: 'user',content: userMessage.content,- attachment: userAttachment+ attachment: userAttachment,+ search: !!state.searchMode});const userIndex = state.messages.length - 1;const preview = formatUserPreview(prompt);@@ -1771,8 +1796,17 @@dom.addFileButton.addEventListener('click', () => {dom.fileInput.click();});+ dom.searchButton?.addEventListener('click', () => {+ state.searchMode = true;+ state.attachment = null;+ dom.attachmentRow.classList.remove('has-attachment');+ dom.attachmentRow.classList.add('search-mode');+ dom.attachmentFilename.textContent = 'Attach Search Results';+ });dom.fileInput.addEventListener('change', handleFileChange);- dom.clearFileButton.addEventListener('click', clearAttachment);+ dom.clearFileButton.addEventListener('click', () => {+ clearAttachment();+ });dom.clearChatButton?.addEventListener('click', clearChatHistory);dom.downloadChatButton?.addEventListener('click', downloadChat);dom.uploadChatButton?.addEventListener('click', () => dom.uploadChatInput?.click());diff --git a/source/net/yacy/http/servlets/RAGProxyServlet.java b/source/net/yacy/http/servlets/RAGProxyServlet.javaindex d2dcdb910..f67a407ac 100644--- a/source/net/yacy/http/servlets/RAGProxyServlet.java+++ b/source/net/yacy/http/servlets/RAGProxyServlet.java@@ -133,7 +133,6 @@ public class RAGProxyServlet extends HttpServlet {//Double temperature = bodyObject.optDouble("temperature", 0.0);//int max_tokens = bodyObject.optInt("max_tokens", 1024);//boolean stream = bodyObject.optBoolean("stream", false);- boolean rag = bodyObject.optBoolean("rag", false);// resolve true model name from configurationLLM.LLMUsage usage = LLM.LLMUsage.chat;@@ -153,13 +152,15 @@ public class RAGProxyServlet extends HttpServlet {}UserObject userObject = new UserObject(messages.getJSONObject(messages.length() - 1));String user = userObject.getContentText(); // this is the latest prompt+ boolean rag = userObject.getSearch();//List<DataURL> data_urls = userObject.getContentAttachments(); // this list is a copy of the content data_urls// RAG+ String searchResultMarkdown = "";if (rag) {// modify system and user prompt here in bodyObject to enable RAGString query = this.searchWordsForPrompt(llm4tldr.llm, llm4tldr.model, user);- String searchResultMarkdown = searchResultsAsMarkdown(query, 4);+ searchResultMarkdown = searchResultsAsMarkdown(query, 10);user += LLM_USER_PREFIX;user += searchResultMarkdown;userObject.setContentText(user);@@ -259,6 +260,11 @@ public class RAGProxyServlet extends HttpServlet {this.normalize();}+ public boolean getSearch() {+ boolean search = this.userObject.optBoolean("search", false);+ return search;+ }+public String getContentText() {Object content = this.userObject.opt("content");assert content != null;