Luca448 commited on
Commit
4fec205
·
1 Parent(s): 79a97ca

AI: Update 'Allgemeine News' to fetch actual top news of the day (Tagesschau level)

Browse files
Files changed (1) hide show
  1. server/news-service.js +15 -6
server/news-service.js CHANGED
@@ -53,19 +53,23 @@ function saveData() {
53
 
54
  // Search Web (Tavily as primary, Google News RSS as fallback)
55
  async function searchWeb(query) {
 
56
  const tavilyKey = process.env.TAVILY_API_KEY;
57
 
58
- let searchData = { results: [], images: [] };
 
 
 
59
 
60
  if (tavilyKey) {
61
- console.log(`[NewsService] Searching with Tavily for: ${query}`);
62
  try {
63
  const response = await fetch('https://api.tavily.com/search', {
64
  method: 'POST',
65
  headers: { 'Content-Type': 'application/json' },
66
  body: JSON.stringify({
67
  api_key: tavilyKey,
68
- query: query,
69
  search_depth: 'basic',
70
  include_answer: false,
71
  include_raw_content: false,
@@ -94,9 +98,9 @@ async function searchWeb(query) {
94
  }
95
 
96
  // Fallback to Google News RSS if Tavily is missing or failed
97
- console.log(`[NewsService] Searching with Google News RSS for: ${query}`);
98
  try {
99
- const url = `https://news.google.com/rss/search?q=${encodeURIComponent(query)}&hl=de&gl=DE&ceid=DE:de`;
100
  const res = await fetch(url);
101
  const xml = await res.text();
102
  const $ = cheerio.load(xml, { xmlMode: true });
@@ -126,8 +130,13 @@ async function generateArticleWithGemini(topic, searchResults, simulateError = f
126
  ? searchResults.map((s, i) => `[${i+1}] ${s.title} (${s.url}):\n${s.snippet}`).join('\n\n')
127
  : "Keine aktuellen Live-Web-Suchergebnisse verfügbar. Bitte nutze dein umfassendes internes Wissen über dieses Thema.";
128
 
 
 
 
 
 
129
  const prompt = `Du bist ein hochintelligenter KI-Journalist für Schüler und Studenten.
130
- Dein Thema: "${topic}"
131
 
132
  Hier sind Informationen zu diesem Thema:
133
  ${sourcesText}
 
53
 
54
  // Search Web (Tavily as primary, Google News RSS as fallback)
55
  async function searchWeb(query) {
56
+ const searchData = { results: [], images: [] };
57
  const tavilyKey = process.env.TAVILY_API_KEY;
58
 
59
+ let searchQuery = query;
60
+ if (query === 'Allgemeine News') {
61
+ searchQuery = 'Aktuelle Top-Nachrichten heute Deutschland und Welt';
62
+ }
63
 
64
  if (tavilyKey) {
65
+ console.log(`[NewsService] Searching with Tavily for: ${searchQuery} (Original: ${query})`);
66
  try {
67
  const response = await fetch('https://api.tavily.com/search', {
68
  method: 'POST',
69
  headers: { 'Content-Type': 'application/json' },
70
  body: JSON.stringify({
71
  api_key: tavilyKey,
72
+ query: searchQuery,
73
  search_depth: 'basic',
74
  include_answer: false,
75
  include_raw_content: false,
 
98
  }
99
 
100
  // Fallback to Google News RSS if Tavily is missing or failed
101
+ console.log(`[NewsService] Searching with Google News RSS for: ${searchQuery}`);
102
  try {
103
+ const url = `https://news.google.com/rss/search?q=${encodeURIComponent(searchQuery)}&hl=de&gl=DE&ceid=DE:de`;
104
  const res = await fetch(url);
105
  const xml = await res.text();
106
  const $ = cheerio.load(xml, { xmlMode: true });
 
130
  ? searchResults.map((s, i) => `[${i+1}] ${s.title} (${s.url}):\n${s.snippet}`).join('\n\n')
131
  : "Keine aktuellen Live-Web-Suchergebnisse verfügbar. Bitte nutze dein umfassendes internes Wissen über dieses Thema.";
132
 
133
+ let promptTopic = topic;
134
+ if (topic === 'Allgemeine News') {
135
+ promptTopic = 'Die wichtigsten und größten tagesaktuellen Nachrichten (Niveau der Hauptnachrichten/Tagesschau) für Deutschland und die Welt. Fasse die wichtigsten Ereignisse des heutigen Tages aus den Suchergebnissen zusammen.';
136
+ }
137
+
138
  const prompt = `Du bist ein hochintelligenter KI-Journalist für Schüler und Studenten.
139
+ Dein Thema: "${promptTopic}"
140
 
141
  Hier sind Informationen zu diesem Thema:
142
  ${sourcesText}