Skip to content

Commit 450e211

Browse files
authored
Merge pull request #2 from martcpp/change_ai
Change AI
2 parents b0d6dd3 + a161fcf commit 450e211

File tree

3 files changed

+61
-30
lines changed

3 files changed

+61
-30
lines changed

.github/workflows/cron.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
CONSUMER_SECRET: ${{ secrets.CONSUMER_SECRET }}
4949
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
5050
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
51+
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
5152

5253
# Bot configuration
5354
BASE_URL: ${{ secrets.BASE_URL }}

requirements.txt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ aiohappyeyeballs==2.6.1
22
aiohttp==3.12.15
33
aiosignal==1.4.0
44
annotated-types==0.6.0
5-
anyio==4.3.0
5+
anyio==4.11.0
66
appdirs==1.4.4
77
async-lru==2.0.4
88
attrs==23.2.0
@@ -12,69 +12,93 @@ black==25.1.0
1212
boolean.py==5.0
1313
bs4==0.0.2
1414
CacheControl==0.14.3
15+
cachetools==6.2.2
1516
certifi==2025.8.3
1617
charset-normalizer==3.3.2
1718
click==8.2.1
1819
colorama==0.4.6
1920
cssselect==1.2.0
2021
cyclonedx-python-lib==9.1.0
22+
decorator==5.2.1
2123
defusedxml==0.7.1
2224
distro==1.9.0
25+
docx==0.2.4
2326
fake-useragent==1.5.1
2427
filelock==3.18.0
2528
flake8==7.3.0
2629
frozenlist==1.4.1
30+
google-auth==2.43.0
31+
google-genai==1.50.1
32+
greenlet==3.2.3
33+
groq==0.33.0
2734
h11==0.14.0
2835
httpcore==1.0.3
29-
httpx==0.26.0
36+
httpx==0.28.1
3037
idna==3.10
38+
imageio==2.37.0
39+
imageio-ffmpeg==0.6.0
3140
importlib_metadata==7.1.0
41+
jiter==0.11.1
3242
license-expression==30.4.4
3343
lxml==5.2.1
3444
lxml_html_clean==0.4.2
3545
markdown-it-py==3.0.0
3646
mccabe==0.7.0
3747
mdurl==0.1.2
3848
meta_ai_api==1.1.7
49+
moviepy==2.2.1
3950
msgpack==1.1.1
4051
multidict==6.0.5
4152
mypy_extensions==1.1.0
53+
numpy==2.3.2
4254
oauthlib==3.2.2
43-
openai==0.28.0
55+
openai==2.6.1
4456
packageurl-python==0.17.3
4557
packaging==25.0
4658
parse==1.20.1
4759
pathspec==0.12.1
60+
pillow==11.3.0
4861
pip-api==0.0.34
4962
pip-requirements-parser==32.0.1
5063
pip_audit==2.9.0
5164
platformdirs==4.3.8
65+
playwright==1.54.0
66+
proglog==0.1.12
5267
propcache==0.3.2
5368
py-serializable==2.1.0
69+
pyasn1==0.6.1
70+
pyasn1_modules==0.4.2
5471
pycodestyle==2.14.0
55-
pydantic==2.6.1
56-
pydantic_core==2.16.2
57-
pyee==11.1.0
72+
pydantic==2.12.4
73+
pydantic_core==2.41.5
74+
pyee==13.0.0
5875
pyflakes==3.4.0
5976
Pygments==2.19.2
6077
pyparsing==3.2.3
6178
pyppeteer==2.0.0
6279
pyquery==2.0.0
6380
python-decouple==3.8
81+
python-docx==1.2.0
82+
python-dotenv==1.1.1
83+
reportlab==4.4.4
6484
requests==2.32.4
6585
requests-html==0.10.0
6686
requests-oauthlib==1.3.1
6787
rich==14.1.0
88+
rsa==4.9.1
6889
ruff==0.12.7
6990
sniffio==1.3.0
7091
sortedcontainers==2.4.0
7192
soupsieve==2.5
93+
tenacity==9.1.2
94+
TikTokApi==7.1.0
7295
toml==0.10.2
7396
tqdm==4.67.1
7497
tweepy==4.14.0
75-
typing_extensions==4.9.0
98+
typing-inspection==0.4.2
99+
typing_extensions==4.15.0
76100
urllib3==1.26.20
77101
w3lib==2.1.2
78-
websockets==10.4
102+
websockets==15.0.1
79103
yarl==1.20.1
80104
zipp==3.18.1

src/bibleAI.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from meta_ai_api import MetaAI
1+
from google import genai
2+
import os
23
import time
4+
from decouple import config
35
from utills import fallback_response, logger_setup, check_quotes
46

5-
ai = MetaAI()
7+
api_key = config("GEMINI_API_KEY") or os.getenv("GEMINI_API_KEY")
8+
client = genai.Client(api_key=api_key)
69

710

811
logger = logger_setup()
@@ -15,9 +18,11 @@ def get_ai_response(prompt, max_retries=3, retry_delay=1):
1518
"""Get AI response with retry logic"""
1619
for attempt in range(max_retries):
1720
try:
18-
response = ai.prompt(message=prompt)
19-
if response and "message" in response:
20-
return response
21+
response = client.models.generate_content(
22+
model="gemini-2.0-flash-001", contents=prompt # "gemini-2.5-pro",
23+
)
24+
if response.text:
25+
return response.text
2126
logger.error(f"Invalid response format, attempt {attempt + 1}")
2227
except Exception as e:
2328
logger.error(f"API error on attempt {attempt + 1}: {e}")
@@ -33,12 +38,12 @@ def bible_verse(verse):
3338
"""Generate bible verse explanation and prayer with optimizations"""
3439

3540
# Primary prompts - more spiritual and engaging
36-
explanation_prompt = f"""Write a powerful, heart-touching explanation of "{verse}" that makes people feel God's love personally. Connect it to real-life struggles, speak with warmth and hope, make it deeply encouraging and relatable. Use simple but profound language that touches both heart and soul. Keep it under 270 characters and make people want to share it. with some nice hashtags."""
37-
prayer_prompt = f"""faith filled, spirit filled prayer based on "{verse}" that people can declare over their lives with confidence. Make it specific, personal, and powerful - like speaking directly to God as a loving Father. Include breakthrough, blessing, and transformation. Write it as a declaration of faith under 270 characters that builds expectation for God's goodness."""
41+
explanation_prompt = f"""Write a powerful, heart-touching explanation of "{verse}" that makes people feel God's love personally. Connect it to real-life struggles, speak with warmth and hope, make it deeply encouraging and relatable. Use simple but profound language that touches both heart and soul. Keep it under 270 characters and make people want to share it. with some nice hashtags.eliminate any markdown formatting ,and use only plain text."""
42+
prayer_prompt = f"""faith filled, spirit filled prayer based on "{verse}" that people can declare over their lives with confidence. Make it specific, personal, and powerful - like speaking directly to God as a loving Father. Include breakthrough, blessing, and transformation. Write it as a declaration of faith under 270 characters that builds expectation for God's goodness.eliminate any markdown formatting , and use only plain text."""
3843

3944
# Backup shorter prompts
40-
short_explanation = f"""Explain "{verse}" in a way that makes people feel God's personal love and care for them. Make it encouraging, hopeful, and relatable to daily life. Use warm, simple language that touches the heart. Under 260 characters. with some nice hashtags."""
41-
short_prayer = f"""Write a powerful prayer from "{verse}" that people can pray with bold faith. Make it personal, specific, and full of expectation for God's goodness. Under 260 characters."""
45+
short_explanation = f"""Explain "{verse}" in a way that makes people feel God's personal love and care for them. Make it encouraging, hopeful, and relatable to daily life. Use warm, simple language that touches the heart. Under 260 characters. with some nice hashtags.eliminate any markdown formatting, and use only plain text."""
46+
short_prayer = f"""Write a powerful prayer from "{verse}" that people can pray with bold faith. Make it personal, specific, and full of expectation for God's goodness. Under 260 characters.eliminate any markdown formatting, and use only plain text."""
4247

4348
# Get initial responses
4449
explanation = get_ai_response(explanation_prompt)
@@ -48,20 +53,20 @@ def bible_verse(verse):
4853
logger.warning("Failed to get AI response, returning fallback")
4954
return fall_back["Explanation"], fall_back["Prayer"]
5055

51-
exp_text = check_quotes(explanation.get("message", ""))
52-
prayer_text = check_quotes(prayer_point.get("message", ""))
56+
exp_text = check_quotes(explanation)
57+
prayer_text = check_quotes(prayer_point)
5358

5459
# Check if content is too long and retry with shorter prompts
5560
if len(exp_text) > 280 or len(prayer_text) > 280:
5661
if len(exp_text) > 280:
5762
explanation = get_ai_response(short_explanation)
5863
if explanation:
59-
exp_text = check_quotes(explanation.get("message", ""))
64+
exp_text = check_quotes(explanation)
6065

6166
if len(prayer_text) > 272:
6267
prayer_point = get_ai_response(short_prayer)
6368
if prayer_point:
64-
prayer_text = check_quotes(prayer_point.get("message", ""))
69+
prayer_text = check_quotes(prayer_point)
6570

6671
# Final length check
6772
if len(exp_text) > 280:
@@ -71,13 +76,14 @@ def bible_verse(verse):
7176
return exp_text, prayer_text
7277

7378

74-
if __name__ == "__main__":
75-
verse = "For God so loved the world that whoever believes in him will not perish but have everlasting life. - John 3:16 - NIV"
76-
explanation, prayer = bible_verse(verse)
77-
print("Explanation1:", explanation)
78-
print("Prayer1:", prayer)
79+
# use for testing reasons
80+
# if __name__ == "__main__":
81+
# verse = "For God so loved the world that whoever believes in him will not perish but have everlasting life. - John 3:16 - NIV"
82+
# explanation, prayer = bible_verse(verse)
83+
# print("Explanation1:", explanation)
84+
# print("Prayer1:", prayer)
7985

80-
verse = "For God so loved the world that whoever believes in him will not perish but have everlasting life. - John 3:16 - NIV"
81-
explanation, prayer = bible_verse(verse)
82-
print("Explanation2:", explanation)
83-
print("Prayer2:", prayer)
86+
# verse = "For God so loved the world that whoever believes in him will not perish but have everlasting life. - John 3:16 - NIV"
87+
# explanation, prayer = bible_verse(verse)
88+
# print("Explanation2:", explanation)
89+
# print("Prayer2:", prayer)

0 commit comments

Comments
 (0)