Spaces:
Running
Running
File size: 2,446 Bytes
ed65c68 5d970ca ed65c68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
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:
<Instruction>
- 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.
</Instruction>
"""
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]),
}
|