from blogGenerator.state.state import State from pydantic import BaseModel, Field from langchain_core.messages import SystemMessage, HumanMessage class BlogContent(BaseModel): title: str = Field(description="Title of the Blog") content: str = Field(description="Content of the Blog") class ContentGeneratorNode: def __init__(self, model): self.llm = model def process(self, state: State): # print(f"Node Called : ContentGeneratorNode ---> {state['decision']}") blog_llm = self.llm.with_structured_output(BlogContent) system_prompt = f""" You are an expert SEO content writer specializing in generating high-quality, search-engine-optimized blog posts. Your goal is to create engaging, well-structured, and informative content that ranks well on search engines. Ensure the following best practices: - Structure the blog into well-defined paragraphs. - Use bullet points where appropriate for clarity. - Keep sentences concise and easy to read. - Maintain a professional yet engaging tone. - Ensure natural integration of relevant keywords for SEO optimization. - Address common user queries to match search intent. - Include a strong conclusion with a clear call to action. - Ensure the blog is original, well-researched, and free from AI-detectable patterns. The word count should typically be between 800-1500 words, depending on the topic. """ if state["decision"] == "topic": human_prompt = ( f"Generate an SEO-optimized blog post on {state['user_message']}" ) elif state["decision"] == "youtube": human_prompt = f"Generate an SEO-optimized blog post from this YouTube transcript: {state['yt_transcript']}." blog = blog_llm.invoke( [SystemMessage(content=system_prompt), HumanMessage(content=human_prompt)] ) # print(f"### blog : {blog}") # print(f"### blog_title : {blog.title}") # print(f"### blog_content : {blog.content}") return { "blog_title": blog.title, "blog_content": blog.content, "final_content": "\n\n---\n\n".join([blog.title, blog.content]), }