From 92845a5a4cff4811fa800e01c72021c0776f61e7 Mon Sep 17 00:00:00 2001 From: sebseb7 Date: Sun, 5 Apr 2026 01:14:11 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20F=C3=BCge=20Zusammenfassung=20der=20Suc?= =?UTF-8?q?hergebnisse=20mit=20summarizeDetail=20hinzu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Neue Funktion summarizeDetail in openRouterService.js implementiert - Verwendet OpenRouter API direkt mit JSON-Schema-Antwortformat - Integriert die Zusammenfassung in searchService.js für detaillierte Inhalte - Filtert relevante Informationen aus den Suchergebnissen basierend auf der ursprünglichen Frage --- src/services/openRouterService.js | 48 +++++++++++++++++++++++++++++++ src/services/searchService.js | 7 ++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/services/openRouterService.js b/src/services/openRouterService.js index 98f0353..df0db4e 100644 --- a/src/services/openRouterService.js +++ b/src/services/openRouterService.js @@ -69,6 +69,54 @@ export async function summarizeSources({ openrouter, text, question }) { return parseResponse(response); } +export async function summarizeDetail({ text, url, question }) { + const prompt = ` + You are a search result analyst. + The original query was "${question}". + A detailed search on the following source "${url}" has returned a result, + filter this result to extract the most relevant information to answer the original query. + `; + + const params = { + model: 'openai/gpt-oss-120b:nitro', + messages: [ + { role: 'system', content: prompt }, + { role: 'user', content: text }, + ], + reasoning: { effort: 'low' }, + response_format: { + type: 'json_schema', + json_schema: { + name: 'summary', + strict: true, + schema: { + type: 'object', + required: ['summary'], + additionalProperties: false, + properties: { + summary: { type: 'string', description: 'Filtered summary of the relevant information' }, + }, + }, + }, + }, + stream: false, + }; + + // Using direct fetch API instead of OpenRouter SDK + const apiKey = process.env.OPENROUTER_API_KEY; + const fetchResponse = await fetch('https://openrouter.ai/api/v1/chat/completions', { + method: 'POST', + headers: { + Authorization: `Bearer ${apiKey}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(params), + }); + const response = await fetchResponse.json(); + await logOpenRouterCall('summarizeDetail', text, params, response); + return parseResponse(response); +} + export async function rephraseQuestion({ question, previousClarification, originalQuestion }) { if(previousClarification) { diff --git a/src/services/searchService.js b/src/services/searchService.js index 8c00fdb..1bac882 100644 --- a/src/services/searchService.js +++ b/src/services/searchService.js @@ -57,7 +57,12 @@ async function fetchDetailedContents({ exa, question, sources, broadcast }) { ); const content = await exa.getContents([source.url], EXA_CONTENT_OPTIONS(question)); - return { url: source.url, content, cost: content.costDollars.total }; + + console.log(content.results.highlights.join('\n')); + + const summary = await summarizeDetail({text: content.results.highlights.join('\n'), url: source.url, question}) + + return { url: source.url, content:summary, cost: content.costDollars.total }; } catch (error) { broadcast(`⚠️ Could not fetch content for ${source.url}: ${error.message}`, 'warning'); return { url: source.url, content: null };