Skip to content
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

chore(wren-ai-service): minor updates #1252

Closed
wants to merge 3 commits into from

Conversation

cyyeh
Copy link
Member

@cyyeh cyyeh commented Feb 3, 2025

  • refine sql generation reasoning prompt
  • refine text to sql prompt
  • add allow_sql_generation_reasoning to config.yaml, default: True

Summary by CodeRabbit

  • New Features

    • Increased the default SQL query result limit to return up to 50 results.
    • Introduced a configurable option to enable SQL generation reasoning, with an optional structured reasoning plan in prompts.
  • Improvements

    • Enhanced processing robustness and error handling for SQL generation outputs.
    • Refined the formatting of the reasoning steps to provide clearer, step-by-step insights.

@cyyeh cyyeh added module/ai-service ai-service related ci/ai-service ai-service related labels Feb 3, 2025
@cyyeh cyyeh requested a review from paopa February 3, 2025 01:35
Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This pull request updates several components to enhance SQL processing and generation. The run_sql.py file now returns up to 50 SQL query results instead of 10. A new configuration option (allow_sql_generation_reasoning) is added and propagated across the system, including in the AskService and various SQL generation pipelines. The changes also make the SQL generation reasoning parameter optional, update the reasoning prompt guidelines, and improve error handling and asynchronous processing in SQL utilities.

Changes

File(s) Change Summary
wren-ai-service/demo/run_sql.py Increased the SQL query result limit from 10 to 50 in the get_data_from_wren_engine call.
wren-ai-service/src/{config.py,globals.py} Introduced a new boolean configuration option allow_sql_generation_reasoning (default True) in the Settings class and passed it to AskService during container creation.
wren-ai-service/src/pipelines/generation/{sql_generation.py,sql_generation_reasoning.py,utils/sql.py} Modified SQL generation functions to make the sql_generation_reasoning parameter optional (default None), updated the prompt to conditionally include a reasoning plan, refined system prompt guidelines, and enhanced error handling including support for varied reply formats.
wren-ai-service/src/web/v1/services/ask.py Added the allow_sql_generation_reasoning parameter (default True) to AskService, updating the ask method to conditionally process SQL generation reasoning.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant A as AskService
    participant P as SQL Generation Pipeline
    participant DB as SQL Engine

    C->>A: Submit ask request
    A->>A: Check allow_sql_generation_reasoning flag
    alt SQL reasoning allowed
        A->>P: Process query with SQL reasoning (pass sql_generation_reasoning)
        P->>DB: Execute refined SQL query
        DB-->>P: Return query results
        P-->>A: Return processed result
    else SQL reasoning disabled
        A->>P: Process query without SQL reasoning
    end
    A-->>C: Return final response
Loading

Possibly related PRs

Suggested reviewers

  • paopa

Poem

I'm just a rabbit, hopping with glee,
Coding through changes as swift as can be.
SQL limits expand, new flags in sight,
With reasoning plans shining oh so bright.
In this digital garden, my code sings true,
A bunny’s delight in each line anew!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b80bf06 and 83c44a9.

📒 Files selected for processing (7)
  • wren-ai-service/demo/run_sql.py (1 hunks)
  • wren-ai-service/src/config.py (1 hunks)
  • wren-ai-service/src/globals.py (1 hunks)
  • wren-ai-service/src/pipelines/generation/sql_generation.py (3 hunks)
  • wren-ai-service/src/pipelines/generation/sql_generation_reasoning.py (1 hunks)
  • wren-ai-service/src/pipelines/generation/utils/sql.py (0 hunks)
  • wren-ai-service/src/web/v1/services/ask.py (3 hunks)
💤 Files with no reviewable changes (1)
  • wren-ai-service/src/pipelines/generation/utils/sql.py
⏰ 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 (8)
wren-ai-service/src/config.py (1)

34-36: LGTM! Well-structured configuration addition.

The new configuration option is well-placed under a dedicated section and follows the established pattern of using Field with a default value.

wren-ai-service/src/pipelines/generation/sql_generation_reasoning.py (2)

28-29: LGTM! Clear requirement to separate reasoning from SQL.

This requirement helps maintain a clear separation between reasoning and implementation.


29-30: LGTM! Enhanced structure for reasoning steps.

Requiring numbered steps with explicit reasoning improves the clarity and readability of the output.

wren-ai-service/src/pipelines/generation/sql_generation.py (2)

49-52: LGTM! Well-structured conditional template section.

The conditional rendering of the reasoning plan section is properly implemented using Jinja2 syntax.


64-64: LGTM! Proper handling of optional reasoning parameter.

The parameter is correctly typed as str | None with a default value of None, maintaining backward compatibility.

Also applies to: 143-143

wren-ai-service/demo/run_sql.py (1)

69-69: Verify impact of increased result limit.

The limit has been increased from 10 to 50 results. While this provides more comprehensive results, please ensure that:

  1. The increased result set size doesn't impact memory usage significantly
  2. The UI/client can handle displaying more results effectively
✅ Verification successful

Increased Result Limit Verified

The search confirms that using a limit of 50 in run_sql.py is consistent with other parts of the codebase where limits are set much higher (e.g., 100 and 500). There’s no evidence from the repository that this change would cause memory or performance issues. Still, please ensure the UI/client properly handles the increased result set.

  • Compared to other modules (e.g., in wren-ai-service/demo/app.py and wren-ai-service/demo/utils.py), the limit of 50 is modest.
  • No additional memory or performance constraints specific to this limit were found in the codebase.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for memory-related configurations or limitations in the codebase
rg -i "memory|limit|max.*results" --type python

Length of output: 80


Script:

#!/bin/bash
echo "=== Searching for memory, limit, and max results configurations in .py files ==="
rg -i "memory|limit|max.*results" -tpy

echo "=== Searching for 'limit=' parameter usage in run_sql.py ==="
rg -i "limit=" wren-ai-service/demo/run_sql.py

echo "=== Searching for get_data_from_wren_engine definition and usages ==="
rg -i "def get_data_from_wren_engine" -tpy

Length of output: 6842

wren-ai-service/src/globals.py (1)

124-124: LGTM!

The allow_sql_generation_reasoning parameter is correctly propagated from the settings to the AskService instance.

wren-ai-service/src/web/v1/services/ask.py (1)

103-106: LGTM!

The implementation of the SQL generation reasoning toggle is clean and well-structured:

  • Default value is sensibly set to True
  • Instance variable is properly initialized
  • Condition for SQL generation reasoning is correctly updated

Also applies to: 113-113, 147-147, 273-277

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cyyeh cyyeh force-pushed the chore/ai-service/enhance-reasoning branch from 83c44a9 to 50b3dde Compare February 3, 2025 06:14
@cyyeh cyyeh closed this Feb 3, 2025
@cyyeh cyyeh deleted the chore/ai-service/enhance-reasoning branch February 3, 2025 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci/ai-service ai-service related module/ai-service ai-service related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant