diff options
| -rw-r--r-- | community/wacca_plus/wacca_plus.py | 3 | ||||
| -rw-r--r-- | summarizer.py | 12 |
2 files changed, 10 insertions, 5 deletions
diff --git a/community/wacca_plus/wacca_plus.py b/community/wacca_plus/wacca_plus.py index fae3dd0..067df9f 100644 --- a/community/wacca_plus/wacca_plus.py +++ b/community/wacca_plus/wacca_plus.py @@ -92,6 +92,7 @@ def parse_announcement_messages(message_json: dict): cache = _load_cache() for message in message_json: type = None + message_content = message.get("content", "") if len(message["attachments"]) == 0: continue image_attachments = [] @@ -122,7 +123,7 @@ def parse_announcement_messages(message_json: dict): date = message["timestamp"].split("T")[0] date_obj = datetime.strptime(date, "%Y-%m-%d") unix_time = int(time.mktime(date_obj.timetuple())) - headline, content = generate_headline_and_content_from_images(image_urls, "WACCA PLUS") + headline, content = generate_headline_and_content_from_images(image_urls, "WACCA PLUS", message_content) news_posts.append({ "date": date, diff --git a/summarizer.py b/summarizer.py index d3d66f1..eefff7c 100644 --- a/summarizer.py +++ b/summarizer.py @@ -5,7 +5,7 @@ import hashlib import os load_dotenv() - +MAX_CHAR_CONTENT_CONSIDERATION_LENGTH = 1000 def summarization_is_possible() -> bool: return os.getenv("OPENAI_API_KEY") @@ -33,10 +33,14 @@ def _make_cache_key(game: str, img_urls: list[str]) -> str: return f"{normalized_game}_{hash_digest}" -def generate_headline_and_content_from_images(img_urls: list[str], game: str): +def generate_headline_and_content_from_images(img_urls: list[str], game: str, message_content: str=""): """ Uses LLM to generate the headline and content when none provided by source, based on one or more images. """ + # Limit message content to 500 characters + if len(message_content) > MAX_CHAR_CONTENT_CONSIDERATION_LENGTH: + message_content = message_content[:MAX_CHAR_CONTENT_CONSIDERATION_LENGTH] + cache = _load_cache() cache_key = _make_cache_key(game, img_urls) if cache_key in cache: @@ -47,7 +51,7 @@ def generate_headline_and_content_from_images(img_urls: list[str], game: str): "type": "function", "function": { "name": "generate_update_text", - "description": "Generates a concise English headline and short description for a rhythm game update image.", + "description": "Generates a concise English headline and short description for a rhythm game update image and the original message content.", "parameters": { "type": "object", "properties": { @@ -73,7 +77,7 @@ def generate_headline_and_content_from_images(img_urls: list[str], game: str): { "type": "text", "text": ( - f"Given one or more update-related images for the arcade game {game}, return a short, professional English headline and a brief, stern and concise description summarizing the content. No need to repeat game name" + f"Given one or more update-related images for the arcade game {game} and the original Discord message content (limited to 500 characters): '{message_content}', return a short, professional English headline and a brief, stern and concise description summarizing the content. No need to repeat game name" ), }, *[{"type": "image_url", "image_url": {"url": url}} for url in img_urls], |
