-
Notifications
You must be signed in to change notification settings - Fork 4
Add Grok API support and improve LLM integration #163
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
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e92acb4
Improve logging
avelytchko b57cc37
Fix linter
avelytchko 33aae20
Add rate limit check
avelytchko 538a090
Implement Grok API support
avelytchko 0806b07
Parametrize user limits
avelytchko e91f722
Fix linter
avelytchko 6db35fb
Add disable=broad-exception-caught for pyling
avelytchko 1e61c42
Implement conversation context
avelytchko 8c19200
Add ukrainian to translation to some log messages
avelytchko ab9188e
Modify system prompt to LLM
avelytchko 606d45a
Implement MAX_CONTEXT_CHARS
avelytchko 98e47dc
Fix LLM rate limiting and error handling issues
avelytchko 5c6c98b
Remove PR_MESSAGE.md
avelytchko 725c3e1
Fix LLM API helpers to propagate exceptions and add plain text instru…
avelytchko c9865ba
Fix linter
avelytchko c3b6179
Add disable=broad-exception-caught for pyling
avelytchko 28bb1c7
Fix linter
avelytchko a8dd712
Fix cleanup task initialization
avelytchko 3be82cc
feat: Add SQLite persistence for user data across restarts
avelytchko 47b25a6
Fix linter
avelytchko 1de8512
Fix linter
avelytchko dbdf3aa
debug: Add detailed logging for SQLite database operations
avelytchko deababe
Fix linter
avelytchko 1696d2d
Update dependencies
avelytchko 5e0b958
fix: Apply code review improvements
avelytchko 8e89347
fix: Apply critical code review fixes
avelytchko 9f15bb8
fix: Apply final code review improvements
avelytchko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| """SQLite storage for bot user data persistence.""" | ||
|
|
||
| import sqlite3 | ||
| import json | ||
| import os | ||
| import time | ||
| from logger import debug | ||
|
|
||
|
|
||
| class BotStorage: | ||
| """Handles persistent storage of user data in SQLite.""" | ||
|
|
||
| def __init__(self, db_path="data/bot.db"): | ||
| """Initialize database connection and create tables.""" | ||
| os.makedirs(os.path.dirname(db_path), exist_ok=True) | ||
| self.db_path = db_path | ||
| self.conn = sqlite3.connect(db_path, check_same_thread=False) | ||
| self._create_tables() | ||
| debug("Database initialized at %s", db_path) | ||
|
|
||
| def _create_tables(self): | ||
| """Create tables if they don't exist.""" | ||
| cursor = self.conn.cursor() | ||
| cursor.execute(""" | ||
| CREATE TABLE IF NOT EXISTS user_data ( | ||
| user_id INTEGER PRIMARY KEY, | ||
| conversation_context TEXT, | ||
| rate_limit_timestamps TEXT, | ||
| daily_count INTEGER DEFAULT 0, | ||
| daily_date TEXT, | ||
| last_seen REAL | ||
| ) | ||
| """) | ||
| cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_data_last_seen ON user_data(last_seen)") | ||
| self.conn.commit() | ||
|
|
||
| def load_user_data(self, user_id): | ||
| """Load user data from database.""" | ||
| cursor = self.conn.cursor() | ||
| cursor.execute("SELECT * FROM user_data WHERE user_id = ?", (user_id,)) | ||
| row = cursor.fetchone() | ||
| if row: | ||
| return { | ||
| "conversation_context": json.loads(row[1]) if row[1] else [], | ||
| "rate_limit_timestamps": json.loads(row[2]) if row[2] else [], | ||
| "daily_count": row[3], | ||
| "daily_date": row[4], | ||
| "last_seen": row[5], | ||
| } | ||
| return None | ||
|
|
||
| def save_user_data(self, user_id, conversation_context, rate_limit_timestamps, daily_count, daily_date, last_seen): | ||
| """Save user data to database.""" | ||
| cursor = self.conn.cursor() | ||
| cursor.execute( | ||
| """ | ||
| INSERT OR REPLACE INTO user_data | ||
| (user_id, conversation_context, rate_limit_timestamps, daily_count, daily_date, last_seen) | ||
| VALUES (?, ?, ?, ?, ?, ?) | ||
| """, | ||
| ( | ||
| user_id, | ||
| json.dumps(conversation_context), | ||
| json.dumps(rate_limit_timestamps), | ||
| daily_count, | ||
| daily_date, | ||
| last_seen, | ||
| ), | ||
| ) | ||
| self.conn.commit() | ||
|
|
||
| def delete_user_data(self, user_id): | ||
| """Delete user data from database.""" | ||
| cursor = self.conn.cursor() | ||
| cursor.execute("DELETE FROM user_data WHERE user_id = ?", (user_id,)) | ||
| self.conn.commit() | ||
|
|
||
| def get_stale_users(self, ttl_seconds): | ||
| """Get list of user IDs that haven't been seen within TTL.""" | ||
| current_time = time.time() | ||
| cursor = self.conn.cursor() | ||
| cursor.execute("SELECT user_id FROM user_data WHERE last_seen < ?", (current_time - ttl_seconds,)) | ||
| return [row[0] for row in cursor.fetchall()] | ||
|
|
||
| def close(self): | ||
| """Close database connection.""" | ||
| self.conn.close() | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add language identifiers to new fenced code blocks.
Lines 31, 35, 39, and 43 trigger MD040 (
fenced-code-language). Please annotate these command fences (e.g.,bash) to keep docs lint-clean.📝 Suggested doc fix
-
+bashdocker run -d --name downloader-bot --restart always --env-file .env ovchynnikov/load-bot-linux:latest
-
+bashdocker run -d --name downloader-bot --restart always --env-file .env -v bot-data:/bot/data -v /absolute/path/to/instagram_cookies.txt:/bot/instagram_cookies.txt ovchynnikov/load-bot-linux:latest
🧰 Tools
🪛 markdownlint-cli2 (0.21.0)
[warning] 31-31: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
[warning] 35-35: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
[warning] 39-39: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
[warning] 43-43: Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🤖 Prompt for AI Agents