arxiv_audio_summary/vibe/summarizer.py

24 lines
933 B
Python
Raw Permalink Normal View History

2025-03-02 03:22:35 +00:00
import logging
2025-03-02 12:47:03 +00:00
from .llm import chat_llm
2025-03-02 03:22:35 +00:00
logger = logging.getLogger(__name__)
2025-03-02 12:47:03 +00:00
def generate_article_summary(article, content, user_info, llm_level="medium"):
2025-03-02 03:22:35 +00:00
"""
Generates a fluid, narrative summary for the article using the LLM.
The summary starts with a connecting phrase.
"""
prompt = (
f"User info: {user_info}\n\n"
f"Please summarize the following article titled '{article['title']}' in a fluid narrative prose style without lists or visual cues. "
f"Begin the summary with a connecting segment like 'And now, Article: {article['title']}'.\n\n"
f"Article Content:\n{content}"
)
2025-03-02 12:47:03 +00:00
2025-03-02 03:22:35 +00:00
logger.info("Generating summary for article '%s'.", article["id"])
try:
2025-03-02 12:47:03 +00:00
response_text = chat_llm(prompt, level=llm_level)
return response_text
2025-03-02 03:22:35 +00:00
except Exception as e:
logger.exception("Error summarizing article '%s': %s", article["id"], e)
return ""