feat: Füge Zusammenfassung der Suchergebnisse mit summarizeDetail hinzu

- 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
This commit is contained in:
sebseb7
2026-04-05 01:14:11 +02:00
parent 88015fbcae
commit 92845a5a4c
2 changed files with 54 additions and 1 deletions

View File

@@ -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) {

View File

@@ -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 };