diff --git a/README.md b/README.md index e9461c8d..511942b5 100644 --- a/README.md +++ b/README.md @@ -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 --- @@ -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: diff --git a/alwrity.py b/alwrity.py index 0b40beb1..6f901af0 100644 --- a/alwrity.py +++ b/alwrity.py @@ -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 @@ -433,41 +434,35 @@ 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" @@ -475,13 +470,14 @@ def check_llm_environs(): # 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) @@ -520,5 +516,7 @@ if __name__ == "__main__": 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() diff --git a/lib/ai_web_researcher/gpt_online_researcher.py b/lib/ai_web_researcher/gpt_online_researcher.py index 16ec8f2a..68af625c 100644 --- a/lib/ai_web_researcher/gpt_online_researcher.py +++ b/lib/ai_web_researcher/gpt_online_researcher.py @@ -45,10 +45,6 @@ logger.add(sys.stdout, 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) diff --git a/lib/ai_writers/keywords_to_blog.py b/lib/ai_writers/keywords_to_blog.py index 362feb7d..1728c6d6 100644 --- a/lib/ai_writers/keywords_to_blog.py +++ b/lib/ai_writers/keywords_to_blog.py @@ -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 = [] @@ -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) diff --git a/lib/ai_writers/speech_to_blog/write_blogs_from_youtube_videos.py b/lib/ai_writers/speech_to_blog/write_blogs_from_youtube_videos.py index d0847ab6..62fbe6d9 100644 --- a/lib/ai_writers/speech_to_blog/write_blogs_from_youtube_videos.py +++ b/lib/ai_writers/speech_to_blog/write_blogs_from_youtube_videos.py @@ -36,7 +36,7 @@ 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: @@ -44,7 +44,7 @@ def youtube_to_blog(video_url): 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. diff --git a/lib/gpt_providers/text_generation/main_text_generation.py b/lib/gpt_providers/text_generation/main_text_generation.py index 7cf16479..1fe5cade 100644 --- a/lib/gpt_providers/text_generation/main_text_generation.py +++ b/lib/gpt_providers/text_generation/main_text_generation.py @@ -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: @@ -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 diff --git a/requirements.txt b/requirements.txt index 9b8687b1..d0dc886f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,3 +24,4 @@ nltk prompt_toolkit ipython html2image +lxml_html_clean