Skip to content

Commit

Permalink
feat: Add AI summary generation and bump version to 0.1.2
Browse files Browse the repository at this point in the history
- Introduced configuration options for AI summary generation in blog-ai-tool.toml, including a toggle and maximum length setting.
- Updated metadata generation logic in blog_seo.py to include AI-generated summaries based on the new configuration.
- Bumped project version to 0.1.2 in pyproject.toml and __init__.py to reflect the new features.
  • Loading branch information
Ryaang committed Dec 19, 2024
1 parent 2b39766 commit f418094
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions blog-ai-tool.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ generate_keywords = false # Whether to generate keywords
max_title_length = 100 # Maximum title length
max_description_length = 300 # Maximum description length
keyword_count = 5 # Number of keywords to generate
ai_summary = false # Whether to generate ai summary
ai_summary_length = 1000 # Maximum ai summary length

[translation]
use = true # Whether to translate articles
Expand Down
2 changes: 1 addition & 1 deletion blog-ai-tool/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .blog_seo import HugoBlogProcessor, metadata_blog_directory
from .main import load_config

__version__ = "0.1.1"
__version__ = "0.1.2"
__all__ = ["HugoBlogProcessor", "metadata_blog_directory", "load_config"]
15 changes: 12 additions & 3 deletions blog-ai-tool/blog_seo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ def __init__(self, api_key: str, base_url: str, model: str, language: str, confi
def generate_metadata(self, content: str) -> Dict[str, str]:
"""Generate metadata using OpenAI based on content"""
metadata_config = self.config["metadata"]
ai_summary_config = metadata_config["ai_summary"]
if ai_summary_config:
ai_summary_task = f"""4. Based on the following blog content, generate a summary (max {metadata_config['ai_summary_length']} words with plain text)"""
else:
ai_summary_task = ""
prompt = f"""Based on the following blog content, generate:
1. A concise title (max {metadata_config['max_title_length']} chars)
2. A brief description (max {metadata_config['max_description_length']} chars)
1. A concise title (max {metadata_config['max_title_length']} words)
2. A brief description (max {metadata_config['max_description_length']} words)
3. {metadata_config['keyword_count']} relevant keywords (space-separated)
{ai_summary_task}
The language should be {self.language}.
Content:
{content}
Format response as JSON with keys: title, description, keywords"""
Format response as JSON with keys: title, description, keywords{", summary" if ai_summary_config else ""}"""

response = self._call_openai(prompt)
return self._extract_json(response)
Expand All @@ -49,6 +55,9 @@ def process_markdown(self, file_path: str) -> None:
metadata['description'] = generated['description']
if not metadata.get('keywords'):
metadata['keywords'] = generated['keywords']
if generated.get("summary") and not metadata.get('summary'):
metadata['summary'] = generated['summary']


if needs_update:
# Create new post with updated metadata
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "blog-ai-tool"
version = "0.1.1"
version = "0.1.2"
description = "Generate seo content (title, description, keywords) for blog post with AI, support blog framework like Hexo, Hugo, etc."
readme = "README.md"
requires-python = ">=3.8"
Expand Down

0 comments on commit f418094

Please sign in to comment.