WIP - Code refactoring
This commit is contained in:
@@ -22,7 +22,7 @@ from ..ai_web_researcher.you_web_reseacher import get_rag_results, search_ydc_in
|
||||
from ..blog_metadata.get_blog_metadata import blog_metadata
|
||||
from ..blog_postprocessing.save_blog_to_file import save_blog_to_file
|
||||
from ..blog_postprocessing.blog_proof_reader import blog_proof_editor
|
||||
|
||||
from ..blog_postprocessing.humanize_blog import blog_humanize
|
||||
|
||||
|
||||
def write_blog_from_keywords(search_keywords, url=None):
|
||||
@@ -48,32 +48,32 @@ def write_blog_from_keywords(search_keywords, url=None):
|
||||
# logger.info/check the final blog content.
|
||||
logger.info(f"######### Blog content Google SERP research: ###########\n\n{blog_markdown_str}\n\n")
|
||||
|
||||
# # Do Tavily AI research to augument the above blog.
|
||||
# try:
|
||||
# tavily_search_result, t_titles = do_tavily_ai_search(search_keywords)
|
||||
# example_blog_titles.append(t_titles)
|
||||
# blog_markdown_str = blog_with_research(blog_markdown_str, tavily_search_result)
|
||||
# logger.info(f"######### Blog content after Tavily AI research: ######### \n\n{blog_markdown_str}\n\n")
|
||||
# except Exception as err:
|
||||
# logger.error(f"Failed to do Tavily AI research: {err}")
|
||||
#
|
||||
# try:
|
||||
# # Do Metaphor/Exa AI search.
|
||||
# metaphor_search_result, m_titles = do_metaphor_ai_research(search_keywords)
|
||||
# example_blog_titles.append(m_titles)
|
||||
# blog_markdown_str = blog_with_research(blog_markdown_str, metaphor_search_result)
|
||||
# logger.info(f"######## Blog content after EXA AI research: ########## \n\n{blog_markdown_str}\n\n")
|
||||
# except Exception as err:
|
||||
# logger.error(f"Failed to do Metaphor AI search: {err}")
|
||||
#
|
||||
# # Do Google trends analysis and combine with latest blog.
|
||||
# try:
|
||||
# pytrends_search_result = do_google_pytrends_analysis(search_keywords)
|
||||
# logger.info(f"Google Trends keywords to use in the blog: {pytrends_search_result}\n")
|
||||
# blog_markdown_str = blog_with_keywords(blog_markdown_str, pytrends_search_result)
|
||||
# except Exception as err:
|
||||
# logger.error(f"Failed to do Google Trends Analysis:{err}")
|
||||
# logger.info(f"########### Blog Content After Google Trends Analysis:######### \n {blog_markdown_str}\n\n")
|
||||
# Do Tavily AI research to augument the above blog.
|
||||
try:
|
||||
tavily_search_result, t_titles = do_tavily_ai_search(search_keywords)
|
||||
example_blog_titles.append(t_titles)
|
||||
blog_markdown_str = blog_with_research(blog_markdown_str, tavily_search_result)
|
||||
logger.info(f"######### Blog content after Tavily AI research: ######### \n\n{blog_markdown_str}\n\n")
|
||||
except Exception as err:
|
||||
logger.error(f"Failed to do Tavily AI research: {err}")
|
||||
|
||||
try:
|
||||
# Do Metaphor/Exa AI search.
|
||||
metaphor_search_result, m_titles = do_metaphor_ai_research(search_keywords)
|
||||
example_blog_titles.append(m_titles)
|
||||
blog_markdown_str = blog_with_research(blog_markdown_str, metaphor_search_result)
|
||||
logger.info(f"######## Blog content after EXA AI research: ########## \n\n{blog_markdown_str}\n\n")
|
||||
except Exception as err:
|
||||
logger.error(f"Failed to do Metaphor AI search: {err}")
|
||||
|
||||
# Do Google trends analysis and combine with latest blog.
|
||||
try:
|
||||
pytrends_search_result = do_google_pytrends_analysis(search_keywords)
|
||||
logger.info(f"Google Trends keywords to use in the blog: {pytrends_search_result}\n")
|
||||
blog_markdown_str = blog_with_keywords(blog_markdown_str, pytrends_search_result)
|
||||
except Exception as err:
|
||||
logger.error(f"Failed to do Google Trends Analysis:{err}")
|
||||
logger.info(f"########### Blog Content After Google Trends Analysis:######### \n {blog_markdown_str}\n\n")
|
||||
|
||||
# Combine YOU.com RAG search with the latest blog content.
|
||||
#you_rag_result = get_rag_results(search_keywords)
|
||||
@@ -81,6 +81,9 @@ def write_blog_from_keywords(search_keywords, url=None):
|
||||
#blog_markdown_str = blog_with_research(blog_markdown_str, you_search_result)
|
||||
#logger.info(f"Final blog content: {blog_markdown_str}")
|
||||
|
||||
# Pass the content to remove obivious words used by AI.
|
||||
blog_markdown_str = blog_humanize(blog_markdown_str)
|
||||
# Pass the final content for proofreading.
|
||||
blog_markdown_str = blog_proof_editor(blog_markdown_str)
|
||||
|
||||
blog_title, blog_meta_desc, blog_tags, blog_categories = blog_metadata(blog_markdown_str,
|
||||
|
||||
34
lib/blog_postprocessing/humanize_blog.py
Normal file
34
lib/blog_postprocessing/humanize_blog.py
Normal file
@@ -0,0 +1,34 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv(Path('../../.env'))
|
||||
|
||||
from ..gpt_providers.gemini_pro_text import gemini_text_response
|
||||
from ..gpt_providers.openai_text_gen import openai_chatgpt
|
||||
|
||||
|
||||
def blog_humanize(blog_content):
|
||||
""" Helper for blog proof reading. """
|
||||
gpt_provider = os.environ["GPT_PROVIDER"]
|
||||
|
||||
prompt = f"""As an expert content writer and editor, I will provide you with blog content.
|
||||
|
||||
Your task is to replace all occurances of words given below:
|
||||
['It’s important to note', 'Delve into', 'Tapestry', 'Bustling', 'In summary', 'In conclusion', 'Unleash', 'Unveiling', 'ever-evolving', '', 'Remember that', 'Take a dive into', 'Navigating', 'Navigating the landscape', 'Navigating the complexities of', 'Landscape', 'The landscape of', 'Testament', 'a testament to', 'In the world of', 'Realm', 'Embark', 'virtuoso', 'Let's explore', 'symphony', 'Harnessing', 'Revolutionizing', 'Empower', 'game changing', 'ever-changing', 'Embrace', 'Embracing', 'game-changing', 'ever-evolving']
|
||||
|
||||
\n\nBlog Content: '{blog_content}'
|
||||
"""
|
||||
if 'openai' in gpt_provider.lower():
|
||||
try:
|
||||
response = openai_chatgpt(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Openai Error Blog Proof Reading: {err}")
|
||||
elif 'google' in gpt_provider.lower():
|
||||
try:
|
||||
response = gemini_text_response(prompt)
|
||||
return response
|
||||
except Exception as err:
|
||||
SystemError(f"Gemini Error Blog Proof Reading: {err}")
|
||||
@@ -20,8 +20,8 @@ blog_demographic = "All"
|
||||
# informational, commercial, company, news, finance, competitor, programming, scholar etc
|
||||
blog_type = "Informational"
|
||||
|
||||
# German, Chinese, Arabic, Nepali, Hindi, Hindustani etc
|
||||
blog_language = "Spanish"
|
||||
# Spanish, German, Chinese, Arabic, Nepali, Hindi, Hindustani etc
|
||||
blog_language = "English"
|
||||
|
||||
# Specify the output format of the blog as: HTML, markdown, plaintext. Defaults to markdown.
|
||||
blog_output_format = "markdown"
|
||||
|
||||
Reference in New Issue
Block a user