diff --git a/config.example.json b/config.example.json index 7c51646..f4bfb7a 100644 --- a/config.example.json +++ b/config.example.json @@ -20,6 +20,7 @@ "scraper_timeout": 300, "outreach_message_subject": "I have a question...", "outreach_message_body_file": "outreach_message.html", + "gemini_api_key": "", "assembly_ai_api_key": "", "font": "bold_font.ttf", "imagemagick_path": "Path to magick.exe or on linux/macOS just /usr/bin/convert" diff --git a/docs/AffiliateMarketing.md b/docs/AffiliateMarketing.md index e7c803e..53c82ca 100644 --- a/docs/AffiliateMarketing.md +++ b/docs/AffiliateMarketing.md @@ -1,6 +1,6 @@ # AFM -This class is responsible for the Affiliate Marketing part of MPV2. It uses the `g4f` package (as all other classes) as it's way to utilize the power of LLMs, in this case, to generate tweets, based on information about an **Amazon Product**. MPV2 will scrape the page of the product, and save the **product title**, and **product features**, thus having enough information to be able to create a pitch for the product, and post it on Twitter. +This class is responsible for the Affiliate Marketing part of MPV2. It uses the `g4f` or `google_gen_ai` package (as all other classes) as it's way to utilize the power of LLMs, in this case, to generate tweets, based on information about an **Amazon Product**. MPV2 will scrape the page of the product, and save the **product title**, and **product features**, thus having enough information to be able to create a pitch for the product, and post it on Twitter. ## Relevant Configuration diff --git a/docs/Configuration.md b/docs/Configuration.md index 0658032..c0dfe92 100644 --- a/docs/Configuration.md +++ b/docs/Configuration.md @@ -14,6 +14,7 @@ All your configurations will be in a file in the root directory, called `config. * `llama2_13b` * `llama2_70b` * `mixtral_8x7b` + * `google` - `image_prompt_llm`: `string` - The Large Language Model that will be used to generate image prompts. If left empty, the default model (`gpt35_turbo`) will be used. Here are your choices: * `gpt4` * `gpt35_turbo` @@ -45,6 +46,7 @@ All your configurations will be in a file in the root directory, called `config. - `scraper_timeout`: `number` - The timeout for the Google Maps scraper. - `outreach_message_subject`: `string` - The subject of your outreach message. `{{COMPANY_NAME}}` will be replaced with the company name. - `outreach_message_body_file`: `string` - The file that contains the body of your outreach message, should be HTML. `{{COMPANY_NAME}}` will be replaced with the company name. +- `gemini_api_key`: `string` - Your Google Gemini API key. Get yours from [here](https://ai.google.dev) - `assembly_ai_api_key`: `string` - Your Assembly AI API key. Get yours from [here](https://www.assemblyai.com/app/). - `font`: `string` - The font that will be used to generate images. This should be a `.ttf` file in the `fonts/` directory. - `imagemagick_path`: `string` - The path to the ImageMagick binary. This is used by MoviePy to manipulate images. Install ImageMagick from [here](https://imagemagick.org/script/download.php) and set the path to the `magick.exe` on Windows, or on Linux/MacOS the path to `convert` (usually /usr/bin/convert). diff --git a/requirements.txt b/requirements.txt index de671b3..fcf52ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,4 @@ assemblyai srt_equalizer undetected_chromedriver platformdirs +google-generativeai diff --git a/src/classes/AFM.py b/src/classes/AFM.py index 044934f..168a781 100644 --- a/src/classes/AFM.py +++ b/src/classes/AFM.py @@ -99,6 +99,17 @@ def generate_response(self, prompt: str) -> str: Returns: response (str): The response for the user. """ + if get_model() == "google": + import google.generativeai as genai + + genai.configure(api_key=get_gemini_api_key()) + + model = genai.GenerativeModel('gemini-pro') + + response: str = model.generate_content(prompt).text + + return response + # Generate the response response: str = g4f.ChatCompletion.create( model=parse_model(get_model()), diff --git a/src/classes/Twitter.py b/src/classes/Twitter.py index 020122f..de5a85c 100644 --- a/src/classes/Twitter.py +++ b/src/classes/Twitter.py @@ -175,15 +175,24 @@ def generate_post(self) -> str: Returns: post (str): The post """ - completion = g4f.ChatCompletion.create( - model=parse_model(get_model()), - messages=[ - { - "role": "user", - "content": f"Generate a Twitter post about: {self.topic} in {get_twitter_language()}. The Limit is 2 sentences. Choose a specific sub-topic of the provided topic." - } - ] - ) + if get_model() == "google": + import google.generativeai as genai + + genai.configure(api_key=get_gemini_api_key()) + prompt = f"Generate a Twitter post about: {self.topic} in {get_twitter_language()}. The Limit is 2 sentences. Choose a specific sub-topic of the provided topic." + model = genai.GenerativeModel('gemini-pro') + + completion = model.generate_content(prompt).text + else: + completion = g4f.ChatCompletion.create( + model=parse_model(get_model()), + messages=[ + { + "role": "user", + "content": f"Generate a Twitter post about: {self.topic} in {get_twitter_language()}. The Limit is 2 sentences. Choose a specific sub-topic of the provided topic." + } + ] + ) if get_verbose(): info("Generating a post...") diff --git a/src/classes/YouTube.py b/src/classes/YouTube.py index 8250278..aa069cc 100644 --- a/src/classes/YouTube.py +++ b/src/classes/YouTube.py @@ -112,6 +112,17 @@ def generate_response(self, prompt: str, model: any = None) -> str: Returns: response (str): The generated AI Repsonse. """ + if get_model() == "google": + import google.generativeai as genai + + genai.configure(api_key=get_gemini_api_key()) + + model = genai.GenerativeModel('gemini-pro') + + response: str = model.generate_content(prompt).text + + return response + if not model: return g4f.ChatCompletion.create( model=parse_model(get_model()), diff --git a/src/config.py b/src/config.py index 17c8790..7e2821f 100644 --- a/src/config.py +++ b/src/config.py @@ -188,6 +188,15 @@ def get_outreach_message_body_file() -> str: """ with open(os.path.join(ROOT_DIR, "config.json"), "r") as file: return json.load(file)["outreach_message_body_file"] +def get_gemini_api_key() -> str: + """ + Gets the Google Gemini API key. + + Returns: + key (str): The Gemini API key + """ + with open(os.path.join(ROOT_DIR, "config.json"), "r") as file: + return json.load(file)["gemini_api_key"] def get_assemblyai_api_key() -> str: """