WIP- Try AI-Writer and Web research; working. Working on usuability aspects.

This commit is contained in:
AjaySi
2024-03-02 08:52:42 +05:30
parent a87a87a620
commit 87053406ba
14 changed files with 162 additions and 108 deletions

View File

@@ -1,7 +1,12 @@
import os
import sys
from .gpt_providers.openai_chat_completion import openai_chatgpt
from .gpt_providers.gemini_pro_text import gemini_text_response
from pathlib import Path
from dotenv import load_dotenv
load_dotenv(Path('../../.env'))
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()
@@ -11,20 +16,33 @@ logger.add(sys.stdout,
)
def generate_blog_title(blog_article, gpt_providers="openai"):
def generate_blog_title(blog_article, keywords=None, example_titles=None, num_titles=1):
"""
Given a blog title generate an outline for it
"""
prompt = ''
gpt_providers = os.environ["GPT_PROVIDER"]
logger.info("Generating blog title.")
prompt = f"""As a SEO expert, I will provide you with a blog content.
Your task is write a SEO optimized, call to action and engaging blog title for it.
Follows SEO best practises to suggest the blog title.
Please keep the titles concise, not exceeding 60 words.
Respond with only one title and no explanations.
Important: Your response should be in plaintext.
Generate blog title for this given blog content:\n '{blog_article}' """
if 'gemini' in gpt_providers:
if not keywords and not example_titles:
prompt = f"""As a SEO expert, I will provide you with a blog content.
Your task is write a SEO optimized and call to action, blog title for given blog content.
Follow SEO best practises to suggest the blog title.
Please keep the titles concise, not exceeding 60 words.
Respond with only {num_titles} title and no explanations.
Negative Keywords: Unvieling, unleash, power of. Dont use such words in your title.
Generate {num_titles} blog title for this given blog content:\n '{blog_article}' """
elif keywords and example_titles:
prompt = f"""As a SEO expert, I will provide you with my blog keywords and example titles.
Your task is to write {num_titles} blog title.
Ensure that your blog titles will help in competing against given example titles.
Follow SEO best practises to suggest the blog title.
Please keep the titles concise, not exceeding 60 words.
Respond with only {num_titles} title and no explanations.
Negative Keywords: Unvieling, unleash, power of. Dont use such words in your title.
Blog Keywords: '{keywords}'
Example Titles: '{example_titles}'
"""
if 'google' in gpt_providers:
try:
response = gemini_text_response(prompt)
return response