Conversation
|
Caution Review failedThe pull request is closed. WalkthroughThe codebase was refactored to introduce class-based, structured management of users, conversations, context, and memory. New models and database schema changes support richer metadata, embedding-based similarity checks, and user preferences. Message processing now leverages these enhancements for context construction, repetition detection, and memory summarization, guided by a comprehensive system prompt. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant API (/webhook)
participant MemoryManager
participant ConversationDB
participant OpenRouterAPI
User->>API: Sends message (with user_id, language)
API->>MemoryManager: process_message(user_id, message, language)
MemoryManager->>ConversationDB: get_or_create_user(user_id)
MemoryManager->>ConversationDB: get_user_preferences(user_id)
MemoryManager->>ConversationDB: get_recent_conversations(user_id)
MemoryManager->>ConversationDB: get_relevant_memories(user_id, embedding)
MemoryManager->>ConversationDB: check_repetition(user_id, message_embedding)
alt Repetition detected
MemoryManager-->>API: Return repeated response
else Not repeated
MemoryManager->>OpenRouterAPI: Generate AI response (with context, memories)
OpenRouterAPI-->>MemoryManager: AI response
MemoryManager->>ConversationDB: add_conversation(user_id, message, response, ...)
MemoryManager->>ConversationDB: update_user_context(user_id, ...)
MemoryManager-->>API: Return AI response
end
API-->>User: Deliver response
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (7)
system_prompt.txt (1)
55-59: Minor grammar nit
“You're proudly created by a talented developer” → “You were proudly created …” reads smoother.🧰 Tools
🪛 LanguageTool
[uncategorized] ~57-~57: Possible missing preposition found.
Context: ...//github.com/gitnasr) - LinkedIn: https://www.linkedin.com/in/c0nasr/ You're proudly created by a talented d...(AI_EN_LECTOR_MISSING_PREPOSITION)
database_config.py (1)
38-40: Add cascading deletes to prevent orphan rows
conversationsandcontextrelationships lackcascade="all, delete-orphan". Without this, deleting aUserwill leave dangling foreign-key rows and violate FK constraints.main.py (3)
1-1: Remove unused importasyncio
It is not referenced anywhere.🧰 Tools
🪛 Ruff (0.11.9)
1-1:
asyncioimported but unusedRemove unused import:
asyncio(F401)
9-9: Remove unused importnumpy
The module isn’t used directly; SentenceTransformer handles numpy internally.🧰 Tools
🪛 Ruff (0.11.9)
9-9:
numpyimported but unusedRemove unused import:
numpy(F401)
281-282: Unused variablesprompt_tokens_used/completion_tokens_used
They are assigned then ignored. Drop them or log them for cost tracking to keep the code lint-clean.🧰 Tools
🪛 Ruff (0.11.9)
281-281: Local variable
prompt_tokens_usedis assigned to but never usedRemove assignment to unused variable
prompt_tokens_used(F841)
282-282: Local variable
completion_tokens_usedis assigned to but never usedRemove assignment to unused variable
completion_tokens_used(F841)
database.py (2)
5-7: Drop unused imports
numpyanddeleteare never referenced; remove to keep the module lean.🧰 Tools
🪛 Ruff (0.11.9)
5-5:
numpyimported but unusedRemove unused import:
numpy(F401)
7-7:
sqlalchemy.deleteimported but unusedRemove unused import:
sqlalchemy.delete(F401)
175-177: Idiomatic boolean filter
UserMemory.is_active == Truecan be rewritten asUserMemory.is_activeto satisfy SQLAlchemy’s linting and avoid E712.🧰 Tools
🪛 Ruff (0.11.9)
176-176: Avoid equality comparisons to
True; useif UserMemory.is_active:for truth checksReplace with
UserMemory.is_active(E712)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
database.py(1 hunks)database_config.py(2 hunks)main.py(3 hunks)requirements.txt(1 hunks)system_prompt.txt(1 hunks)
🧰 Additional context used
🪛 Ruff (0.11.9)
main.py
1-1: asyncio imported but unused
Remove unused import: asyncio
(F401)
9-9: numpy imported but unused
Remove unused import: numpy
(F401)
169-187: Use a single with statement with multiple contexts instead of nested with statements
Combine with statements
(SIM117)
239-240: Use a single if statement instead of nested if statements
(SIM102)
281-281: Local variable prompt_tokens_used is assigned to but never used
Remove assignment to unused variable prompt_tokens_used
(F841)
282-282: Local variable completion_tokens_used is assigned to but never used
Remove assignment to unused variable completion_tokens_used
(F841)
296-296: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
database.py
5-5: numpy imported but unused
Remove unused import: numpy
(F401)
7-7: sqlalchemy.delete imported but unused
Remove unused import: sqlalchemy.delete
(F401)
176-176: Avoid equality comparisons to True; use if UserMemory.is_active: for truth checks
Replace with UserMemory.is_active
(E712)
🪛 Pylint (3.3.7)
main.py
[refactor] 71-71: Too many local variables (29/15)
(R0914)
[refactor] 71-71: Too many branches (15/12)
(R0912)
[refactor] 71-71: Too many statements (57/50)
(R0915)
[refactor] 208-208: Too many local variables (21/15)
(R0914)
[refactor] 208-208: Too many statements (56/50)
(R0915)
database_config.py
[refactor] 28-28: Too few public methods (0/2)
(R0903)
[refactor] 41-41: Too few public methods (1/2)
(R0903)
[refactor] 73-73: Too few public methods (1/2)
(R0903)
[refactor] 102-102: Too few public methods (0/2)
(R0903)
database.py
[refactor] 50-50: Too many arguments (9/5)
(R0913)
[refactor] 50-50: Too many positional arguments (9/5)
(R0917)
[refactor] 209-209: Too many arguments (7/5)
(R0913)
[refactor] 209-209: Too many positional arguments (7/5)
(R0917)
🪛 LanguageTool
system_prompt.txt
[uncategorized] ~57-~57: Possible missing preposition found.
Context: ...//github.com/gitnasr) - LinkedIn: https://www.linkedin.com/in/c0nasr/ You're proudly created by a talented d...
(AI_EN_LECTOR_MISSING_PREPOSITION)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-push
🔇 Additional comments (1)
database_config.py (1)
78-80:⚠️ Potential issueAvoid mutable default for JSON column
context_messages = Column(JSON, default=list)instantiates the list once at import time. Usedefault=lambda: []to avoid shared state across instances.- context_messages = Column(JSON, default=list) + context_messages = Column(JSON, default=lambda: [])Likely an incorrect or invalid review comment.
There was a problem hiding this comment.
Actionable comments posted: 2
♻️ Duplicate comments (1)
main.py (1)
303-311: Sensitive data is still logged — duplicate warningRaw
request_payload(including user text) is written toopenrouter_requests.logunconditionally. This duplicates the earlier review comment and still poses PII leakage risk. Gate behind a DEBUG flag or redact payload before logging.
🧹 Nitpick comments (5)
database_config.py (1)
33-36: Consider constrainingusers.idlength
idis declared asStringwithout a length limit. PG will map this totext, which may bloat indexes and hurt look-ups on the primary key. In most messaging scenarios a WhatsApp/JWT/user UUID fits into 36–64 chars.- id = Column(String, primary_key=True, index=True) + id = Column(String(64), primary_key=True, index=True)main.py (2)
11-11: Remove unusednumpyimport
numpyis imported but never used, tripping Ruff F401 and increasing cold-start time in serverless deployments.-import numpy as np🧰 Tools
🪛 Ruff (0.11.9)
11-11:
numpyimported but unusedRemove unused import:
numpy(F401)
299-302: Unused variablesprompt_tokens_used/completion_tokens_usedThese variables are parsed but not referenced afterwards, producing linter noise and misleading future readers.
- prompt_tokens_used = result['usage']['prompt_tokens'] - completion_tokens_used = result['usage']['completion_tokens']🧰 Tools
🪛 Ruff (0.11.9)
300-300: Local variable
prompt_tokens_usedis assigned to but never usedRemove assignment to unused variable
prompt_tokens_used(F841)
301-301: Local variable
completion_tokens_usedis assigned to but never usedRemove assignment to unused variable
completion_tokens_used(F841)
database.py (2)
6-8: Remove unuseddeleteimport
sqlalchemy.deleteis imported but never referenced. Clean-up avoids Ruff F401 and keeps the dependency list minimal.-from sqlalchemy import and_, delete, select +from sqlalchemy import and_, select🧰 Tools
🪛 Ruff (0.11.9)
6-6:
sqlalchemy.deleteimported but unusedRemove unused import:
sqlalchemy.delete(F401)
180-183: PEP 8: avoid== Truein query filterSQLAlchemy allows the boolean column itself to be evaluated. Using
== Truetriggers Ruff E712 and produces verbose SQL.- UserMemory.is_active == True + UserMemory.is_active🧰 Tools
🪛 Ruff (0.11.9)
182-182: Avoid equality comparisons to
True; useif UserMemory.is_active:for truth checksReplace with
UserMemory.is_active(E712)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
database.py(1 hunks)database_config.py(2 hunks)main.py(2 hunks)requirements.txt(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- requirements.txt
🧰 Additional context used
🧬 Code Graph Analysis (1)
database.py (1)
database_config.py (6)
Conversation(43-74)User(29-41)UserContext(76-103)UserMemory(105-121)to_dict(61-74)add_message(92-103)
🪛 Pylint (3.3.7)
database_config.py
[refactor] 29-29: Too few public methods (0/2)
(R0903)
[refactor] 43-43: Too few public methods (1/2)
(R0903)
[refactor] 76-76: Too few public methods (1/2)
(R0903)
[refactor] 105-105: Too few public methods (0/2)
(R0903)
main.py
[refactor] 86-86: Too many local variables (29/15)
(R0914)
[refactor] 86-86: Too many branches (15/12)
(R0912)
[refactor] 86-86: Too many statements (57/50)
(R0915)
[refactor] 224-224: Too many local variables (22/15)
(R0914)
[refactor] 224-224: Too many statements (56/50)
(R0915)
database.py
[refactor] 56-56: Too many arguments (9/5)
(R0913)
[refactor] 56-56: Too many positional arguments (9/5)
(R0917)
[refactor] 215-215: Too many arguments (7/5)
(R0913)
[refactor] 215-215: Too many positional arguments (7/5)
(R0917)
🪛 Ruff (0.11.9)
main.py
11-11: numpy imported but unused
Remove unused import: numpy
(F401)
184-202: Use a single with statement with multiple contexts instead of nested with statements
Combine with statements
(SIM117)
258-259: Use a single if statement instead of nested if statements
(SIM102)
300-300: Local variable prompt_tokens_used is assigned to but never used
Remove assignment to unused variable prompt_tokens_used
(F841)
301-301: Local variable completion_tokens_used is assigned to but never used
Remove assignment to unused variable completion_tokens_used
(F841)
315-315: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling
(B904)
database.py
6-6: sqlalchemy.delete imported but unused
Remove unused import: sqlalchemy.delete
(F401)
182-182: Avoid equality comparisons to True; use if UserMemory.is_active: for truth checks
Replace with UserMemory.is_active
(E712)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build-and-push
There was a problem hiding this comment.
Pull Request Overview
This PR introduces structured user management with enhanced memory and conversation context handling, as well as updated workflows for the Docker build process. Key changes include a new system prompt file for the WhatsAppWizard assistant, comprehensive updates to database models and conversation operations, and refinements in the CI/CD pipeline.
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| system_prompt.txt | New system prompt establishing the WhatsAppWizard assistant’s personality |
| database_config.py | Updates to database models including relationships, new fields, and refinements |
| database.py | Enhanced database operations with new functions for user, conversation, and memory management |
| .github/workflows/docker-build.yml | Adjusted file patterns and caching keys for Docker build and push conditions |
Comments suppressed due to low confidence (1)
database_config.py:49
- Changing the column type for 'message' from Text to String might truncate longer messages. Consider using Text if messages can be lengthy.
message = Column(String, nullable=False)
Summary by CodeRabbit
New Features
Improvements
Documentation
Chores