-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore(wren-ai-service): improve sql prompt #1819
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
Conversation
WalkthroughThe SQL generation rules documentation was updated to forbid the use of the EXTRACT() function with INTERVAL data types. Additionally, the function for constructing ask history messages was modified to accept both AskHistory objects and dictionaries, adjusting its logic to handle both data structures accordingly. Changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. π§ Pylint (3.3.7)wren-ai-service/src/pipelines/generation/utils/sql.pyβ¨ Finishing Touches
π§ͺ Generate Unit Tests
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
π§Ή Nitpick comments (1)
wren-ai-service/src/pipelines/generation/utils/sql.py (1)
468-485: Consider improving type safety and error handling.The function modification adds flexibility to handle both
AskHistoryobjects and dictionaries, but the current implementation has some potential issues:
- Mixed list handling: The function doesn't explicitly handle cases where the list contains both
AskHistoryobjects and dictionaries- Error handling: If an item is neither an
AskHistoryobject nor a dictionary with the required keys, it will raise aKeyError- Type safety: Using
hasattrfor duck typing works butisinstancechecks would be more explicitConsider this more robust implementation:
def construct_ask_history_messages( histories: list[AskHistory] | list[dict], ) -> list[ChatMessage]: messages = [] for history in histories: - messages.append( - ChatMessage.from_user( - history.question - if hasattr(history, "question") - else history["question"] - ) - ) - messages.append( - ChatMessage.from_assistant( - history.sql if hasattr(history, "sql") else history["sql"] - ) - ) + if isinstance(history, AskHistory): + question = history.question + sql = history.sql + elif isinstance(history, dict): + question = history["question"] + sql = history["sql"] + else: + raise TypeError(f"Expected AskHistory or dict, got {type(history)}") + + messages.append(ChatMessage.from_user(question)) + messages.append(ChatMessage.from_assistant(sql)) return messages
π Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
π Files selected for processing (1)
wren-ai-service/src/pipelines/generation/utils/sql.py(2 hunks)
π§° Additional context used
π§ Learnings (2)
π Common learnings
Learnt from: wwwy3y3
PR: Canner/WrenAI#1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.
wren-ai-service/src/pipelines/generation/utils/sql.py (1)
Learnt from: wwwy3y3
PR: Canner/WrenAI#1585
File: wren-ui/src/pages/api/v1/generate_sql.ts:98-106
Timestamp: 2025-04-24T16:10:43.308Z
Learning: In the generate_sql API, allow users to specify language codes not predefined in the WrenAILanguage enum, passing them through directly rather than strictly validating against the enum.
𧬠Code Graph Analysis (1)
wren-ai-service/src/pipelines/generation/utils/sql.py (1)
wren-ai-service/src/web/v1/services/ask.py (1)
AskHistory(16-18)
β° Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: pytest
- GitHub Check: pytest
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
π Additional comments (1)
wren-ai-service/src/pipelines/generation/utils/sql.py (1)
209-209: LGTM! Good addition to SQL constraints.The new rule appropriately forbids the use of
EXTRACT()function with INTERVAL data types, which aligns with the existing constraint pattern and helps prevent potential SQL generation issues.
Summary by CodeRabbit
Documentation
New Features