WIP- Under maintenence- Web research working.
This commit is contained in:
37
lib/blog_sections/faqs_generator_blog.py
Normal file
37
lib/blog_sections/faqs_generator_blog.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import sys
|
||||
|
||||
from .gpt_providers.openai_chat_completion import openai_chatgpt
|
||||
from .gpt_providers.gemini_pro_text import gemini_text_response
|
||||
|
||||
from loguru import logger
|
||||
logger.remove()
|
||||
logger.add(sys.stdout,
|
||||
colorize=True,
|
||||
format="<level>{level}</level>|<green>{file}:{line}:{function}</green>| {message}"
|
||||
)
|
||||
|
||||
|
||||
def generate_blog_faq(blog_article, gpt_providers="openai"):
|
||||
"""
|
||||
Given a blog title generate an outline for it
|
||||
"""
|
||||
logger.info("Generating blog FAQs.")
|
||||
prompt = f"""As an expert writer, I will provide you with blog content below.
|
||||
Your task is to write 5 FAQs based on the given blog content.
|
||||
Always, write fact based answers. Use emojis where applicable.
|
||||
You must reply in MARKDOWN format.
|
||||
blog content: '{blog_article}' """
|
||||
|
||||
if 'gemini' in gpt_providers:
|
||||
try:
|
||||
response = gemini_text_response(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
logger.error(f"Failed to get response from gemini: {err}")
|
||||
elif 'openai' in gpt_providers:
|
||||
try:
|
||||
logger.info("Calling OpenAI LLM.")
|
||||
response = openai_chatgpt(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Failed to get response from Openai: {err}")
|
||||
15
lib/blog_sections/get_blog_conclusion.py
Normal file
15
lib/blog_sections/get_blog_conclusion.py
Normal file
@@ -0,0 +1,15 @@
|
||||
def get_blog_conclusion(blog_content):
|
||||
"""
|
||||
Accepts a blog content and concludes it.
|
||||
"""
|
||||
prompt = f"""As an expert SEO and blog writer, please conclude the given blog providing vital take aways,
|
||||
summarise key points (no more than 300 characters) in bullet points. The blog content: {blog_content}
|
||||
"""
|
||||
logger.info(f"Generating blog conclusion iwth prompt: {prompt}")
|
||||
try:
|
||||
# TBD: Add logic for which_provider and which_model
|
||||
response = openai_chatgpt(prompt)
|
||||
except Exception as err:
|
||||
SystemError(f"Error in generating blog conclusion: {err}")
|
||||
else:
|
||||
return response
|
||||
16
lib/blog_sections/get_blog_intro.py
Normal file
16
lib/blog_sections/get_blog_intro.py
Normal file
@@ -0,0 +1,16 @@
|
||||
def get_blog_intro(blog_title, blog_topics):
|
||||
"""
|
||||
Generate blog introduction as per title and sub topics
|
||||
"""
|
||||
prompt = f"""As a skilled wordsmith, I'll equip you with a blog title and relevant topics, tasking you with crafting an engaging introduction. Your challenge: Create a brief, compelling entry that entices readers to explore the entire post. This introduction must be concise (under 250 characters) yet powerful, clearly stating the blog's purpose and what readers stand to gain. Reply with only the introduction.
|
||||
|
||||
Intrigue your audience from the start with vibrant language, employing strong verbs and vivid descriptions. Address a common challenge your readers face, demonstrating empathy and positioning yourself as their go-to expert. Pose thought-provoking questions that prompt reader engagement and contemplation.
|
||||
|
||||
Remember, your words matter. This introduction serves as the cornerstone of the blog post. It should not only captivate attention but also encourage deeper exploration. Additionally, strategically integrate relevant keywords to enhance visibility on search engine results pages (SERPs). Your mission: Craft a blog introduction that resonates, leaving readers eager to delve further into the titled piece: '{blog_title}', covering these sub-topics: {blog_topics}."""
|
||||
|
||||
try:
|
||||
# TBD: Add logic for which_provider and which_model
|
||||
response = openai_chatgpt(prompt)
|
||||
except Exception as err:
|
||||
SystemError(f"Error in generating Blog Introduction: {err}")
|
||||
return response
|
||||
18
lib/blog_sections/get_blog_outline.py
Normal file
18
lib/blog_sections/get_blog_outline.py
Normal file
@@ -0,0 +1,18 @@
|
||||
def generate_topic_outline(blog_title, num_subtopics):
|
||||
"""
|
||||
Given a blog title generate an outline for it
|
||||
"""
|
||||
# TBD: Remove hardcoding, make dynamic
|
||||
prompt = f"""As a SEO expert, suggest only {num_subtopics} beginner-friendly and
|
||||
insightful sub topics for the blog title: {blog_title}.
|
||||
Respond with only answer and no description, explanations."""
|
||||
|
||||
# The suggested {num_subtopics} outline should include few long-tailed keywords and most popular questions.
|
||||
# TBD: Include --niche
|
||||
logger.info(f"Prompt used for blog title Outline :\n{prompt}\n")
|
||||
# TBD: Add logic for which_provider and which_model
|
||||
try:
|
||||
response = openai_chatgpt(prompt)
|
||||
except Exception as err:
|
||||
SystemError(f"Error in generating Blog Title: {err}")
|
||||
return response
|
||||
47
lib/blog_sections/get_blog_topics.py
Normal file
47
lib/blog_sections/get_blog_topics.py
Normal file
@@ -0,0 +1,47 @@
|
||||
def generate_blog_topics(blog_keywords, num_blogs, niche):
|
||||
"""
|
||||
For a given prompt, generate blog topics.
|
||||
Using the davinci-instruct-beta-v3 model. It’s proven to be an ideal
|
||||
one for generating unique blog content.
|
||||
Ex: Generate SEO optimized blog topics on given keywords
|
||||
"""
|
||||
prompt = f"""As an SEO specialist and blog writer, write {num_blogs} catchy
|
||||
and SEO-friendly blog topics on {blog_keywords}. The blog title must be less than 80 characters.
|
||||
The blog titles must follow best SEO practises, be engaging and invite/tempt users to read full blog.
|
||||
Do not include descriptions, explanations. Do not number the result."""
|
||||
|
||||
# Beware of keywords stuffing, clustering, semantic should help avoid.
|
||||
if num_blogs > 5:
|
||||
# Get more keywords, based on user given keywords.
|
||||
more_keywords = get_related_keywords(num_blogs, blog_keywords, niche)
|
||||
prompt = prompt + """Use the following keywords wisely, without keyword stuffing: {more_keywords}"""
|
||||
|
||||
logger.info(f"Prompt used for generating blog topics: \n{prompt}\n")
|
||||
try:
|
||||
response = openai_chatgpt(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Error in generating blog topics: {err}")
|
||||
|
||||
|
||||
def get_related_keywords(num_blogs, keywords, niche):
|
||||
"""
|
||||
Helper function to get more keywords from GPTs.
|
||||
"""
|
||||
# Check if niche: use long tailed, else use popular keywords.
|
||||
if niche:
|
||||
prompt = (f"Generate a list without description of the top {num_blogs} most popular and semantically"
|
||||
f"related long-tailed keywords and entities for the topic of {keywords} that are used in"
|
||||
"high-quality content and relevant to my competitors."
|
||||
)
|
||||
else:
|
||||
prompt = (f"Generate a list without description of the top {num_blogs} most popular and"
|
||||
f" semantically related keywords and entities for the topic of {keywords} that are used"
|
||||
" in high-quality content and relevant to my competitors."
|
||||
)
|
||||
try:
|
||||
# TBD: Add logic for which_provider and which_model
|
||||
response = openai_chatgpt(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Error in getting related keywords.")
|
||||
37
lib/blog_sections/get_code_examples.py
Normal file
37
lib/blog_sections/get_code_examples.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
At the command line, only need to run once to install the package via pip:
|
||||
$ pip install google-generativeai
|
||||
"""
|
||||
from .gpt_providers.gemini_pro_text import gemini_text_response
|
||||
|
||||
|
||||
def gemini_get_code_samples(blog_article):
|
||||
""" Provide a programming blog and get code exmaples."""
|
||||
prompt = f"""As an expert programmer and copywriter, I will provide you with blog article.
|
||||
Your task is to research and write one code example for the given blog article.
|
||||
Do not include your explanations in response.
|
||||
Blog Article: '{blog_article}' """
|
||||
try:
|
||||
code_sample = gemini_text_response(prompt)
|
||||
response = combine_blog_code_sample(blog_article, code_sample)
|
||||
return response
|
||||
except Exception as err:
|
||||
raise ValueError(f"Failed to get response from Gemini pro: {err}")
|
||||
|
||||
|
||||
def combine_blog_code_sample(blog_article, code_sample):
|
||||
""" Include the code sample into the given blog. """
|
||||
prompt = """You are expert document editor, I will provide you blog article and a code sample.
|
||||
Your task is to edit the given blog article to include the code sample after the introduction section.
|
||||
Do not modify the content of the given blog article. Your response should include the whole blog_article with
|
||||
the code sample added to it.
|
||||
Adopt the formatting of the given blog article. Do not include explanations of your response.
|
||||
Edit the given blog to include the code sample in it.
|
||||
Blog Article: {blog_article}\n
|
||||
Code sample: {code_sample}\n"""
|
||||
|
||||
try:
|
||||
response = gemini_text_response(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
raise ValueError(f"Failed to combine blog and code: {err}")
|
||||
19
lib/blog_sections/get_topic_content.py
Normal file
19
lib/blog_sections/get_topic_content.py
Normal file
@@ -0,0 +1,19 @@
|
||||
def generate_topic_content(blog_keywords, sub_topic):
|
||||
"""
|
||||
For each of given topic generate content for it.
|
||||
"""
|
||||
# The outline should contain various subheadings and include the starting sentence for each section.
|
||||
# TBD: Depending on the usecase 'Voice and style' will change to professional etc.
|
||||
prompt = f"""As a professional blogger and topic authority on {blog_keywords},
|
||||
craft factual (no more than 200 characters) subtopic content on {sub_topic}.
|
||||
Your response should reflect Experience, Expertise, Authoritativeness and Trustworthiness from content.
|
||||
Voice and style guide: Write in a professional manner, giving enlightening details and reasons.
|
||||
Use natural language and phrases that a real person would use: in normal conversations.
|
||||
Format your response using markdown. REMEMBER Not to include introduction or conclusion in your response.
|
||||
Use headings(h3 to h6 only), subheadings, bullet points, and bold to organize the information."""
|
||||
logger.info(f"Generate topic content using prompt:\n{prompt}\n")
|
||||
try:
|
||||
response = openai_chatgpt(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Error in generating topic content: {err}")
|
||||
Reference in New Issue
Block a user