[update] improved summary generation prompts with stricter location formatting, updated JSON schema to support location
field, and enhanced logging for AI operations in backend services
This commit is contained in:
@@ -156,14 +156,15 @@ class NewsFetcher:
|
|||||||
"### Vorliegende Informationen\n"
|
"### Vorliegende Informationen\n"
|
||||||
f"{context}\n\n"
|
f"{context}\n\n"
|
||||||
"### Längenbegrenzungen\n"
|
"### Längenbegrenzungen\n"
|
||||||
"title: max 100 Zeichen\n"
|
"title: Format \"ORT: Titel\", max 100 Zeichen\n"
|
||||||
|
"location: nur der ORT-Teil, max 40 Zeichen\n"
|
||||||
"summary: 100–160 Wörter\n"
|
"summary: 100–160 Wörter\n"
|
||||||
"tags: bis zu 6 Schlüsselwörter, durch Komma getrennt, alles Kleinbuchstaben.\n\n"
|
"tags: bis zu 6 Schlüsselwörter, durch Komma getrennt, alles Kleinbuchstaben.\n\n"
|
||||||
"### Regeln\n"
|
"### Regeln\n"
|
||||||
"1. Nutze ausschließlich Informationen, die im bereitgestellten Material eindeutig vorkommen. Externes Wissen ist untersagt.\n"
|
"1. Nutze ausschließlich Informationen, die im bereitgestellten Material eindeutig vorkommen. Externes Wissen ist untersagt.\n"
|
||||||
"2. Liegt sowohl Artikel-Text als auch RSS-Metadaten vor, hat der Artikel-Text Vorrang; verwende RSS nur ergänzend.\n"
|
"2. Liegt sowohl Artikel-Text als auch RSS-Metadaten vor, hat der Artikel-Text Vorrang; verwende RSS nur ergänzend.\n"
|
||||||
"3. Liegt nur RSS-Titel und/oder -Beschreibung vor, stütze dich ausschließlich darauf.\n"
|
"3. Liegt nur RSS-Titel und/oder -Beschreibung vor, stütze dich ausschließlich darauf.\n"
|
||||||
"4. Sind die Informationen unzureichend, gib exakt {\"title\":\"\",\"summary\":\"\",\"tags\":\"\"} zurück.\n"
|
"4. Sind die Informationen unzureichend, gib exakt {\"location\":\"\",\"title\":\"\",\"summary\":\"\",\"tags\":\"\"} zurück.\n"
|
||||||
"5. Gib nur gültiges, minifiziertes JSON zurück – keine Zeilenumbrüche, kein Markdown, keine Kommentare.\n"
|
"5. Gib nur gültiges, minifiziertes JSON zurück – keine Zeilenumbrüche, kein Markdown, keine Kommentare.\n"
|
||||||
"6. Verwende keine hypothetischen Formulierungen (\"könnte\", \"möglicherweise\" etc.).\n"
|
"6. Verwende keine hypothetischen Formulierungen (\"könnte\", \"möglicherweise\" etc.).\n"
|
||||||
"7. Wörtliche Zitate dürfen höchstens 15 % des Summary-Texts ausmachen.\n"
|
"7. Wörtliche Zitate dürfen höchstens 15 % des Summary-Texts ausmachen.\n"
|
||||||
@@ -205,6 +206,8 @@ class NewsFetcher:
|
|||||||
A dictionary containing the article title and summaries in German and English,
|
A dictionary containing the article title and summaries in German and English,
|
||||||
or None if summarization failed
|
or None if summarization failed
|
||||||
"""
|
"""
|
||||||
|
logger.info("[AI] Fetching article content from: " + url)
|
||||||
|
|
||||||
article_content = await NewsFetcher.fetch_article_content(client, url)
|
article_content = await NewsFetcher.fetch_article_content(client, url)
|
||||||
|
|
||||||
if not article_content:
|
if not article_content:
|
||||||
@@ -233,6 +236,9 @@ class NewsFetcher:
|
|||||||
"items": {
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"location": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -247,6 +253,8 @@ class NewsFetcher:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info("[AI] Running summary generation...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
f"{OLLAMA_HOST}/api/generate",
|
f"{OLLAMA_HOST}/api/generate",
|
||||||
@@ -258,6 +266,8 @@ class NewsFetcher:
|
|||||||
result = response.json()
|
result = response.json()
|
||||||
llm_response = result["response"]
|
llm_response = result["response"]
|
||||||
|
|
||||||
|
logger.info("[AI] " + llm_response)
|
||||||
|
|
||||||
if isinstance(llm_response, str):
|
if isinstance(llm_response, str):
|
||||||
summary_data = json.loads(llm_response)
|
summary_data = json.loads(llm_response)
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user