Spaces:
Running
Running
Upload 57 files
Browse files- .env.example +2 -2
- content/__pycache__/__init__.cpython-313.pyc +0 -0
- content/__pycache__/config_manager.cpython-313.pyc +0 -0
- content/__pycache__/database.cpython-313.pyc +0 -0
- content/__pycache__/doubt_solver.cpython-313.pyc +0 -0
- content/__pycache__/generator.cpython-313.pyc +0 -0
- content/__pycache__/history.cpython-313.pyc +0 -0
- content/__pycache__/news_scraper.cpython-313.pyc +0 -0
- content/__pycache__/pdf_generator.cpython-313.pyc +0 -0
- content/__pycache__/remote_storage.cpython-313.pyc +0 -0
- content/__pycache__/syllabus_manager.cpython-313.pyc +0 -0
- content/__pycache__/template_manager.cpython-313.pyc +0 -0
- content/__pycache__/user_registry.cpython-313.pyc +0 -0
- content/doubt_solver.py +4 -19
- content/generator.py +4 -2
- handlers/__pycache__/__init__.cpython-313.pyc +0 -0
- handlers/__pycache__/callbacks.cpython-313.pyc +0 -0
- handlers/__pycache__/commands.cpython-313.pyc +0 -0
- handlers/__pycache__/doubt_handler.cpython-313.pyc +0 -0
- handlers/__pycache__/leaderboard_handler.cpython-313.pyc +0 -0
- handlers/__pycache__/menu_router.cpython-313.pyc +0 -0
- handlers/__pycache__/poll_handler.cpython-313.pyc +0 -0
- scheduler/__pycache__/__init__.cpython-313.pyc +0 -0
- scheduler/__pycache__/job_scheduler.cpython-313.pyc +0 -0
.env.example
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
# Telegram Bot Token (from @BotFather)
|
| 2 |
BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN_HERE
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
|
| 7 |
# Admin User IDs (comma-separated, get from @userinfobot)
|
| 8 |
ADMIN_USER_IDS=123456789,987654321
|
|
|
|
| 1 |
# Telegram Bot Token (from @BotFather)
|
| 2 |
BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN_HERE
|
| 3 |
|
| 4 |
+
# OpenRouter API Key (from openrouter.ai)
|
| 5 |
+
OPENROUTER_API_KEY=YOUR_OPENROUTER_API_KEY_HERE
|
| 6 |
|
| 7 |
# Admin User IDs (comma-separated, get from @userinfobot)
|
| 8 |
ADMIN_USER_IDS=123456789,987654321
|
content/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/__init__.cpython-313.pyc and b/content/__pycache__/__init__.cpython-313.pyc differ
|
|
|
content/__pycache__/config_manager.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/config_manager.cpython-313.pyc and b/content/__pycache__/config_manager.cpython-313.pyc differ
|
|
|
content/__pycache__/database.cpython-313.pyc
ADDED
|
Binary file (8.61 kB). View file
|
|
|
content/__pycache__/doubt_solver.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/doubt_solver.cpython-313.pyc and b/content/__pycache__/doubt_solver.cpython-313.pyc differ
|
|
|
content/__pycache__/generator.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/generator.cpython-313.pyc and b/content/__pycache__/generator.cpython-313.pyc differ
|
|
|
content/__pycache__/history.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/history.cpython-313.pyc and b/content/__pycache__/history.cpython-313.pyc differ
|
|
|
content/__pycache__/news_scraper.cpython-313.pyc
ADDED
|
Binary file (4.32 kB). View file
|
|
|
content/__pycache__/pdf_generator.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/pdf_generator.cpython-313.pyc and b/content/__pycache__/pdf_generator.cpython-313.pyc differ
|
|
|
content/__pycache__/remote_storage.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/remote_storage.cpython-313.pyc and b/content/__pycache__/remote_storage.cpython-313.pyc differ
|
|
|
content/__pycache__/syllabus_manager.cpython-313.pyc
CHANGED
|
Binary files a/content/__pycache__/syllabus_manager.cpython-313.pyc and b/content/__pycache__/syllabus_manager.cpython-313.pyc differ
|
|
|
content/__pycache__/template_manager.cpython-313.pyc
ADDED
|
Binary file (6.16 kB). View file
|
|
|
content/__pycache__/user_registry.cpython-313.pyc
ADDED
|
Binary file (4.54 kB). View file
|
|
|
content/doubt_solver.py
CHANGED
|
@@ -6,12 +6,8 @@ Works for: DM messages, group @mentions, replies-to-bot messages.
|
|
| 6 |
|
| 7 |
import logging
|
| 8 |
import re
|
| 9 |
-
from google import genai
|
| 10 |
-
from google.genai import types
|
| 11 |
-
from config import GEMINI_API_KEY, GEMINI_MODEL, GEMINI_MAX_TOKENS
|
| 12 |
|
| 13 |
logger = logging.getLogger(__name__)
|
| 14 |
-
client = genai.Client(api_key=GEMINI_API_KEY)
|
| 15 |
|
| 16 |
# System prompt that makes the bot act as a JEE/NEET tutor
|
| 17 |
_SYSTEM_PROMPT = (
|
|
@@ -72,7 +68,7 @@ def _extract_text(message) -> str:
|
|
| 72 |
|
| 73 |
async def solve_doubt(user_question: str) -> str:
|
| 74 |
"""
|
| 75 |
-
Call
|
| 76 |
Returns formatted response string.
|
| 77 |
"""
|
| 78 |
if not user_question or len(user_question.strip()) < 5:
|
|
@@ -89,31 +85,20 @@ async def solve_doubt(user_question: str) -> str:
|
|
| 89 |
|
| 90 |
try:
|
| 91 |
from content.config_manager import config_manager
|
|
|
|
| 92 |
s = config_manager.settings
|
| 93 |
system_prompt = _SYSTEM_PROMPT.replace("CrazyBot", s['bot_name'])
|
| 94 |
|
| 95 |
-
|
| 96 |
-
model=GEMINI_MODEL,
|
| 97 |
-
contents=prompt,
|
| 98 |
-
config=types.GenerateContentConfig(
|
| 99 |
-
system_instruction=system_prompt,
|
| 100 |
-
max_output_tokens=GEMINI_MAX_TOKENS,
|
| 101 |
-
temperature=0.5,
|
| 102 |
-
)
|
| 103 |
-
)
|
| 104 |
-
answer = response.text
|
| 105 |
if not answer:
|
| 106 |
return "β οΈ I couldn't generate a response right now. Please try again."
|
| 107 |
|
| 108 |
-
from content.generator import _clean_markdown
|
| 109 |
-
answer = _clean_markdown(answer)
|
| 110 |
-
|
| 111 |
# Add helpful footer
|
| 112 |
answer += f"\n\nββββββββββββββ\nπ <b><a href=\"{s['main_channel_url']}\">{s['main_channel_name']}</a></b> | Ask more doubts anytime!"
|
| 113 |
return answer
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
-
logger.error(f"[DoubtSolver]
|
| 117 |
from content.config_manager import config_manager
|
| 118 |
s = config_manager.settings
|
| 119 |
return (
|
|
|
|
| 6 |
|
| 7 |
import logging
|
| 8 |
import re
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
logger = logging.getLogger(__name__)
|
|
|
|
| 11 |
|
| 12 |
# System prompt that makes the bot act as a JEE/NEET tutor
|
| 13 |
_SYSTEM_PROMPT = (
|
|
|
|
| 68 |
|
| 69 |
async def solve_doubt(user_question: str) -> str:
|
| 70 |
"""
|
| 71 |
+
Call LLM to explain/solve the student's question.
|
| 72 |
Returns formatted response string.
|
| 73 |
"""
|
| 74 |
if not user_question or len(user_question.strip()) < 5:
|
|
|
|
| 85 |
|
| 86 |
try:
|
| 87 |
from content.config_manager import config_manager
|
| 88 |
+
from content.generator import _call_llm, _clean_markdown
|
| 89 |
s = config_manager.settings
|
| 90 |
system_prompt = _SYSTEM_PROMPT.replace("CrazyBot", s['bot_name'])
|
| 91 |
|
| 92 |
+
answer = await _call_llm(prompt, system_prompt=system_prompt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
if not answer:
|
| 94 |
return "β οΈ I couldn't generate a response right now. Please try again."
|
| 95 |
|
|
|
|
|
|
|
|
|
|
| 96 |
# Add helpful footer
|
| 97 |
answer += f"\n\nββββββββββββββ\nπ <b><a href=\"{s['main_channel_url']}\">{s['main_channel_name']}</a></b> | Ask more doubts anytime!"
|
| 98 |
return answer
|
| 99 |
|
| 100 |
except Exception as e:
|
| 101 |
+
logger.error(f"[DoubtSolver] API error: {e}")
|
| 102 |
from content.config_manager import config_manager
|
| 103 |
s = config_manager.settings
|
| 104 |
return (
|
content/generator.py
CHANGED
|
@@ -90,7 +90,7 @@ def _today() -> str:
|
|
| 90 |
return datetime.now().strftime("%A")
|
| 91 |
|
| 92 |
|
| 93 |
-
async def _call_llm(prompt: str) -> str:
|
| 94 |
"""Wrapper for OpenRouter API using httpx."""
|
| 95 |
import httpx
|
| 96 |
max_retries = 3
|
|
@@ -106,10 +106,12 @@ async def _call_llm(prompt: str) -> str:
|
|
| 106 |
"Content-Type": "application/json"
|
| 107 |
}
|
| 108 |
|
|
|
|
|
|
|
| 109 |
payload = {
|
| 110 |
"model": "google/gemini-2.0-flash-lite-preview-02-05:free",
|
| 111 |
"messages": [
|
| 112 |
-
{"role": "system", "content":
|
| 113 |
{"role": "user", "content": prompt}
|
| 114 |
],
|
| 115 |
"temperature": GEMINI_TEMPERATURE
|
|
|
|
| 90 |
return datetime.now().strftime("%A")
|
| 91 |
|
| 92 |
|
| 93 |
+
async def _call_llm(prompt: str, system_prompt: str = None) -> str:
|
| 94 |
"""Wrapper for OpenRouter API using httpx."""
|
| 95 |
import httpx
|
| 96 |
max_retries = 3
|
|
|
|
| 106 |
"Content-Type": "application/json"
|
| 107 |
}
|
| 108 |
|
| 109 |
+
sys_prompt = system_prompt if system_prompt else template_manager.system_prompt
|
| 110 |
+
|
| 111 |
payload = {
|
| 112 |
"model": "google/gemini-2.0-flash-lite-preview-02-05:free",
|
| 113 |
"messages": [
|
| 114 |
+
{"role": "system", "content": sys_prompt},
|
| 115 |
{"role": "user", "content": prompt}
|
| 116 |
],
|
| 117 |
"temperature": GEMINI_TEMPERATURE
|
handlers/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/handlers/__pycache__/__init__.cpython-313.pyc and b/handlers/__pycache__/__init__.cpython-313.pyc differ
|
|
|
handlers/__pycache__/callbacks.cpython-313.pyc
CHANGED
|
Binary files a/handlers/__pycache__/callbacks.cpython-313.pyc and b/handlers/__pycache__/callbacks.cpython-313.pyc differ
|
|
|
handlers/__pycache__/commands.cpython-313.pyc
CHANGED
|
Binary files a/handlers/__pycache__/commands.cpython-313.pyc and b/handlers/__pycache__/commands.cpython-313.pyc differ
|
|
|
handlers/__pycache__/doubt_handler.cpython-313.pyc
ADDED
|
Binary file (3.94 kB). View file
|
|
|
handlers/__pycache__/leaderboard_handler.cpython-313.pyc
ADDED
|
Binary file (2.35 kB). View file
|
|
|
handlers/__pycache__/menu_router.cpython-313.pyc
CHANGED
|
Binary files a/handlers/__pycache__/menu_router.cpython-313.pyc and b/handlers/__pycache__/menu_router.cpython-313.pyc differ
|
|
|
handlers/__pycache__/poll_handler.cpython-313.pyc
ADDED
|
Binary file (2.41 kB). View file
|
|
|
scheduler/__pycache__/__init__.cpython-313.pyc
CHANGED
|
Binary files a/scheduler/__pycache__/__init__.cpython-313.pyc and b/scheduler/__pycache__/__init__.cpython-313.pyc differ
|
|
|
scheduler/__pycache__/job_scheduler.cpython-313.pyc
CHANGED
|
Binary files a/scheduler/__pycache__/job_scheduler.cpython-313.pyc and b/scheduler/__pycache__/job_scheduler.cpython-313.pyc differ
|
|
|