Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Google Gemini support #78

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docs/AffiliateMarketing.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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).
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ assemblyai
srt_equalizer
undetected_chromedriver
platformdirs
google-generativeai
11 changes: 11 additions & 0 deletions src/classes/AFM.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
27 changes: 18 additions & 9 deletions src/classes/Twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down
11 changes: 11 additions & 0 deletions src/classes/YouTube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
9 changes: 9 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down