Skip to content

Commit

Permalink
Try Essay, story, Audio to Blog
Browse files Browse the repository at this point in the history
  • Loading branch information
AJaySi committed Apr 17, 2024
1 parent 80c52fa commit d2bb42c
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 34 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To start using this tool, simply follow one of the options below:

---
### Option 1: FOLLOW-ME Local Laptop Install 💻 **(WINDOWS)**

#### Step 0 **Pre-requisites:** Git, Python3
---

Expand Down Expand Up @@ -43,7 +43,7 @@ To clone the repository to your local machine, perform the following steps:
2. **Navigate to the Desired Directory:** Use the 'cd' command to move to the directory where you want to clone the repository.

3. **Clone the Repository:** Run the following command in PowerShell to clone the repository:
`git clone https://github.com/AJaySi/AI-Blog-Writer.git`
`git clone https://github.com/AJaySi/AI-Writer.git`
This command will download all the files from the repository to your local machine.

4. **Verify the Clone:** After the cloning process is complete, navigate into the newly created directory using:
Expand Down
36 changes: 17 additions & 19 deletions alwrity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from pathlib import Path
import configparser
from datetime import datetime

import typer
from prompt_toolkit.shortcuts import checkboxlist_dialog, message_dialog, input_dialog
Expand Down Expand Up @@ -433,55 +434,50 @@ def do_web_research():

def check_llm_environs():
""" Function to check which LLM api is given. """
# Check if GPT_PROVIDER is defined in .env file
gpt_provider = os.getenv("GPT_PROVIDER")

# Load .env file
load_dotenv()

# Check if GPT_PROVIDER is defined in .env file
gpt_provider = os.getenv("GPT_PROVIDER")

# Disable unsupported GPT providers
supported_providers = ['google', 'openai', 'mistralai']
if gpt_provider is None or gpt_provider.lower() not in supported_providers:
#message_dialog(
# title="Unsupported GPT Provider",
# text="GPT_PROVIDER is not set or has an unsupported value."
#).run()

if gpt_provider is None or gpt_provider not in supported_providers:
# Prompt user to select a provider
selected_provider = radiolist_dialog(
title='Select your preferred GPT provider:',
text="Please choose GPT provider Below:\n👺Google Gemini recommended, its 🆓.",
values=[
("Google", "google"),
("Openai", "openai"),
("Google", "Google"),
("OpenAI", "OpenAI"),
("MistralAI/WIP", "mistralai/WIP"),
("Ollama", "Ollama (TBD)")
]
).run()
if selected_provider:
gpt_provider = selected_provider
gpt_provider = selected_provider
os.environ["GPT_PROVIDER"] = gpt_provider

if gpt_provider.lower() == "google":
if gpt_provider == "Google":
api_key_var = "GEMINI_API_KEY"
missing_api_msg = f"To get your {api_key_var}, please visit: https://aistudio.google.com/app/apikey"
elif gpt_provider.lower() == "openai":
elif gpt_provider == "OpenAI":
api_key_var = "OPENAI_API_KEY"
missing_api_msg = "To get your OpenAI API key, please visit: https://openai.com/blog/openai-api"
elif gpt_provider.lower() == "mistralai":
elif gpt_provider == "mistralai":
api_key_var = "MISTRAL_API_KEY"
missing_api_msg = "To get your MistralAI API key, please visit: https://mistralai.com/api"

if os.getenv(api_key_var) is None:
# Ask for the API key
print(f"🚫The {api_key_var} is missing. {missing_api_msg}")
api_key = typer.prompt(f"\n🙆🙆Please enter {api_key_var} API Key:")

# Update .env file
with open(".env", "a", encoding="utf-8") as env_file:
env_file.write(f"GPT_PROVIDER={gpt_provider.lower()}\n")
env_file.write(f"GPT_PROVIDER={gpt_provider}\n")
env_file.write(f"{api_key_var}={api_key}\n")



def check_internet():
try:
response = requests.get("http://www.google.com", timeout=20)
Expand Down Expand Up @@ -520,5 +516,7 @@ def create_env_file():
check_search_apis()
print("Check LLM details & AI Model to use.")
check_llm_environs()
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace",
"web_research_report" + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
load_dotenv(Path('.env'))
app()
4 changes: 0 additions & 4 deletions lib/ai_web_researcher/gpt_online_researcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
def gpt_web_researcher(search_keywords):
""" Keyword based web researcher, basic, neural and Semantic search."""

# TBD: Keeping the results directory as fixed, for now.
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace",
search_keywords.replace(" ", "_") + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))

try:
google_search_result = do_google_serp_search(search_keywords)
tavily_search_result = do_tavily_ai_search(search_keywords)
Expand Down
4 changes: 0 additions & 4 deletions lib/ai_writers/keywords_to_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def write_blog_from_keywords(search_keywords, url=None):
This function will take a blog Topic to first generate sections for it
and then generate content for each section.
"""
# TBD: Keeping the results directory as fixed, for now.
os.environ["SEARCH_SAVE_FILE"] = os.path.join(os.getcwd(), "workspace", "web_research_reports",
search_keywords.replace(" ", "_") + "_" + datetime.now().strftime("%Y-%m-%d_%H-%M-%S"))
# Use to store the blog in a string, to save in a *.md file.
blog_markdown_str = ""
example_blog_titles = []
Expand All @@ -48,7 +45,6 @@ def write_blog_from_keywords(search_keywords, url=None):
# logger.info/check the final blog content.
logger.info("\n######### Draft1: Finished Blog from Google web search: ###########\n\n")


# Do Tavily AI research to augument the above blog.
try:
tavily_search_result, t_titles = do_tavily_ai_search(search_keywords)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def youtube_to_blog(video_url):

try:
# Summarizing the content of the YouTube video
audio_blog_content = summarize_youtube_video(audio_text, "gemini")
audio_blog_content = summarize_youtube_video(audio_text)
logger.info("Successfully converted given URL to blog article.")
return audio_blog_content, audio_title
except Exception as e:
logger.error(f"Error in summarize_youtube_video: {e}")
sys.exit(1) # Exit the program due to error in summarize_youtube_video


def summarize_youtube_video(user_content, gpt_providers):
def summarize_youtube_video(user_content):
"""Generates a summary of a YouTube video using OpenAI GPT-3 and displays a progress bar.
Args:
video_link: The URL of the YouTube video to summarize.
Expand Down
4 changes: 1 addition & 3 deletions lib/gpt_providers/text_generation/main_text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def llm_text_gen(prompt):
# Check if API key is provided for the given gpt_provider
get_api_key(gpt_provider)

logger.info(f"Temp: {temperature}, MaxTokens: {max_tokens}, TopP: {top_p}, N: {n}, FrequencyPenalty: {fp}")
# Perform text generation using the specified LLM parameters and prompt
if 'google' in gpt_provider.lower():
try:
Expand Down Expand Up @@ -69,9 +68,8 @@ def check_gpt_provider(gpt_provider):
ValueError: If both the specified GPT provider and environment variable GPT_PROVIDER are missing.
"""
env_gpt_provider = os.getenv('GPT_PROVIDER')
if gpt_provider and gpt_provider != env_gpt_provider:
if gpt_provider and gpt_provider.lower() != env_gpt_provider.lower():
logger.warning(f"Config: '{gpt_provider}' different to environment variable 'GPT_PROVIDER' '{env_gpt_provider}'")
logger.info(f"Using Environment GPT provider: {env_gpt_provider}")
gpt_provider = env_gpt_provider

return gpt_provider
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ nltk
prompt_toolkit
ipython
html2image
lxml_html_clean

0 comments on commit d2bb42c

Please sign in to comment.