agent_1 / tools /blog_tools.py
jojopp's picture
personalised blog
5567345
raw
history blame
3.06 kB
from smolagents import tool
from typing import List, Dict
import re
import yaml
from app import DuckDuckGoSearchTool
# Load style guide
with open("style_guide.yaml", 'r') as f:
style_guide = yaml.safe_load(f)
@tool
def generate_blog_section(topic: str, section_title: str) -> str:
"""Generates content for a specific section of the blog post, following Joséphine's style:
- Direct and conversational tone
- Short, clear sentences
- Personal but professional
- Draws from AI product experience when relevant
Args:
topic: The main topic of the blog post
section_title: The title of the section to generate
"""
# First, get some background information
search_tool = DuckDuckGoSearchTool(max_results=3)
try:
search_query = f"{topic} {section_title}"
research = search_tool.forward(search_query)
# Format the content in your style
content = f"# {section_title}\n\n"
content += f"Let me share my perspective on {topic} (specifically {section_title}). "
content += f"Based on my experience in scaling AI products and recent developments:\n\n"
content += f"{research}\n\n"
content += "I'll keep updating this as I learn more. Let me know if you'd like to discuss any specific aspects."
return content
except Exception as e:
return f"Error generating content: {str(e)}"
@tool
def improve_writing_style(text: str, style: str = "professional") -> str:
"""Improves the writing style while maintaining Joséphine's voice:
- Keeps direct, conversational tone
- Removes AI clichés
- Ensures natural flow
- Maintains authenticity
Args:
text: The text to improve
style: The desired writing style (e.g., professional, casual, academic)
"""
return f"Improved version of the text in {style} style"
@tool
def check_readability(text: str) -> Dict:
"""Analyzes the readability of the text, focusing on:
- Sentence length and clarity
- Natural flow
- Direct communication
- Professional but personal tone
Args:
text: The text to analyze
"""
words = len(text.split())
sentences = len(re.split(r'[.!?]+', text))
avg_words_per_sentence = words / max(sentences, 1)
return {
"word_count": words,
"sentence_count": sentences,
"avg_words_per_sentence": avg_words_per_sentence,
"readability_score": "Good" if avg_words_per_sentence < 15 else "Consider shorter sentences",
"style_notes": "Check for direct tone and clear communication"
}
@tool
def generate_seo_metadata(title: str, content: str) -> Dict:
"""Generates SEO metadata while maintaining authentic voice
Args:
title: The blog post title
content: The blog post content
"""
return {
"meta_description": f"A practical look at {title}",
"keywords": [word.lower() for word in title.split()],
"suggested_title_tags": [f"<h1>{title}</h1>"]
}